mirror of
https://github.com/sbrl/PolyFeed.git
synced 2024-11-22 06:23:02 +00:00
Set out some data structures and start using MicrosoftSyndicationFeed.ReaderWriter, but it's not finished yet
This commit is contained in:
parent
7276b8cf6b
commit
59a0289b3a
5 changed files with 317 additions and 4 deletions
30
PolyFeed/FeedBuilder.cs
Normal file
30
PolyFeed/FeedBuilder.cs
Normal file
|
@ -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());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
56
PolyFeed/FeedSource.cs
Normal file
56
PolyFeed/FeedSource.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
namespace PolyFeed
|
||||
{
|
||||
public enum SourceType { HTML, XML, JSON };
|
||||
|
||||
public class FeedSource
|
||||
{
|
||||
/// <summary>
|
||||
/// The url of the source document to parse.
|
||||
/// </summary>
|
||||
/// <value>The URL.</value>
|
||||
public string Url { get; set; }
|
||||
/// <summary>
|
||||
/// The title of the feed.
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// The type of source document to expect.
|
||||
/// </summary>
|
||||
public SourceType SourceType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A selector that matches against an element that contains the URL that an
|
||||
/// entry should link to.
|
||||
/// Relative to the element selected by <see cref="EntrySelector" />.
|
||||
/// </summary>
|
||||
public string UrlSelector { get; set; }
|
||||
/// <summary>
|
||||
/// The name of the attribute on the element selected by <see cref="UrlSelector" />.
|
||||
/// Set to an empty string to select the content of the element instead of the
|
||||
/// content of an attribute.
|
||||
/// </summary>
|
||||
public string UrlElementAttribute { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="SourceType" />.
|
||||
/// - HTML: CSS selector (e.g. main > article)
|
||||
/// - XML: XPath (e.g. //element_name)
|
||||
/// - JSON: Dotted object (e.g. items.fruit)
|
||||
/// </summary>
|
||||
public string EntrySelector { get; set; }
|
||||
/// <summary>
|
||||
/// 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 <see cref="EntrySelector" /> does.
|
||||
/// </summary>
|
||||
public string EntryTitle { get; set; }
|
||||
/// <summary>
|
||||
/// Same as <see cref="EntryTitle" />, but for the body of an entry. HTML is allowed.
|
||||
/// </summary>
|
||||
public string EntryContent { get; set; }
|
||||
}
|
||||
}
|
|
@ -30,10 +30,116 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Fizzler">
|
||||
<HintPath>..\packages\Fizzler.1.2.0\lib\netstandard2.0\Fizzler.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="HtmlAgilityPack">
|
||||
<HintPath>..\packages\HtmlAgilityPack.1.11.9\lib\Net45\HtmlAgilityPack.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Win32.Primitives">
|
||||
<HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System.AppContext">
|
||||
<HintPath>..\packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Console">
|
||||
<HintPath>..\packages\System.Console.4.3.1\lib\net46\System.Console.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Diagnostics.Tracing">
|
||||
<HintPath>..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Globalization.Calendars">
|
||||
<HintPath>..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO">
|
||||
<HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Compression">
|
||||
<HintPath>..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Compression.ZipFile">
|
||||
<HintPath>..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.IO.FileSystem.Primitives">
|
||||
<HintPath>..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.FileSystem">
|
||||
<HintPath>..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Linq">
|
||||
<HintPath>..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Linq.Expressions">
|
||||
<HintPath>..\packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Sockets">
|
||||
<HintPath>..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reflection">
|
||||
<HintPath>..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime">
|
||||
<HintPath>..\packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.Composition" />
|
||||
<Reference Include="System.Runtime.Extensions">
|
||||
<HintPath>..\packages\System.Runtime.Extensions.4.3.1\lib\net462\System.Runtime.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.InteropServices">
|
||||
<HintPath>..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation">
|
||||
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Security.Cryptography.Encoding">
|
||||
<HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Security.Cryptography.Primitives">
|
||||
<HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Security.Cryptography.Algorithms">
|
||||
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Security.Cryptography.X509Certificates">
|
||||
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http">
|
||||
<HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.RegularExpressions">
|
||||
<HintPath>..\packages\System.Text.RegularExpressions.4.3.1\lib\net463\System.Text.RegularExpressions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.ReaderWriter">
|
||||
<HintPath>..\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="Fizzler.Systems.HtmlAgilityPack">
|
||||
<HintPath>..\packages\Fizzler.Systems.HtmlAgilityPack.1.2.0\lib\netstandard1.3\Fizzler.Systems.HtmlAgilityPack.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SyndicationFeed.ReaderWriter">
|
||||
<HintPath>..\packages\Microsoft.SyndicationFeed.ReaderWriter.1.0.2\lib\netstandard1.3\Microsoft.SyndicationFeed.ReaderWriter.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="FeedBuilder.cs" />
|
||||
<Compile Include="FeedSource.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
|
||||
</Project>
|
|
@ -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)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
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)
|
||||
{
|
||||
|
||||
///// 1: Parse arguments /////
|
||||
List<string> extras = new List<string>();
|
||||
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
|
||||
|
||||
}
|
||||
}
|
||||
|
|
54
PolyFeed/packages.config
Normal file
54
PolyFeed/packages.config
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Fizzler" version="1.2.0" targetFramework="net47" />
|
||||
<package id="Fizzler.Systems.HtmlAgilityPack" version="1.2.0" targetFramework="net47" />
|
||||
<package id="HtmlAgilityPack" version="1.11.9" targetFramework="net47" />
|
||||
<package id="Microsoft.NETCore.Platforms" version="2.2.2" targetFramework="net47" />
|
||||
<package id="Microsoft.SyndicationFeed.ReaderWriter" version="1.0.2" targetFramework="net47" />
|
||||
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net47" />
|
||||
<package id="NETStandard.Library" version="2.0.3" targetFramework="net47" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net47" />
|
||||
<package id="System.AppContext" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Collections" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Console" version="4.3.1" targetFramework="net47" />
|
||||
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Diagnostics.DiagnosticSource" version="4.5.1" targetFramework="net47" />
|
||||
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Globalization" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.IO" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.IO.Compression" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.IO.FileSystem" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Linq" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Linq.Expressions" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Net.Http" version="4.3.4" targetFramework="net47" />
|
||||
<package id="System.Net.Primitives" version="4.3.1" targetFramework="net47" />
|
||||
<package id="System.Net.Sockets" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.ObjectModel" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Reflection" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Runtime" version="4.3.1" targetFramework="net47" />
|
||||
<package id="System.Runtime.Extensions" version="4.3.1" targetFramework="net47" />
|
||||
<package id="System.Runtime.Handles" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net47" />
|
||||
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net47" />
|
||||
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Text.RegularExpressions" version="4.3.1" targetFramework="net47" />
|
||||
<package id="System.Threading" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Xml.ReaderWriter" version="4.3.1" targetFramework="net47" />
|
||||
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net47" />
|
||||
</packages>
|
Loading…
Reference in a new issue