initial, seems to work
This commit is contained in:
parent
541432ef9b
commit
a983871803
2
.gitignore
vendored
2
.gitignore
vendored
@ -373,3 +373,5 @@ FodyWeavers.xsd
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
MagicCompRules.txt
|
||||
MagicCompRules.NoNums.txt
|
26
.vscode/launch.json
vendored
Normal file
26
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/bin/Debug/net5.0/mtg-rules-dler.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
42
.vscode/tasks.json
vendored
Normal file
42
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/mtg-rules-dler.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/mtg-rules-dler.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/mtg-rules-dler.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
64
Program.cs
Normal file
64
Program.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
namespace mtg_rules_dler
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
HtmlWeb web = new HtmlWeb();
|
||||
|
||||
var htmlDoc = web.Load("https://magic.wizards.com/en/game-info/gameplay/rules-and-formats/rules");
|
||||
|
||||
var links = htmlDoc.DocumentNode.SelectNodes("//div[contains(@id,'comprehensive-rules')]//a");
|
||||
if (links == null || links.Count == 0)
|
||||
{
|
||||
Console.Error.WriteLine("can't find any links.");
|
||||
return;
|
||||
}
|
||||
|
||||
var linkTarget = "";
|
||||
var found = false;
|
||||
foreach (var link in links)
|
||||
{
|
||||
linkTarget = link.Attributes["href"]?.Value;
|
||||
if (linkTarget?.EndsWith(".txt") == true)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
Console.Error.WriteLine("couldn't find link to rules.txt");
|
||||
return;
|
||||
}
|
||||
|
||||
var request = WebRequest.Create(linkTarget);
|
||||
var response = request.GetResponse();
|
||||
|
||||
var responseAsText = "";
|
||||
using (var dataStream = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
responseAsText = dataStream.ReadToEnd();
|
||||
}
|
||||
|
||||
if (File.Exists("MagicCompRules.txt"))
|
||||
{
|
||||
if (File.ReadAllText("MagicCompRules.txt") == responseAsText)
|
||||
{
|
||||
Console.WriteLine("no update.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
File.WriteAllText("MagicCompRules.txt", responseAsText);
|
||||
|
||||
File.WriteAllText("MagicCompRules.NoNums.txt", new Regex("\\b\\d+(\\.\\d+)?([\\w]+)?\\b").Replace(responseAsText, "#"));
|
||||
}
|
||||
}
|
||||
}
|
13
mtg-rules-dler.csproj
Normal file
13
mtg-rules-dler.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<RootNamespace>mtg_rules_dler</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.39" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user