Parcourir la source

Archival Tools

LH il y a 4 ans
Parent
commit
30772fe498

+ 3 - 0
ArchiveTools/.gitignore

@@ -0,0 +1,3 @@
+bin
+obj
+.vs

+ 25 - 0
ArchiveTools/ArchiveTools.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.31129.286
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackExchangeLinker", "StackExchangeLinker\StackExchangeLinker.csproj", "{BF296E2D-E519-4E2F-8812-2B0ECEF0C12C}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{BF296E2D-E519-4E2F-8812-2B0ECEF0C12C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{BF296E2D-E519-4E2F-8812-2B0ECEF0C12C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{BF296E2D-E519-4E2F-8812-2B0ECEF0C12C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{BF296E2D-E519-4E2F-8812-2B0ECEF0C12C}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {961CF10E-61E6-43A2-B411-D1D297E81523}
+	EndGlobalSection
+EndGlobal

+ 2 - 0
ArchiveTools/StackExchangeLinker/Neues Textdokument.txt

@@ -0,0 +1,2 @@
+bin
+obj

+ 62 - 0
ArchiveTools/StackExchangeLinker/Program.cs

@@ -0,0 +1,62 @@
+using HtmlAgilityPack;
+using System;
+using System.IO;
+using System.Xml;
+
+namespace StackExchangeLinker
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            foreach(string arg in args)
+            {
+                XmlReader r = XmlReader.Create(arg);
+                using TextWriter tw = new StreamWriter(arg + ".txt"); //C# 8, selfdestructs at scope end
+                r.MoveToContent();
+                while (r.Read())
+                {
+                    Console.WriteLine("READ");
+                    var body = r.GetAttribute("Body");
+                    if (body != null)
+                    {
+                        var parseMsgBody = String.Format(@"<html><body>{0}</body></html>", body);
+                        var doc = new HtmlDocument();
+                        doc.LoadHtml(parseMsgBody);
+                        var nodes = doc.DocumentNode.SelectNodes("//a");
+
+                        if (nodes != null)
+                        {
+                            foreach (var node in nodes)
+                            {
+                                var link = node.Attributes["href"].Value + "\n";
+                                if (!link.StartsWith("/"))
+                                {
+                                    tw.Write(link);
+                                }
+                            }
+                        }
+                        nodes = doc.DocumentNode.SelectNodes("//img");
+
+                        if (nodes != null)
+                        {
+                            foreach (var node in nodes)
+                            {
+                                var link = node.Attributes["src"].Value + "\n";
+                                if (!link.StartsWith("/"))
+                                {
+                                    tw.Write(link);
+                                }
+                                else
+                                {
+                                    throw new Exception("BLAH!, this shouldnt have happened at all. Not sure what fudgery is the reason");
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            
+        }
+    }
+}

+ 12 - 0
ArchiveTools/StackExchangeLinker/StackExchangeLinker.csproj

@@ -0,0 +1,12 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net5.0</TargetFramework>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="HtmlAgilityPack" Version="1.11.33" />
+  </ItemGroup>
+
+</Project>