From 6a97816e33348f776beb94beffd736879037cbb3 Mon Sep 17 00:00:00 2001 From: Spencer Jones Date: Fri, 4 Feb 2022 15:41:54 -0700 Subject: [PATCH] Add project files. --- .gitattributes | 63 ++++ .gitignore | 364 +++++++++++++++++++ PocketRSSSync.sln | 30 ++ PocketRSSSync/Auth.cs | 119 ++++++ PocketRSSSync/Models/PocketItem.cs | 74 ++++ PocketRSSSync/PocketRSSSync.csproj | 20 + PocketRSSSync/Program.cs | 38 ++ PocketRSSSync/Properties/launchSettings.json | 11 + PocketRSSSync/Worker.cs | 96 +++++ PocketRSSSync/appsettings.Development.json | 9 + PocketRSSSync/appsettings.json | 23 ++ README.md | 3 + 12 files changed, 850 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 PocketRSSSync.sln create mode 100644 PocketRSSSync/Auth.cs create mode 100644 PocketRSSSync/Models/PocketItem.cs create mode 100644 PocketRSSSync/PocketRSSSync.csproj create mode 100644 PocketRSSSync/Program.cs create mode 100644 PocketRSSSync/Properties/launchSettings.json create mode 100644 PocketRSSSync/Worker.cs create mode 100644 PocketRSSSync/appsettings.Development.json create mode 100644 PocketRSSSync/appsettings.json create mode 100644 README.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dcbb0e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,364 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.editorconfig +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/PocketRSSSync.sln b/PocketRSSSync.sln new file mode 100644 index 0000000..304a33e --- /dev/null +++ b/PocketRSSSync.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32112.339 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PocketRSSSync", "PocketRSSSync\PocketRSSSync.csproj", "{EDD77FC5-9EF4-4006-8B19-154627F76917}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{50DB3646-6B0C-45F4-835F-1CE7D50817DE}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EDD77FC5-9EF4-4006-8B19-154627F76917}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDD77FC5-9EF4-4006-8B19-154627F76917}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDD77FC5-9EF4-4006-8B19-154627F76917}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDD77FC5-9EF4-4006-8B19-154627F76917}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {30E17C69-CDA5-43B1-BEC0-AFBD0F743BAE} + EndGlobalSection +EndGlobal diff --git a/PocketRSSSync/Auth.cs b/PocketRSSSync/Auth.cs new file mode 100644 index 0000000..a6b5411 --- /dev/null +++ b/PocketRSSSync/Auth.cs @@ -0,0 +1,119 @@ +namespace PocketRSSSync +{ + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Logging; + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + using System.Dynamic; + using System.IO; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Net.Http.Json; + using System.Threading.Tasks; + public class Auth + { + private readonly IConfiguration config; + private readonly ILogger logger; + private readonly HttpClient client; + + public string AuthenticatedUsername { get; private set; } + public string AccessToken { get; private set; } + public string ConsumerKey { get; private set; } + + public Auth(IConfiguration config, HttpClient client, ILogger logger) + { + this.config = config; + this.logger = logger; + this.client = client; + GetAuthentication().Wait(); + } + + private async Task GetAuthentication() + { + var accessToken = config["AuthToken"]; + var userName = config["AuthUser"]; + var consumerKey = config["ConsumerKey"]; + + if (string.IsNullOrWhiteSpace(accessToken)) + { + // throw if null + + var redirectUri = config["AuthRedirectURI"]; + if (string.IsNullOrWhiteSpace(redirectUri)) + { + throw new System.Exception("Didn't parse config"); + } + + var request = new HttpRequestMessage(HttpMethod.Post, "https://getpocket.com/v3/oauth/request"); + + request.Headers.Add("X-Accept", "application/json"); + request.Content = JsonContent.Create(new { consumer_key = consumerKey, redirect_uri = redirectUri }); + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + + var resp = await client.SendAsync(request); + resp.EnsureSuccessStatusCode(); + + var def = new { code = "", state = "" }; + + var obj = JsonConvert.DeserializeAnonymousType(await resp.Content.ReadAsStringAsync(), def); + + logger.LogInformation($"https://getpocket.com/auth/authorize?request_token={obj.code}&redirect_uri={redirectUri}"); + + using (var listener = new HttpListener()) + { + listener.Prefixes.Add($"{redirectUri}/"); + listener.Start(); + logger.LogInformation("Listening for Authentication Response..."); + + HttpListenerContext context = listener.GetContext(); + HttpListenerRequest sentRequest = context.Request; + HttpListenerResponse response = context.Response; + string responseString = $"Successfully authenticated with Pocket!"; + byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); + response.ContentLength64 = buffer.Length; + System.IO.Stream output = response.OutputStream; + output.Write(buffer, 0, buffer.Length); + output.Close(); + listener.Stop(); + } + + request = new HttpRequestMessage(HttpMethod.Post, "https://getpocket.com/v3/oauth/authorize"); + + request.Headers.Add("X-Accept", "application/json"); + request.Content = JsonContent.Create(new { consumer_key = consumerKey, code = obj.code }); + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + + resp = await client.SendAsync(request); + resp.EnsureSuccessStatusCode(); + + var authDef = new { access_token = "", username = "" }; + + var auth = JsonConvert.DeserializeAnonymousType(await resp.Content.ReadAsStringAsync(), authDef); + + logger.LogInformation($"User {auth.username} authenticated with pocket."); + + accessToken = auth.access_token; + userName = auth.username; + + var appSettingsPath = Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"); + var json = File.ReadAllText(appSettingsPath); + var jsonSettings = new JsonSerializerSettings(); + jsonSettings.Converters.Add(new ExpandoObjectConverter()); + jsonSettings.Converters.Add(new StringEnumConverter()); + + dynamic dynConfig = JsonConvert.DeserializeObject(json, jsonSettings); + + dynConfig.AuthToken = accessToken; + dynConfig.AuthUser = userName; + + var newJson = JsonConvert.SerializeObject(dynConfig, Formatting.Indented, jsonSettings); + File.WriteAllText(appSettingsPath, newJson); + } + + ConsumerKey = consumerKey; + AccessToken = accessToken; + AuthenticatedUsername = userName; + } + } +} diff --git a/PocketRSSSync/Models/PocketItem.cs b/PocketRSSSync/Models/PocketItem.cs new file mode 100644 index 0000000..eb1cd8c --- /dev/null +++ b/PocketRSSSync/Models/PocketItem.cs @@ -0,0 +1,74 @@ +namespace PocketRSSSync.Models +{ + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + using System.Collections.Generic; + using System.Dynamic; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Net.Http.Json; + using System.Threading.Tasks; + + internal class PocketItem + { + public string Url { get; set; } + public string Title { get; set; } + + public static async Task> GetPocketItemsAsync(Auth auth, HttpClient client) + { + var request = new HttpRequestMessage(HttpMethod.Post, "https://getpocket.com/v3/get"); + + request.Headers.Add("X-Accept", "application/json"); + request.Content = JsonContent.Create( + new + { + consumer_key = auth.ConsumerKey, + access_token = auth.AccessToken, + detailType = "complete", + state = "all" + }); + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + + var response = await client.SendAsync(request); + response.EnsureSuccessStatusCode(); + + var jsonSettings = new JsonSerializerSettings(); + jsonSettings.Converters.Add(new ExpandoObjectConverter()); + jsonSettings.Converters.Add(new StringEnumConverter()); + + dynamic dynConfig = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync(), jsonSettings); + + var items = new List(); + + foreach (var listItem in dynConfig.list) + { + items.Add(new PocketItem() + { + Title = listItem.Value.given_title, + Url = listItem.Value.given_url + }); + } + + return items; + } + + public static async Task AddPocketItem(Auth auth, HttpClient client, PocketItem item) + { + var request = new HttpRequestMessage(HttpMethod.Post, "https://getpocket.com/v3/add"); + + request.Headers.Add("X-Accept", "application/json"); + request.Content = JsonContent.Create( + new + { + consumer_key = auth.ConsumerKey, + access_token = auth.AccessToken, + url = item.Url, + title = item.Title + }); + request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + + var response = await client.SendAsync(request); + response.EnsureSuccessStatusCode(); + } + } +} diff --git a/PocketRSSSync/PocketRSSSync.csproj b/PocketRSSSync/PocketRSSSync.csproj new file mode 100644 index 0000000..8196cb9 --- /dev/null +++ b/PocketRSSSync/PocketRSSSync.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + dotnet-PocketRSSSync-38427F31-93D9-429E-9CA0-5401B7B884D6 + + + + + + + + + + + + + + + diff --git a/PocketRSSSync/Program.cs b/PocketRSSSync/Program.cs new file mode 100644 index 0000000..34822a8 --- /dev/null +++ b/PocketRSSSync/Program.cs @@ -0,0 +1,38 @@ +namespace PocketRSSSync +{ + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Hosting; + using Microsoft.Extensions.Logging; + using System; + + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration((hostContext, config) => + { + config + .SetBasePath(Environment.CurrentDirectory) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true); + + config.AddEnvironmentVariables(); + }) + .ConfigureServices((hostContext, services) => + { + services.AddHttpClient(); + services.AddHostedService(); + services.AddLogging(logging => + { + var loggingConfig = hostContext.Configuration.GetSection("Logging"); + logging.AddFile(loggingConfig); + }); + }); + } +} diff --git a/PocketRSSSync/Properties/launchSettings.json b/PocketRSSSync/Properties/launchSettings.json new file mode 100644 index 0000000..acd6b55 --- /dev/null +++ b/PocketRSSSync/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "PocketRSSSync": { + "commandName": "Project", + "dotnetRunMessages": "true", + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/PocketRSSSync/Worker.cs b/PocketRSSSync/Worker.cs new file mode 100644 index 0000000..82b9e7d --- /dev/null +++ b/PocketRSSSync/Worker.cs @@ -0,0 +1,96 @@ +namespace PocketRSSSync +{ + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.Hosting; + using Microsoft.Extensions.Logging; + using PocketRSSSync.Models; + using RssFeedParser; + using RssFeedParser.Models; + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Threading; + using System.Threading.Tasks; + + public class Worker : BackgroundService + { + private readonly IConfiguration config; + private readonly ILogger logger; + private readonly HttpClient client; + private int count = 0; + + private Auth Auth { get; set; } + private FeedParser FeedReader { get; set; } + + + public Worker(IConfiguration configuration, ILogger logger, IHttpClientFactory httpClient) + { + this.config = configuration; + this.logger = logger; + this.client = httpClient.CreateClient(); + this.Auth = new Auth(config, client, this.logger); + this.FeedReader = new FeedParser(); + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + var feedReader = new FeedParser(); + + while (!stoppingToken.IsCancellationRequested) + { + var currentItems = await PocketItem.GetPocketItemsAsync(Auth, client); + + var feedUris = config.GetSection("Feeds").Get>(); + + var taskList = new List>(); + + foreach (var feedUri in feedUris) + { + try + { + var feed = (await FeedReader.ParseFeed(feedUri)).Articles; + var skipped = feed.Where(a => a.Link.Contains('#')).OrderBy(a => a.Link).ToList(); + var articles = feed.DistinctBy(a => a.Link).Where(a => !a.Link.Contains('#')).ToList(); + + foreach (var article in articles) + { + if (currentItems.Select(i => i.Url).Contains(article.Link)) + { + continue; + } + + var pocketItem = new PocketItem() + { + Title = article.Title, + Url = article.Link, + }; + + await PocketItem.AddPocketItem(Auth, client, pocketItem); + count++; + } + + foreach (var skip in skipped) + { + logger.LogInformation("Skipped: {}\n{}", skip.Link, skip.Title); + } + } + + catch (HttpRequestException ex) + { + if (ex.StatusCode != System.Net.HttpStatusCode.NotFound) + { + throw; + } + logger.LogError($"{feedUri} returned {ex.StatusCode.ToString()}"); + } + + } + + logger.LogInformation("{count} total items added to Pocket since program starting. Worker running at: {time}", count, DateTimeOffset.Now); + await Task.Delay(new TimeSpan(2, 0, 0), stoppingToken); + } + } + } +} + diff --git a/PocketRSSSync/appsettings.Development.json b/PocketRSSSync/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/PocketRSSSync/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/PocketRSSSync/appsettings.json b/PocketRSSSync/appsettings.json new file mode 100644 index 0000000..4b85705 --- /dev/null +++ b/PocketRSSSync/appsettings.json @@ -0,0 +1,23 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + }, + "File": { + "Path": "app.log", + "Append": true, + "MinLevel": "Information", + "FileSizeLimitBytes": 5000000, + "MaxRollingFiles": 2 + } + }, + "Feeds": [ + "" + ], + "ConsumerKey": "", + "AuthRedirectURI": "http://localhost:9999", + "AuthToken": "", + "AuthUser": "" +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d5385ba --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Pocket RSS Sync +This is a small for-fun project that helped me make a product I use more useful to me. I was looking for a way to consume articles that didn't include paywalls and advertisements. I decided to use Mozilla's Pocket as I like the UI, app, and browser integrations that exist currently. This project is a tool to allow me to automatically deliver RSS feeds to my pocket account. +This is a toy project and is far from finished.