public static void SaveSettings(string jsonFilePath, TweetResponse settings) { jsonFilePath = Path.Combine(jsonFilePath, jsonFileName); // serialize JSON to a string and then write string to a file System.IO.File.WriteAllText(jsonFilePath, JsonConvert.SerializeObject(settings)); }
public MapController(IHostingEnvironment host, IConfiguration configuration) { _configuration = configuration; API_KEY = _configuration.GetValue <string>("IncomingMapAPIKey"); var dataFolderPath = host.ContentRootPath + @"/_datastore/"; Settings = SettingsRepository.GetSettings(dataFolderPath); db = new SqLiteMapPointRepository(dataFolderPath); }
private async Task AddTweetToDb(TweetResponse tweet) { var newTweet = new Tweet() { CreatedAt = tweet.CreatedAt, Id = tweet.Id }; _context.Add(newTweet); await _context.SaveChangesAsync(); }
public IActionResult Index(TweetResponse tweetResponse) { SettingsRepository.SaveSettings(_settingsFolderPath, tweetResponse); var model = new SettingsPageModel { ApiKey = _configuration.GetValue <string>("IncomingMapAPIKey"), TweetResponse = tweetResponse }; ViewData["message"] = "Settings saved"; return(View(model)); }
public static TweetResponse GetSettings(string jsonFilePath) { jsonFilePath = Path.Combine(jsonFilePath, jsonFileName); if (!File.Exists(jsonFilePath)) { return(new TweetResponse()); } string json = System.IO.File.ReadAllText(jsonFilePath); TweetResponse settings = JsonConvert.DeserializeObject <TweetResponse>(json); return(settings); }
public ActionResult TweetsForUserLookup(string userName) { var auth = new SingleUserAuthorizer { CredentialStore = new SingleUserInMemoryCredentialStore { ConsumerKey = ConfigurationManager.AppSettings["consumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"], AccessToken = ConfigurationManager.AppSettings["accessToken"], AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"] } }; var twitterCtx = new TwitterContext(auth); var users = (List <User>)Session["Users"]; var user = users.FirstOrDefault(u => u.Name == userName); var tweetList = new List <Status>(); tweetList.AddRange((from tweet in twitterCtx.Status where tweet.Type == StatusType.User && tweet.ScreenName == user.ScreenNameResponse select tweet).ToList()); tweetList = tweetList.Where(t => t.Text.Contains(Session["Trend"].ToString())).ToList(); var resultList = new List <TweetResponse>(); foreach (var item in tweetList) { var model = new TweetResponse(); model.ID = item.StatusID.ToString(); model.FullText = item.FullText; model.ScreenName = item.User.Name; model.UserIDResponse = item.User.UserIDResponse; model.Lat = item.User.Location.ToString(); model.Lng = item.Coordinates.Longitude.ToString(); resultList.Add(model); } Session["TweetList"] = resultList; return(Json(resultList, JsonRequestBehavior.AllowGet)); }
public ActionResult TweetsLookup(string trendId) { var resultList = new List <TweetResponse>(); var auth = new SingleUserAuthorizer { CredentialStore = new SingleUserInMemoryCredentialStore { ConsumerKey = ConfigurationManager.AppSettings["consumerKey"], ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"], AccessToken = ConfigurationManager.AppSettings["accessToken"], AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"] } }; var twitterCtx = new TwitterContext(auth); string searchTerm = trendId; //searchTerm = "кот ("; const int MaxSearchEntriesToReturn = 10; const int MaxTotalResults = 100; // oldest id you already have for this search term ulong sinceID = 1; // used after the first query to track current session ulong maxID; var combinedSearchResults = new List <Status>(); List <Status> searchResponse = (from search in twitterCtx.Search where search.Type == SearchType.Search && search.Query == searchTerm && search.Count == MaxSearchEntriesToReturn && search.SinceID == sinceID && search.TweetMode == TweetMode.Extended select search.Statuses) .SingleOrDefault(); if (searchResponse != null) { combinedSearchResults.AddRange(searchResponse); ulong previousMaxID = ulong.MaxValue; do { // one less than the newest id you've just queried maxID = searchResponse.Min(status => status.StatusID) - 1; Debug.Assert(maxID < previousMaxID); previousMaxID = maxID; searchResponse = (from search in twitterCtx.Search where search.Type == SearchType.Search && search.Query == searchTerm && search.Count == MaxSearchEntriesToReturn && search.MaxID == maxID && search.SinceID == sinceID && search.TweetMode == TweetMode.Extended select search.Statuses) .SingleOrDefault(); combinedSearchResults.AddRange(searchResponse); } while (searchResponse.Any() && combinedSearchResults.Count < MaxTotalResults); foreach (var item in combinedSearchResults.Where(t => t.User.GeoEnabled == true && t.User.Location != "")) { var model = new TweetResponse(); model.ID = item.StatusID.ToString(); model.FullText = item.FullText; model.ScreenName = item.User.Name; model.UserIDResponse = item.User.UserIDResponse; model.Lat = item.User.Location.ToString(); model.Lng = item.Coordinates.Longitude.ToString(); resultList.Add(model); } } else { Console.WriteLine("No entries found."); } Session["TrendQuery"] = trendId; Session["TweetList"] = resultList; return(Json(resultList, JsonRequestBehavior.AllowGet)); }