public async Task <TelegraphSimplePage> RetrieveTodaysPost(DateTimeOffset dateTimeOffset) { Page result = null; var hasResultsPendingToCheck = true; var currentOffset = 0; try { while (hasResultsPendingToCheck) { var pageList = await _secureClient.GetPageListAsync(offset : currentOffset, limit : 50); if (pageList.Pages.Count == 50) { currentOffset += 50; } else { hasResultsPendingToCheck = false; while (pageList.Pages.All(x => x.Title.FromTitleWithDate() != null)) { currentOffset -= 50; pageList = await _secureClient.GetPageListAsync(offset : currentOffset, limit : 50); } } var(item1, item2) = Result(dateTimeOffset, pageList, hasResultsPendingToCheck); result = item1; hasResultsPendingToCheck = !item2 && hasResultsPendingToCheck; } } catch (Exception e) { if (e.Message.Contains("FLOOD_WAIT_")) { _logger.LogError("Error while retrieving the posts from the API {0}, waiting 30 seconds.", e.Message); Thread.Sleep(TimeSpan.FromSeconds(30)); } else if (e.Message.Contains("ERROR")) { _logger.LogError("The API returned an error {0}.", e.Message); } } if (result == null) { return(null); } var pageContents = await _client.GetPageAsync(result.Path, true); return(pageContents.ToSimpleTelegraphDto(dateTimeOffset.Date)); }
public async Task <bool> CheckIfPageExistsOnTelegraph(string title) { var validationResult = false; var hasResultsPendingToCheck = true; var currentOffset = 0; try { while (hasResultsPendingToCheck) { var pageList = await _secureClient.GetPageListAsync(offset : currentOffset, limit : 50); if (pageList.Pages.Count == 50) { currentOffset += 50; } else { hasResultsPendingToCheck = false; } if (pageList.Pages.Any(page => page.Title == title)) { validationResult = true; _logger.LogInformation("Post '{0}' exists on the API", pageList.Pages.Find(x => x.Title == title)?.Url); break; } } } catch (Exception e) { if (e.Message.Contains("FLOOD_WAIT_")) { _logger.LogError("Error while retrieving the posts from the API {0}, waiting 30 seconds.", e.Message); Thread.Sleep(TimeSpan.FromSeconds(30)); } } if (!validationResult) { _logger.LogInformation("Post '{0}' doesn't exist on the API", title); } return(validationResult); }
public async Task <PageList> GetPageListFromTelegraph(int offset) { try { var result = await _secureClient.GetPageListAsync(offset : offset, limit : 10); return(result); } catch (Exception e) { if (e.Message.Contains("FLOOD_WAIT_")) { _logger.LogError("Error while retrieving the posts from the API {0}, waiting 12 seconds.", e.Message); Thread.Sleep(TimeSpan.FromSeconds(12)); } } return(null); }