예제 #1
0
        static void Main(string[] args)
        {
            string key = Keys.GetIndeedKey();

            var outLines = new List <string>();

            const string searchTerms = "webgl";
            string       outFile     = string.Format("'{0}' by location.csv", searchTerms);

            File.WriteAllLines(outFile, new[] { "Query,Date,City,State,Source,Sponsored,Expired,FormattedRelativeTime" });

            var        queryUrl = IndeedQueryUtil.BuildBatchQueryFormatUrl(key, searchTerms);
            List <Job> jobs     = IndeedQueryUtil.GetAllJobs(queryUrl, key);

            outLines.AddRange(jobs.Select(job => string.Format("{0},\"{1}\",{2},{3},\"{4}\",{5},{6},{7},\"{8}\"",
                                                               searchTerms, job.Date, job.City, job.State, job.Source,
                                                               job.Sponsored, job.Expired, job.FormattedRelativeTime,
                                                               job.Snippet)));
            File.AppendAllLines(outFile, outLines);

            var cityGroups    = jobs.GroupBy(x => x.City).OrderByDescending(x => x.Count());
            var groupOutLines =
                cityGroups.Select(cityGroup => string.Format("{0} jobs in {1}", cityGroup.Count(), cityGroup.Key))
                .ToList();

            File.AppendAllLines(outFile, groupOutLines);
        }
예제 #2
0
        public static List <FullJob> GetJobs()
        {
            string key = Keys.GetIndeedKey();

            string searchTerms = "scala";
            string location    = "Baltimore, MD";
            int    radius      = 25;

            List <FullJob> jobs;
            var            cachedResults = $"{searchTerms}_{location}_{radius}.json";

            if (File.Exists(cachedResults))
            {
                jobs = JsonConvert.DeserializeObject <List <FullJob> >(File.ReadAllText(cachedResults));
            }
            else
            {
                var queryUrl        = IndeedQueryUtil.BuildBatchQueryFormatUrl(key, searchTerms, location, radius);
                var jobQueryResults = IndeedQueryUtil.GetAllJobs(queryUrl, key);

                jobs = new List <FullJob>();

                foreach (var job in jobQueryResults)
                {
                    Thread.Sleep(1000);
                    var document     = NSoupClient.Connect(job.Url).Timeout(5000).Get();
                    var summaryNodes = document.Select("#job_summary");
                    var fullText     = summaryNodes.Text;

                    jobs.Add(new FullJob
                    {
                        JobQueryResult = job,
                        FullText       = fullText
                    });
                }

                string json = JsonConvert.SerializeObject(jobs, Formatting.Indented);
                File.WriteAllText(cachedResults, json);
            }

            return(jobs);
        }