From 59a0289b3a4a6c6d74730e3c72374891614ec1ed Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 14 Jul 2019 01:02:45 +0100 Subject: [PATCH] Set out some data structures and start using MicrosoftSyndicationFeed.ReaderWriter, but it's not finished yet --- PolyFeed/FeedBuilder.cs | 30 +++++++++++ PolyFeed/FeedSource.cs | 56 +++++++++++++++++++++ PolyFeed/PolyFeed.csproj | 106 +++++++++++++++++++++++++++++++++++++++ PolyFeed/Program.cs | 75 +++++++++++++++++++++++++-- PolyFeed/packages.config | 54 ++++++++++++++++++++ 5 files changed, 317 insertions(+), 4 deletions(-) create mode 100644 PolyFeed/FeedBuilder.cs create mode 100644 PolyFeed/FeedSource.cs create mode 100644 PolyFeed/packages.config diff --git a/PolyFeed/FeedBuilder.cs b/PolyFeed/FeedBuilder.cs new file mode 100644 index 0000000..c806efa --- /dev/null +++ b/PolyFeed/FeedBuilder.cs @@ -0,0 +1,30 @@ +using System; +using System.IO; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using Microsoft.SyndicationFeed.Atom; + +namespace PolyFeed +{ + public class FeedBuilder + { + StringBuilder result = new StringBuilder(); + XmlWriter xml = null; + AtomFeedWriter feed = null; + + public FeedBuilder() { + xml = XmlWriter.Create(result); + feed = new AtomFeedWriter(xml); + } + + public async Task AddSource(FeedSource source) { + WebResponse response = await WebRequest.Create(source.Url).GetResponseAsync(); + + using StreamReader reader = new StreamReader(response.GetResponseStream()); + + + } + } +} diff --git a/PolyFeed/FeedSource.cs b/PolyFeed/FeedSource.cs new file mode 100644 index 0000000..1fe2100 --- /dev/null +++ b/PolyFeed/FeedSource.cs @@ -0,0 +1,56 @@ +using System; +namespace PolyFeed +{ + public enum SourceType { HTML, XML, JSON }; + + public class FeedSource + { + /// + /// The url of the source document to parse. + /// + /// The URL. + public string Url { get; set; } + /// + /// The title of the feed. + /// + public string Title { get; set; } + /// + /// The type of source document to expect. + /// + public SourceType SourceType { get; set; } + + /// + /// A selector that matches against an element that contains the URL that an + /// entry should link to. + /// Relative to the element selected by . + /// + public string UrlSelector { get; set; } + /// + /// The name of the attribute on the element selected by . + /// Set to an empty string to select the content of the element instead of the + /// content of an attribute. + /// + public string UrlElementAttribute { get; set; } = ""; + + /// + /// The selector that specifies the location in the object model of nodes that should + /// be added to the feed. + /// The format varies depending on the . + /// - HTML: CSS selector (e.g. main > article) + /// - XML: XPath (e.g. //element_name) + /// - JSON: Dotted object (e.g. items.fruit) + /// + public string EntrySelector { get; set; } + /// + /// The title of an entry. + /// Selectors may be included in curly braces {} to substitute in content. + /// Such selectors are relative to the current feed entry. + /// The format varies in the samem way as does. + /// + public string EntryTitle { get; set; } + /// + /// Same as , but for the body of an entry. HTML is allowed. + /// + public string EntryContent { get; set; } + } +} diff --git a/PolyFeed/PolyFeed.csproj b/PolyFeed/PolyFeed.csproj index c290590..e6489c7 100644 --- a/PolyFeed/PolyFeed.csproj +++ b/PolyFeed/PolyFeed.csproj @@ -30,10 +30,116 @@ + + ..\packages\Fizzler.1.2.0\lib\netstandard2.0\Fizzler.dll + + + ..\packages\HtmlAgilityPack.1.11.9\lib\Net45\HtmlAgilityPack.dll + + + ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll + + + + ..\packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll + + + + ..\packages\System.Console.4.3.1\lib\net46\System.Console.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll + + + ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll + + + ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + + + ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll + + + ..\packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll + + + ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + + + ..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll + + + ..\packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll + + + + ..\packages\System.Runtime.Extensions.4.3.1\lib\net462\System.Runtime.Extensions.dll + + + ..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll + + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll + + + ..\packages\System.Text.RegularExpressions.4.3.1\lib\net463\System.Text.RegularExpressions.dll + + + ..\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll + + + + + ..\packages\Fizzler.Systems.HtmlAgilityPack.1.2.0\lib\netstandard1.3\Fizzler.Systems.HtmlAgilityPack.dll + + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Microsoft.SyndicationFeed.ReaderWriter.1.0.2\lib\netstandard1.3\Microsoft.SyndicationFeed.ReaderWriter.dll + + + + + + + \ No newline at end of file diff --git a/PolyFeed/Program.cs b/PolyFeed/Program.cs index ec804f5..f62d6b2 100644 --- a/PolyFeed/Program.cs +++ b/PolyFeed/Program.cs @@ -1,12 +1,79 @@ using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; -namespace PolyFeed +namespace ProjectNamespace { - class MainClass + internal class Settings { - public static void Main(string[] args) + public readonly string ProgramName = "PolyFeed"; + public readonly string Description = "creates Atom feeds from websites that don't support it"; + // Settings here + } + + class Program + { + private static Settings settings = new Settings(); + + public static int Main(string[] args) { - Console.WriteLine("Hello World!"); + + ///// 1: Parse arguments ///// + List extras = new List(); + for (int i = 0; i < args.Length; i++) + { + if (!args[i].StartsWith("-")) + { + extras.Add(args[i]); + continue; + } + + switch (args[i]) + { + case "-h": + case "--help": + Console.WriteLine($"{settings.ProgramName}, {getProgramVersion()}"); + Console.WriteLine(" By Starbeamrainbowlabs"); + + Console.WriteLine(); + Console.WriteLine($"This program {settings.Description}."); + Console.WriteLine(); + Console.WriteLine("Usage:"); + Console.WriteLine($" ./{Path.GetFileName(Assembly.GetExecutingAssembly().Location)} [arguments]"); + Console.WriteLine(); + Console.WriteLine("Options:"); + Console.WriteLine(" -h --help Displays this message"); + Console.WriteLine(" -v --version Outputs the version number of this program"); + return 0; + + case "-v": + case "--version": + Console.WriteLine($"{settings.ProgramName}\t{getProgramVersion()}"); + return 0; + } + } + + ///// 2: Acquire environment variables ///// + + + ///// 3: Run program ///// + + + + return 0; } + + + #region Helper Methods + + private static string getProgramVersion() + { + Version version = Assembly.GetExecutingAssembly().GetName().Version; + return $"{version.Major}.{version.Minor}"; + } + + #endregion + } } diff --git a/PolyFeed/packages.config b/PolyFeed/packages.config new file mode 100644 index 0000000..7e72b7b --- /dev/null +++ b/PolyFeed/packages.config @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file