private static async Task <int> RunAsync(MenuType menuType) { var now = KST.Now; var date = now.ToDateOnly(); Log.Information($"Action started time: {now} KST\n"); var consumerApiKey = GetEnvVariable(ConsumerApiKeyName); var consumerSecretKey = GetEnvVariable(ConsumerSecretKeyName); var accessToken = GetEnvVariable(AccessTokenName); var accessTokenSecret = GetEnvVariable(AccessTokenSecretName); var twitterApiKeys = new TwitterApiKeys(consumerApiKey, consumerSecretKey, accessToken, accessTokenSecret); Log.Information($"Successfully loaded Twitter API keys."); Log.Information("Requesting menu list..."); var weekMenu = await WeekMenu.LoadAsync(); var todayMenu = weekMenu.Find(date); if (todayMenu is null) { Log.Warning($"Cannot found menu of day {now.Day}."); return(0); } var menu = todayMenu[menuType]; if (menu is null || menu.IsEmpty()) { Log.Warning($"Cannot found menu of type {menuType}."); return(0); } Log.Information(menu.ToString()); Log.Information("Generating image..."); var image = await MenuImageGenerator.GenerateAsync(date, menuType, menu); Log.Information($"Image generated. length={image.Length}"); var twitterClient = GetTwitterClient(twitterApiKeys); Log.Information("Tweeting..."); var tweetMessage = GetMenuTweetText(date, menuType); Log.Information($"\n- tweet message -\n{tweetMessage}\n- tweet message -"); #if DEBUG Log.Information("Cannot tweet because it's debug mode."); #else var tweet = await PublishTweetAsync(twitterClient, tweetMessage, image); Log.Information($"Done! {tweet.Url}"); #endif return(0); }
public async Task MenuImageGenTest() { var now = DateTime.Now; var date = now.ToDateOnly(); var weekMenu = CreateTestWeekMenu(date); foreach (var menu in weekMenu) { var imageBytes = await MenuImageGenerator.GenerateAsync(menu.Date, MenuType.Lunch, menu.Lunch); Assert.IsNotNull(imageBytes); } }
public async Task MenuLoadTest() { var menu = await WeekMenu.LoadAsync(); Assert.IsNotNull(menu); if (menu.Count > 0) { foreach (var todayMenu in menu) { if (!todayMenu.Lunch.IsEmpty()) { var imageBytes = await MenuImageGenerator.GenerateAsync(todayMenu.Date, MenuType.Lunch, todayMenu.Lunch); Assert.IsNotNull(imageBytes); } } } }