Skip to content

Instantly share code, notes, and snippets.

@anuraj
Created June 12, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anuraj/22016453035fbf40344c60c20be20213 to your computer and use it in GitHub Desktop.
Save anuraj/22016453035fbf40344c60c20be20213 to your computer and use it in GitHub Desktop.
Azure Function
private static readonly AzureKeyCredential Credentials = new AzureKeyCredential("KEY");
private static readonly Uri Endpoint = new Uri("ENDPOINT");
private static readonly string SearchApiKey = "KEY";
private static readonly string BitlyKey = "KEY";
private static readonly string TwitterConsumerKey = "CONSUMERKEY";
private static readonly string TwitterConsumerSecret = "CONSUMERSECRET";
private static readonly string TwitterAccessToken = "ACCESSTOKEN";
private static readonly string TwitterAccessTokenSecret = "ACCESSTOKENSECRET";
private static readonly string[] searchTerms = new[] { "Application Technology", "Architecture",
"Artificial Intelligence", "Open Source", "SAAS", "Business Transformation",
"Digital Transformation", "Database", "Enterprise Systems",
"Information Security", "Programming", "Docker",
"Containers", "Cloud", "Web Based Technology", "Serverless",
"Azure", "Microsoft", "Machine Learning", "Data Analytics" };
[FunctionName(nameof(NewsTweet))]
public static void Run([TimerTrigger("0 0 9-18 * * *")] TimerInfo timerInfo, ILogger log)
{
var startTime = DateTime.UtcNow;
log.LogInformation($"Execution started on:{startTime}");
var random = new Random().Next(searchTerms.Length - 1);
var randomSearchTerms = searchTerms.OrderBy(n => Guid.NewGuid()).ToArray();
var searchTerm = randomSearchTerms[random];
log.LogInformation($"Looking for Search term :{searchTerm}");
var newsResults = GetSearchResults(searchTerm).Result;
log.LogInformation($"Found results:{newsResults.Value.Count}");
if (newsResults.Value.Count >= 1)
{
var news = newsResults.Value[0];
log.LogInformation($"Trying to get keywords for :{news.Name}");
var keywords = GetKeywords(news.Name).Result;
log.LogInformation($"Found Keywords :{keywords}");
log.LogInformation($"About to Start URL generation for:{news.Url}");
var shortLink = CreateShortURL(news.Url).Result;
log.LogInformation($"Short URL Generated:{shortLink}");
var tweet = $"{news.Name} {keywords} {shortLink}";
log.LogInformation($"Tweet Text created:{tweet}");
CreateTweet(tweet);
log.LogInformation($"Execution finished.");
}
log.LogInformation($"Execution finished on:{DateTime.UtcNow}");
log.LogInformation($"Time took:{DateTime.UtcNow - startTime}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment