public static void Run([TimerTrigger("0 */30 * * * *")] TimerInfo myTimer, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); NosyBot.Services.Repositories.NosyRepository repo = new NosyBot.Services.Repositories.NosyRepository(); List <ProviderRecord> providers = repo.GetProviders(); foreach (ProviderRecord provider in providers) { List <StoryRecord> stories = NosyBot.Services.Utilities.RssUtilities.GetRSSUpdates(provider); if (stories.Count > 0) { System.Diagnostics.Trace.TraceInformation($"Found {stories.Count} new stories from {provider.Name}"); // We have updates repo.UpdateProvider(provider); // Save to db foreach (StoryRecord story in stories) { if (!repo.CheckIfStoryExists(story)) { System.Diagnostics.Trace.TraceInformation($"Adding story {story.Title} from provider {story.ProviderName}"); repo.InsertStory(story); } } } } }
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); NosyBot.Services.Repositories.NosyRepository repo = new NosyBot.Services.Repositories.NosyRepository(); List <ProviderRecord> providers = repo.GetProviders(); foreach (ProviderRecord provider in providers) { List <StoryRecord> stories = NosyBot.Services.Utilities.RssUtilities.GetRSSUpdates(provider); if (stories.Count > 0) { System.Diagnostics.Trace.TraceInformation($"Found {stories.Count} new stories from {provider.Name}"); // We have updates repo.UpdateProvider(provider); // Save to db foreach (StoryRecord story in stories) { if (!repo.CheckIfStoryExists(story)) { System.Diagnostics.Trace.TraceInformation($"Adding story {story.Title} from provider {story.ProviderName}"); repo.InsertStory(story); } } } } return(new OkObjectResult("news checked.")); }
public ActionResult <WorldStoryRecords> Get([FromQuery] int count = 10, [FromQuery] string displayLanguage = "en") { NosyBot.Services.Repositories.NosyRepository repo = new NosyBot.Services.Repositories.NosyRepository(); WorldStoryRecords records = repo.GetRegionStories(count); TranslateCommand translate = new TranslateCommand() { DisplayLanguage = displayLanguage }; // Now translate AMERICAS if necessary foreach (StoryRecord story in records.Americas) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } //story.TranslatedTitle = NosyBot.Services.Utilities.ServiceProxies.GetTranslation(story.Title, story.Language, displayLanguage).Result; } // EMEA foreach (StoryRecord story in records.EMEA) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } //story.TranslatedTitle = NosyBot.Services.Utilities.ServiceProxies.GetTranslation(story.Title, story.Language, displayLanguage).Result; } // APAC foreach (StoryRecord story in records.APAC) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } //story.TranslatedTitle = NosyBot.Services.Utilities.ServiceProxies.GetTranslation(story.Title, story.Language, displayLanguage).Result; } NosyBot.Services.Utilities.ServiceProxies.GetTranslations(translate); return(records); }
public ActionResult <List <StoryRecord> > Get(string country = "us", [FromQuery] int count = 10, [FromQuery] string displayLanguage = "en") { NosyBot.Services.Repositories.NosyRepository repo = new NosyBot.Services.Repositories.NosyRepository(); List <StoryRecord> records = repo.GetLatestStoriesForCountry(country, count); TranslateCommand translate = new TranslateCommand() { DisplayLanguage = displayLanguage }; foreach (StoryRecord story in records) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } NosyBot.Services.Utilities.ServiceProxies.GetTranslations(translate); return(records); }
public ActionResult <ContinentStoryRecords> Continents([FromQuery] int count = 10, [FromQuery] string displayLanguage = "en") { NosyBot.Services.Repositories.NosyRepository repo = new NosyBot.Services.Repositories.NosyRepository(); ContinentStoryRecords records = repo.GetContinentStories(count); TranslateCommand translate = new TranslateCommand() { DisplayLanguage = displayLanguage }; // Translate NA foreach (StoryRecord story in records.NorthAmerica) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate SA foreach (StoryRecord story in records.SouthAmerica) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate EU foreach (StoryRecord story in records.Europe) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate AS foreach (StoryRecord story in records.Asia) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate AF foreach (StoryRecord story in records.Africa) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } // Translate AU foreach (StoryRecord story in records.Australia) { story.TranslatedTitle = story.Title; if (story.Language != null && story.Language != displayLanguage) { translate.AddStory(story); } } NosyBot.Services.Utilities.ServiceProxies.GetTranslations(translate); return(records); }