Skip to content

Commit a2a775d

Browse files
committed
Generate NewMascots.txt file
1 parent 125ec92 commit a2a775d

File tree

6 files changed

+257
-0
lines changed

6 files changed

+257
-0
lines changed

.github/workflows/newmascots.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build and Run C# Program
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-and-run:
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v3
19+
20+
- name: Setup .NET
21+
uses: actions/setup-dotnet@v3
22+
with:
23+
dotnet-version: '8.x'
24+
25+
- name: Restore dependencies
26+
working-directory: ./newmascots
27+
run: dotnet restore
28+
29+
- name: Build the project
30+
working-directory: ./newmascots
31+
run: dotnet build --no-restore --configuration Release
32+
33+
- name: Run the program
34+
working-directory: ./newmascots
35+
run: dotnet run --no-build --configuration Release
36+
37+
- name: Verify file generation
38+
run: |
39+
if [ ! -f NewMascots.txt ]; then
40+
echo "NewMascots.txt was not generated."
41+
exit 1
42+
fi
43+
44+
- name: Commit and push changes
45+
run: |
46+
git config user.name "github-actions[bot]"
47+
git config user.email "github-actions[bot]@users.noreply.github.com"
48+
git add NewMascots.txt
49+
git diff-index --quiet HEAD || git commit -m "Update NewMascots.txt"
50+
git push

.vscode/launch.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
// Use IntelliSense to find out which attributes exist for C# debugging
6+
// Use hover for the description of the existing attributes
7+
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/newmascots/bin/Debug/net8.0/MissingMascots.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/newmascots",
16+
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17+
"console": "internalConsole",
18+
"stopAtEntry": false
19+
},
20+
{
21+
"name": ".NET Core Attach",
22+
"type": "coreclr",
23+
"request": "attach"
24+
}
25+
]
26+
}

.vscode/tasks.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/HighSchoolMascotMap.sln",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary;ForceNoAlign"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/HighSchoolMascotMap.sln",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary;ForceNoAlign"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"--project",
36+
"${workspaceFolder}/HighSchoolMascotMap.sln"
37+
],
38+
"problemMatcher": "$msCompile"
39+
}
40+
]
41+
}

newmascots/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Build Folders
2+
bin/
3+
obj/
4+
5+
# Visual Studio Code
6+
.vscode/
7+
8+
# NuGet
9+
*.nupkg
10+
*.snupkg
11+
*.nuget/
12+
13+
# Generated Files
14+
*.exe
15+
*.dll
16+
*.pdb
17+
18+
# OS-specific files
19+
.DS_Store
20+
Thumbs.db
21+
22+
# Temporary files
23+
*.tmp
24+
*.temp
25+
~$*

newmascots/MissingMascots.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

newmascots/Program.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
5+
class Program
6+
{
7+
static async Task Main(string[] args)
8+
{
9+
string filePath = "../Style.ultra";
10+
11+
var lines = File.ReadAllLines(filePath);
12+
13+
bool inPreamble = true;
14+
15+
var mascots = new List<string>();
16+
17+
for (int i = 0; i < lines.Length; i++)
18+
{
19+
if (lines[i] == " - - match")
20+
break;
21+
22+
if (inPreamble)
23+
{
24+
if (lines[i] == " - [ \"get\", \"mascot\" ]")
25+
{
26+
inPreamble = false;
27+
}
28+
continue;
29+
}
30+
31+
if (lines[i].StartsWith(" - - "))
32+
{
33+
mascots.Add(lines[i].Replace(" - - ", ""));
34+
}
35+
else if (lines[i].StartsWith(" - "))
36+
{
37+
mascots.Add(lines[i].Replace(" - ", ""));
38+
}
39+
}
40+
41+
42+
string apiUrl = "https://taginfo.openstreetmap.org/api/4/key/values?key=mascot";
43+
// Call the function to fetch and compare results
44+
List<string> newResults = await FetchAndReturnValues(apiUrl);
45+
PrintNewItems(newResults, mascots);
46+
}
47+
48+
static async Task<List<string>> FetchAndReturnValues(string url)
49+
{
50+
using (HttpClient client = new HttpClient())
51+
{
52+
var values = new List<string>();
53+
54+
try
55+
{
56+
HttpResponseMessage response = await client.GetAsync(url);
57+
response.EnsureSuccessStatusCode();
58+
59+
string responseBody = await response.Content.ReadAsStringAsync();
60+
61+
// Parse the JSON and extract only "value" fields
62+
var jsonData = System.Text.Json.JsonDocument.Parse(responseBody);
63+
var dataArray = jsonData.RootElement.GetProperty("data");
64+
65+
foreach (var item in dataArray.EnumerateArray())
66+
{
67+
if (item.TryGetProperty("value", out var value))
68+
{
69+
values.Add(value.GetString());
70+
}
71+
}
72+
}
73+
catch (Exception e)
74+
{
75+
Console.WriteLine($"Error: {e.Message}");
76+
}
77+
78+
return values;
79+
}
80+
}
81+
static void PrintNewItems(List<string> newResults, List<string> oldResults)
82+
{
83+
string fileName = "../NewMascots.txt";
84+
85+
try
86+
{
87+
using (StreamWriter writer = new StreamWriter(fileName))
88+
{
89+
foreach (var newItem in newResults)
90+
{
91+
if (!oldResults.Contains(newItem))
92+
{
93+
writer.WriteLine(newItem);
94+
}
95+
}
96+
}
97+
98+
Console.WriteLine($"New items have been written to {fileName}");
99+
}
100+
catch (Exception ex)
101+
{
102+
Console.WriteLine($"Error writing to file: {ex.Message}");
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)