<commit_before>using System;
using Hanselman.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using System.Xml.Linq;
using System.Linq;
using Hanselman.Functions.Models;
using System.Net.Http;
using System.Text;
using System.Json;
using System.IO;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.Net;

namespace Hanselman.Functions.Triggers
{
    public static class TwitterFunctions
    {
        [FunctionName("GetTweets")]
        public static HttpResponseMessage RunGetTweets(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req,
            [Blob("hanselman/twitter.json", FileAccess.Read, Connection = "AzureWebJobsStorage")]Stream inBlob,
            ILogger log)
        {
            try
            {
                log.LogInformation("Reading feed to twitter.");
                var json = string.Empty;
                using (var reader = new StreamReader(inBlob))
                {
                    json = reader.ReadToEnd();
                }

                log.LogInformation("Finished reading twitter feed from stream.");

                return new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(json, Encoding.UTF8, "application/json")
                };          

            }
            catch (Exception ex)
            {
                log.LogError(ex, "Unable to get twitter feed");
            }

            return new HttpResponseMessage(HttpStatusCode.InternalServerError);
        }

        [FunctionName("TwitterUpdate")]
        public static async Task RunTwitterUpdate(
#if DEBUG
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req,
#else
            [TimerTrigger("0 */10 * * * *")]TimerInfo myTimer,
#endif
            [Blob("hanselman/twitter.json", FileAccess.Write, Connection = "AzureWebJobsStorage")]Stream outTwitterBlob,
            [HttpClientFactory]HttpClient client,
            ILogger log)
        {
            try
            {

                log.LogInformation("Getting twitter feed.");

                var tweetsRaw = await TwitterHelpers.GetTweets(client);

                var json = JsonConvert.SerializeObject(tweetsRaw);

                log.LogInformation("Writting feed to blob.");
                using (var writer = new StreamWriter(outTwitterBlob))<commit_msg>Cleanup times<commit_after>using System;
using Hanselman.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using System.Xml.Linq;
using System.Linq;
using Hanselman.Functions.Models;
using System.Net.Http;
using System.Text;
using System.Json;
using System.IO;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.Net;

namespace Hanselman.Functions.Triggers
{
    public static class TwitterFunctions
    {
        [FunctionName("GetTweets")]
        public static HttpResponseMessage RunGetTweets(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req,
            [Blob("hanselman/twitter.json", FileAccess.Read, Connection = "AzureWebJobsStorage")]Stream inBlob,
            ILogger log)
        {
            try
            {
                log.LogInformation("Reading feed to twitter.");
                var json = string.Empty;
                using (var reader = new StreamReader(inBlob))
                {
                    json = reader.ReadToEnd();
                }

                log.LogInformation("Finished reading twitter feed from stream.");

                return new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(json, Encoding.UTF8, "application/json")
                };          

            }
            catch (Exception ex)
            {
                log.LogError(ex, "Unable to get twitter feed");
            }

            return new HttpResponseMessage(HttpStatusCode.InternalServerError);
        }

        [FunctionName("TwitterUpdate")]
        public static async Task RunTwitterUpdate(
#if DEBUG
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req,
#else
            [TimerTrigger("0 */15 * * * *")]TimerInfo myTimer,
#endif
            [Blob("hanselman/twitter.json", FileAccess.Write, Connection = "AzureWebJobsStorage")]Stream outTwitterBlob,
            [HttpClientFactory]HttpClient client,
            ILogger log)
        {
            try
            {

                log.LogInformation("Getting twitter feed.");

                var tweetsRaw = await TwitterHelpers.GetTweets(client);

                var json = JsonConvert.SerializeObject(tweetsRaw);

                log.LogInformation("Writting feed to blob.");
                using (var writer = new StreamWriter(outTwitterBlob))
{'fraction_non_alphanumeric': 0.09288767975126312, 'fraction_numerical': 0.001554605518849592, 'mean_word_length': 2.204856787048568, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5521860', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1278, 'n_words': 298}