public async Task <String> GetTweetsAndPOSTAReportToPincident() { //https://dev.twitter.com/rest/reference/get/search/tweets adresinde resource information adı altında 15 dk ıçerisinde 450 request yollayabıleceğimiz yazıyor. //maximum count/rpp ( rows per page ) sayısı 100 olduğu için 15 dk içerisinde maximum 45,000 tweet cekebiliriz. //https://dev.twitter.com/rest/public/search adresinde best practices adı altında 10 keyword ve operatorden fazla kullanılmaması oneriliyor. Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string text = File.ReadAllText(@HyperConfig.ilIlce, Encoding.GetEncoding("iso-8859-9")); dynamic cityCounty = JsonConvert.DeserializeObject <dynamic>(text); //Filelar Debug klasoru içinde tutuluyor !!! /* StreamWriter strTweetsJsonFormat = new StreamWriter(Path.Combine(Directory.GetCurrentDirectory(), HyperConfig.tweetsJsonFormat), append: true ); * * StreamWriter strTweets = new StreamWriter(Path.Combine(Directory.GetCurrentDirectory(), HyperConfig.tweets), append: true); * StreamWriter strTweetId = new StreamWriter(Path.Combine(Directory.GetCurrentDirectory(), HyperConfig.tweetId), append: true); * */ TweetFilter tweetFilter = new TweetFilter(); Class.TwitterRequest twitterRequestObject = new Class.TwitterRequest(); Class.PincidentRequest pincidentRequestObject = new Class.PincidentRequest(); String[] screenNames = new string[5] { "@ntv", "@cnnturk", "@Hurriyet", "@gazetesozcu", "@yeniasircomtr" }; String[] categories = new String[5] { HyperConfig.categoryFire, HyperConfig.categoryInfrastructure, HyperConfig.categoryNaturalDisaster, HyperConfig.categorySecurity, HyperConfig.categoryTraffic }; var counter = 0; var filteredTweetArray = new JArray(); var tweetArrayJsonFormat = new JArray(); var tweetIdArrayJsonFormat = new JArray(); int d = 0; foreach (var screenN in screenNames) { foreach (var category in categories) { dynamic tweetsFromRequest = JsonConvert.DeserializeObject <dynamic>(await twitterRequestObject.GetTweets(category, screenN)); tweetArrayJsonFormat.Add(tweetsFromRequest); foreach (var item in tweetsFromRequest.statuses) { if (item.coordinates == null) { for (int i = 0; i < 917; i++) { d++; Class.CriteriaObject.TweetFilterCriteriaObject criteriaObject = new Class.CriteriaObject.TweetFilterCriteriaObject(); criteriaObject.city = cityCounty[i].il.ToString(); criteriaObject.county = cityCounty[i].ilce.ToString(); criteriaObject.item = item; criteriaObject.category = category; criteriaObject.allId = tweetIdArrayJsonFormat; criteriaObject.withCoordinate = false; var filteredTweet = tweetFilter.Filter(criteriaObject); if (filteredTweet != null) { if (await pincidentRequestObject.POSTReport(filteredTweet) == null) { return(null); } filteredTweetArray.Add(filteredTweet); } } counter++; } else { for (int i = 0; i < cityCounty.Count(); i++) { d++; Class.CriteriaObject.TweetFilterCriteriaObject criteriaObject2 = new Class.CriteriaObject.TweetFilterCriteriaObject(); criteriaObject2.city = cityCounty[i].il.ToString(); criteriaObject2.county = cityCounty[i].ilce.ToString(); criteriaObject2.item = item; criteriaObject2.category = category; criteriaObject2.allId = tweetIdArrayJsonFormat; criteriaObject2.withCoordinate = true; var filteredTweet = tweetFilter.Filter(criteriaObject2); if (filteredTweet != null) { if (await pincidentRequestObject.POSTReport(filteredTweet) != null) { return(null); } filteredTweetArray.Add(filteredTweet); } GC.Collect(); } counter++; GC.Collect(); } GC.Collect(); } GC.Collect(); } GC.Collect(); } /* * strTweetId.WriteLine(tweetIdArrayJsonFormat); * * strTweets.WriteLine(filteredTweetArray + "\r\n\r\n"); * * strTweetsJsonFormat.WriteLine(tweetArrayJsonFormat); * * * * strTweetId.Close(); * strTweetsJsonFormat.Close(); * strTweets.Close(); */ GC.Collect(); // var resp= req.get_results_delta(not_coordinates_json); await twitterRequestObject.GetAndLogAccountLimits(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTimeInner :" + elapsedTime); Console.WriteLine(counter.ToString()); Console.WriteLine(d.ToString()); string foo = "foo"; return(foo); }
/// <summary> /// Takes tweet and converts it to a dynamic JObject after applying some filters. /// /// </summary> /// <param name="item"> twitStatus </param> /// <param name="category"></param> /// <param name="city"></param> /// <param name="county"></param> /// <param name="all_id"> allTweetsId</param> /// <returns></returns> public dynamic Filter(Class.CriteriaObject.TweetFilterCriteriaObject criteriaObject) { Class.Utilities utilityObject = new Class.Utilities(); string city = criteriaObject.city; string category = criteriaObject.category; string county = criteriaObject.county; dynamic all_id = criteriaObject.allId; dynamic item = criteriaObject.item; if (city == null || category == null || county == null || all_id == null || item == null) { return(null); } //TODO : variable naminig. GeoLocationDTO location = new GeoLocationDTO(); dynamic jarr = new JArray(); //TODO : resultItem dynamic resultItem = new JObject(); Class.KMPAlgorithm KMP = new Class.KMPAlgorithm(); string P1 = "" + city + "'"; string P2 = "" + city + " "; string P3 = "" + county + "'"; string P4 = "" + county + " "; string[] extra = new String[4] { P1, P2, P3, P4 }; Boolean[] arr = new Boolean[4]; Parallel.For(0, 4, tmp => { arr[tmp] = KMP.Search(extra[tmp].ToString(), item.text.ToString()); }); if (criteriaObject.withCoordinate) { location.Latitude = item.coordinates.coordinates[0]; location.Longitude = item.coordinates.coordinates[1]; location.Address = null; resultItem.Location = location; } else { resultItem.Location = null; } resultItem.Id = null; if (arr[2]) { resultItem.CreatedOn = utilityObject.TweetDate(item); resultItem.City = city; resultItem.County = county; if (item.text.ToString().Substring(0, 2).Equals("RT") != true) { return(NormalTweet(item, all_id, resultItem)); } else { if (item.retweeted_status.id == null) { return(null); } return(Retweet(item, all_id, resultItem)); } } else if (arr[3]) { resultItem.CreatedOn = utilityObject.TweetDate(item); resultItem.City = city; resultItem.County = county; if (item.text.ToString().Substring(0, 2).Equals("RT") != true) { return(NormalTweet(item, all_id, resultItem)); } else { return(Retweet(item, all_id, resultItem)); } } else if (arr[0]) { resultItem.CreatedOn = utilityObject.TweetDate(item); if (arr[2] || arr[3] == true) { resultItem.City = city; resultItem.County = county; } else { resultItem.City = city; resultItem.County = null; } if (item.text.ToString().Substring(0, 2).Equals("RT") != true) { return(NormalTweet(item, all_id, resultItem)); } else { return(Retweet(item, all_id, resultItem)); } } else if (arr[1]) { resultItem.CreatedOn = utilityObject.TweetDate(item); if (arr[2] || arr[3] == true) { resultItem.City = city; resultItem.County = county; } else { resultItem.City = city; resultItem.County = null; } if (item.text.ToString().Substring(0, 2).Equals("RT") != true) { return(NormalTweet(item, all_id, resultItem)); } else { return(Retweet(item, all_id, resultItem)); } } else { return(null); } }