public ActionResult ProductDetail(string id, string Key) { var modelCrawler = new CMS_CrawlerModels(); try { var model = new PinsModels(); CrawlerHelper.Get_Tagged_PinsDetail(ref model, id); CrawlerHelper.Get_Tagged_OrtherPins(ref modelCrawler, Key, Commons.PinOrtherDefault, "", 1, id); modelCrawler.Pin = model; } catch (Exception) { } return(View(modelCrawler)); }
public bool CrawlData(string Id, string createdBy, ref string msg) { NSLog.Logger.Info("CrawlData: " + Id); var result = true; try { using (var _db = new CMS_Context()) { /* get key by ID */ var keyWord = _db.CMS_KeyWord.Where(o => o.ID == Id && o.Status == (byte)Commons.EStatus.Active).FirstOrDefault(); if (keyWord != null) { /* check time span crawl */ var timeSpanCrawl = DateTime.Now - keyWord.UpdatedDate; if (timeSpanCrawl.Value.TotalMinutes > 5 || keyWord.UpdatedDate == keyWord.CreatedDate) /* 5min to crawl data again */ { /* update crawer date */ var bkTime = keyWord.UpdatedDate; keyWord.UpdatedDate = DateTime.Now; keyWord.UpdatedBy = createdBy; keyWord.KeyWord = keyWord.KeyWord.Trim(); _db.SaveChanges(); /* cookies * User: [email protected] * Pass: pitool.org79 */ if (!string.IsNullOrEmpty(keyWord.CrawlAccountID)) { var _Cookie = keyWord.CMS_Account.Cookies; if (!string.IsNullOrEmpty(_Cookie)) { CrawlerBoardHelper._Cookies = _Cookie; } else { CrawlerHelper._Cookies = "_b = \"AS+B1gn0GdpGgLQl83JubKX1bG19kiuUUvX8lnvITKDHNq2tJcgqXNIQ0cLN+kjq4KM=\"; _pinterest_pfob = enabled; _ga = GA1.2.229901352.1528170174; pnodepath = \"/pin4\"; fba = True; G_ENABLED_IDPS = google; bei = false; logged_out = True; sessionFunnelEventLogged = 1; cm_sub = denied; _auth = 1; csrftoken = fkrSitmDb4vW2kT1G3GfOkcC8mPvl0kV; _pinterest_sess = \"TWc9PSZWaE0xeDZOVm4yL3Yva0VSazRkRjlHR013bk9mdVJBcU9zVEtEOUhXVjhKSFZmZUEreWJiNDYrV3FubVRoVzdqdDF0dmtD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MjB4c1dMND0=\""; } } else { CrawlerHelper._Cookies = "_b = \"AS+B1gn0GdpGgLQl83JubKX1bG19kiuUUvX8lnvITKDHNq2tJcgqXNIQ0cLN+kjq4KM=\"; _pinterest_pfob = enabled; _ga = GA1.2.229901352.1528170174; pnodepath = \"/pin4\"; fba = True; G_ENABLED_IDPS = google; bei = false; logged_out = True; sessionFunnelEventLogged = 1; cm_sub = denied; _auth = 1; csrftoken = fkrSitmDb4vW2kT1G3GfOkcC8mPvl0kV; _pinterest_sess = \"TWc9PSZWaE0xeDZOVm4yL3Yva0VSazRkRjlHR013bk9mdVJBcU9zVEtEOUhXVjhKSFZmZUEreWJiNDYrV3FubVRoVzdqdDF0dmtDcXErcFF6MmlXQUQ3RDVzWERCWTZYZUt4eXMzemkvOGlXRFZQT1J6MjkwampOZlVJUFEvTnNkTUZYMkJ3dGxPTTRKaVIwdGNJY2h1MUhaSHlFT3djd0huNHE0YmtiTTBZR3dVTVB3d0RyYVE4UC8rMjZCYWo2eTJLNGJVSHR6KzRENjlWVE0rNFMxNWdGMUtVL0VtL2RDZktiUFg3M1Y2Z2dEbllPeUxFR3FOdEd6SUJSRTlBMWs1YkJnbTBlWHhwcC9pMmlqRmoydlh0V2VQSGYvYk1zeXlSM2dIU1dmUXIyRWVxWVBPdTYzbHFjcVhYRWRBT0FTQ3VBNmdWMm5QUlREZDdSY2ZQeE1NWklqSUZxNDllVHF1WUVzRFRrRjBXQnZCMVBGTlYxT0UzM1daeHFOUnBBTzliMzFJdmovQ1hQR2Vvc1pkTHNxL1FjT3FrWllTR1d6VHFrd2g5cFBFMmswM3dIa0dOOHVCbGd6aVlKUkJlZlZNeWVyRTBYREcrQVFlUTdRc1NqMlFlQ3RvaWlZMjJXZ1RURmIxNDA2d2JTODRGNk9BYWpoRzVJTUhLMkJ4UDJGb0NmN0NOQXpmZ0FoR08xcElmWmh5S29OeGRadFpDVWR1RGw3ZzZGRS81SlU4UlhSUVlIWm4wRzRJMGFVaTQzdGI3T2ovSCtHR2ZSWlk0M1RCN2JXSmZJRFdQUUpZWVpRMW5ta0pMbXgwT2NZckZJcHg0RTJrTjJlZWJIdXFSdkdJTWNXc2d3NHpXdzFTRGhKVkN4YmY4SCtJaTdSQSt0K2dhc1VDc0tkNnJIeVFhb3BHeDd6OUwvamZsanRKV0ZYNGFmZWFQNGlqNFVqekVFcGUreHU4UGVqZXRuMFVDNE1QbkFuWnJ6YzNjMTF3dVNZUHJ2MjBwMi8xeXNwbnczMlpSa3cvbzVPQUhQSyswNlU4Y2JQaThxNWN1NWtHVm83SWc0YjJVVW1tUWZYcHpWR2RCYS8wRE0yb2RtNUs0NzRteFp4JjVhOXZDbjB5RGtxL1lROE5WOVNDMjB4c1dMND0=\""; } var searchStr = HttpUtility.UrlEncode(keyWord.KeyWord); /* get first class result */ var model = new CMS_CrawlerModels(); CMSPinFactory _fac = new CMSPinFactory(); CrawlerHelper.Get_Tagged_Pins(ref model, searchStr, Commons.PinDefault); if (model != null && model.Pins != null && model.Pins.Any()) { /* get second class result */ var listPinID = model.Pins.Select(o => o.ID).ToList(); Parallel.ForEach(listPinID, pinID => { CrawlerHelper.Get_Tagged_OrtherPins(ref model, searchStr, Commons.PinOrtherDefault, "", 1, pinID); }); } /* create or update pin */ var res = _fac.CreateOrUpdate(model.Pins, keyWord.ID, createdBy, ref msg); if (res == false) { /* back to last crawl data */ //keyWord.UpdatedDate = bkTime; //_db.SaveChanges(); result = false; } else { keyWord.UpdatedDate = DateTime.Now; _db.SaveChanges(); } } } } NSLog.Logger.Info("ResponseCrawlData: " + Id, result); } catch (Exception ex) { msg = "Crawl data is unsuccessfully."; result = false; LogHelper.WriteLogs("ErrorCrawlData: " + Id, JsonConvert.SerializeObject(ex)); NSLog.Logger.Error("ErrorCrawlData: " + Id, ex); } return(result); }