Esempio n. 1
0
        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);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        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."));
        }