Exemple #1
0
        public static JobMatched GetLastAppliedJob(IMongoDatabase db)
        {
            // Users collection
            var userjobs_collection = db.GetCollection <MyJobs>("userjobs");

            var userdetails_filter = Builders <MyJobs> .Filter.Eq("username", "*****@*****.**") &
                                     Builders <MyJobs> .Filter.Eq("site", "cwjobs");

            var userdetails = userjobs_collection.Find(userdetails_filter);

            JobMatched lastAppliedJob = null;

            if (userdetails.Count() != 0)
            {
                // Take the latest applied job
                lastAppliedJob = userdetails.FirstOrDefault().jobs_applied.LastOrDefault();
            }
            else
            {
                // Creates new user if it does not exist
                var newUser = new MyJobs
                {
                    username         = "******",
                    site             = "cwjobs",
                    positiveKeywords = new string[] { },
                    negativeKeywords = new string[] { },
                    jobs             = new List <JobMatched>(),
                    jobs_applied     = new List <JobMatched>(),
                    createdOn        = DateTime.Now.ToShortDateString()
                };
                userjobs_collection.InsertOne(newUser);
            }

            return(lastAppliedJob);
        }
Exemple #2
0
        public static void MoveJobToApplied(JobMatched job, IMongoDatabase db)
        {
            var userjobs_collection = db.GetCollection <MyJobs>("userjobs");

            // Move job record to the "jobs_applied" array and delete from the "jobs" array
            var filter = Builders <MyJobs> .Filter.Eq("username", "*****@*****.**") &
                         Builders <MyJobs> .Filter.Eq("site", "cwjobs");

            var insert = Builders <MyJobs> .Update.AddToSet("jobs_applied", job);

            userjobs_collection.FindOneAndUpdate <MyJobs>(filter, insert);

            //var delete_filter = new BsonDocument("username", "bodrum");
            var jobToDelete = Builders <JobMatched> .Filter.Eq("ApplicationURL", job.ApplicationURL);

            var delete = Builders <MyJobs> .Update.PullFilter("jobs", jobToDelete);

            var result = userjobs_collection.FindOneAndUpdateAsync(filter, delete).Result;
        }
Exemple #3
0
        public void Execute_Matcher()
        {
            Logger.Log("---MATCHER STARTED---");

            // Initialize MongoDB driver
            var            client = new MongoClient("mongodb://localhost:27017");
            IMongoDatabase db     = client.GetDatabase("heapjob");

            // Get the last applied job or null (if new user)
            JobMatched lastAppliedJob = Matcher.GetLastAppliedJob(db);

            // Get a list of the newest jobs
            List <Job> latestJobs = Matcher.GetTheNewestJobs(lastAppliedJob, db);

            // Iterate over filtered results to prepare a list of jobs to be inserted
            var jobsMatched = Matcher.SelectOnlyMatchingJobs(latestJobs, db);

            // Add matched jobs to the user jobs
            Matcher.PersistNewJobsToMongo(jobsMatched, db);

            Logger.Log("---MATCHER FINISHED---");
        }
Exemple #4
0
        public static List <Job> GetTheNewestJobs(JobMatched lastAppliedJob, IMongoDatabase db)
        {
            var cwjobs_collection = db.GetCollection <Job>("cwjobs");

            string mongodbStartOfTheSearchObjectId;

            if (lastAppliedJob != null)
            {
                //Logger.Log(readyToApplyJobs.ApplicationURL);

                var applicationURL_filter = Builders <Job> .Filter.Eq("ApplicationURL", lastAppliedJob.ApplicationURL);

                var preveousjob = cwjobs_collection.Find(applicationURL_filter).FirstOrDefault();
                Logger.Log("Will be loading from the latest user job - " + (preveousjob?.Id ?? ""));
                mongodbStartOfTheSearchObjectId = preveousjob?.Id;

                if (preveousjob == null)
                {
                    Logger.Log("Will be loading from the start of the day");

                    int timestamp = (int)(DateTime.Now.Date - BsonConstants.UnixEpoch).TotalSeconds;
                    var mongodbStartOfTheDayObjectId = new ObjectId(timestamp, 0, 0, 0);

                    var applicationURL_filter2 = Builders <Job> .Filter.Gt("_id", mongodbStartOfTheDayObjectId);

                    preveousjob = cwjobs_collection.Find(applicationURL_filter2).FirstOrDefault();
                    Logger.Log("Search by ObjectID - " + (preveousjob?.Id ?? ""));
                    mongodbStartOfTheSearchObjectId = preveousjob?.Id;
                }
            }
            else
            {
                // Take jobs from the start of the current day
                Logger.Log("Will be loading from the start of the day");

                int timestamp       = (int)(DateTime.Now.Date - BsonConstants.UnixEpoch).TotalSeconds;
                var mongodbObjectId = new ObjectId(timestamp, 0, 0, 0);

                var applicationURL_filter = Builders <Job> .Filter.Gt("_id", mongodbObjectId);

                var preveousjob = cwjobs_collection.Find(applicationURL_filter).FirstOrDefault();
                Logger.Log("Search by ObjectID - " + (preveousjob?.Id ?? ""));
                mongodbStartOfTheSearchObjectId = preveousjob?.Id;
            }

            // Retrieve all latest jobs
            //Logger.Log("ObjectId(\"" + mongodbStartOfTheSearchObjectId + "\")");
            var latestjobs_filter = Builders <Job> .Filter.Gt("_id", ObjectId.Parse(mongodbStartOfTheSearchObjectId));

            var latestjobs = cwjobs_collection.Find(latestjobs_filter);

            // Regex filter
            //var search_filter = Builders<Job>.Filter.Regex("Description", new BsonRegularExpression("C#"));
            //var latestjobs = cwjobs_collection.Find(search_filter);

            // Count
            Logger.Log("Number of jobs before filtering - " + latestjobs.Count());
            //Logger.Log(latestjobs.ToList<Job>()[0].Title);

            return(latestjobs.ToList <Job>());
        }