Skip to content

Commit

Permalink
deprecated api fixes, nuget update.
Browse files Browse the repository at this point in the history
  • Loading branch information
meetox80 committed Jan 16, 2024
1 parent e4613a8 commit a974b40
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 45 deletions.
2 changes: 1 addition & 1 deletion zstio-tv/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class Config

#region API's
public static string VersionAPI = "https://raw.githubusercontent.com/lemonekq/zstio-tv/main/.version";
public static string ReplacementsAPI = "https://zastepstwa.awfulworld.space/api/getSubstitutions";
public static string ReplacementsAPI = "http://kristofc.webd.pro/plan/InformacjeOZastepstwach.html";

public static string SpotifyID = "859de286484544ad859832003ac4e6b4";
public static string SpotifyAuth = "f10212b6f8d74b058f5685edfdc92704";
Expand Down
1 change: 0 additions & 1 deletion zstio-tv/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void ReloadReplacements()
{
if (checkbox_short.IsChecked == true)

Check failure on line 43 in zstio-tv/ConfigWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The name 'checkbox_short' does not exist in the current context
{
MainWindow.ReplacementsGETAPI_Tick(null, null);
MainWindow.ReplacementsCALC_Tick(null, null);
}
}
Expand Down
2 changes: 1 addition & 1 deletion zstio-tv/Helpers/ILesson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static string[] GetLessons()

// replace the api after lessons
if (TemponaryState == 1)
MainWindow.ReplacementsGETAPI_Tick(null, null);
MainWindow.ReplacementsCALC_Tick(null, null);

return new string[] { "Przerwa", $"{TimeToNextLessonOrBreak.ToString(@"hh\:mm\:ss")}" };
}
Expand Down
78 changes: 72 additions & 6 deletions zstio-tv/Helpers/IReplacements.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,75 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Linq;

namespace zstio_tv.Helpers
{

/*
*
* See the deprecated API from zstio-substitutions: https://github.com/rvyk/zstio-substitutions/blob/main/src/pages/api/getSubstitutions.ts
* -> Archived, and moved into an one repo (rvyk/zstio-timetable)
*
*/
internal class IReplacementsAPI
{
public static string GetReplacements()
{
using (var Client = new HttpClient())
{
try
{
var RawContent = Client.GetStringAsync(Config.ReplacementsAPI).Result;
var Document = new HtmlAgilityPack.HtmlDocument();
Document.LoadHtml(RawContent);

var TimeNode = Document.DocumentNode.SelectSingleNode("//h2");
var Time = TimeNode?.InnerText.Trim();
var TableNodes = Document.DocumentNode.SelectNodes("//table");

var Tables = TableNodes?.Select(table => new
{
Time = table.SelectSingleNode(".//tr[1]")?.InnerText.Trim(),
Zastepstwa = table.SelectNodes(".//tr[position()>1]")
?.Select(row => row.SelectNodes(".//td")?.Select(td => td.InnerText.Trim()).ToArray())
?.Where(cols => cols != null && !string.IsNullOrEmpty(cols[0]))
?.Select(cols => new
{
lesson = cols[0],
teacher = cols[1],
branch = cols[2],
subject = cols[3],
@class = cols[4],
@case = cols[5],
message = cols[6]
})
?.ToList()
})?.ToList();

if (Tables != null)
{
var Result = new { time = Time, tables = Tables };
var JsonResult = JsonConvert.SerializeObject(Result);

return JsonResult;
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}

return "{}";
}
}

internal class IReplacements
{
public class Substitution
Expand Down Expand Up @@ -36,6 +98,8 @@ public class Root
public static int CurrentLessonIndexBackup;
public static void ConfigureReplacements()
{
LocalMemory.ReplacementsAPIResponse = IReplacementsAPI.GetReplacements();

try
{
if (LocalMemory.ReplacementsAPIResponse != "")
Expand Down Expand Up @@ -69,6 +133,8 @@ public static void ConfigureReplacements()
replacement = substitution.message;
}

replacement = replacement.Split(new String[] { " - " }, StringSplitOptions.None)[0]; //

if (substitution.@class == "")
{
substitution.@class = "-";
Expand Down Expand Up @@ -101,7 +167,7 @@ public static void ConfigureReplacements()
public static void PlaceElement(string LessonNumber, string branch, string teacher, string replacement, string classroom)
{
Grid HandlerGrid = new Grid();
HandlerGrid.VerticalAlignment = VerticalAlignment.Top;
HandlerGrid.VerticalAlignment = System.Windows.VerticalAlignment.Top;
HandlerGrid.Margin = new Thickness(0, 10, 0, 0);

Rectangle HandlerRectangle = new Rectangle();
Expand All @@ -113,7 +179,7 @@ public static void PlaceElement(string LessonNumber, string branch, string teach
HandlerGrid.Children.Add(HandlerRectangle);

StackPanel HandlerPanel = new StackPanel();
HandlerPanel.Orientation = Orientation.Horizontal;
HandlerPanel.Orientation = System.Windows.Controls.Orientation.Horizontal;

Grid LessonNumberGrid = new Grid();
LessonNumberGrid.Width = 45;
Expand Down Expand Up @@ -146,7 +212,7 @@ public static void PlaceElement(string LessonNumber, string branch, string teach
BranchTextBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFFFF"));
BranchTextBlock.FontSize = 16;
BranchTextBlock.TextAlignment = TextAlignment.Center;
BranchTextBlock.VerticalAlignment = VerticalAlignment.Center;
BranchTextBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center;
BranchGrid.Children.Add(BranchTextBlock);
HandlerPanel.Children.Add(BranchGrid);
Rectangle BranchSpacingRectangle = new Rectangle();
Expand All @@ -162,7 +228,7 @@ public static void PlaceElement(string LessonNumber, string branch, string teach
TeacherTextBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFFFF"));
TeacherTextBlock.FontSize = 16;
TeacherTextBlock.TextAlignment = TextAlignment.Center;
TeacherTextBlock.VerticalAlignment = VerticalAlignment.Center;
TeacherTextBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center;
TeacherGrid.Children.Add(TeacherTextBlock);
HandlerPanel.Children.Add(TeacherGrid);
Rectangle TeacherSpacingRectangle = new Rectangle();
Expand All @@ -183,7 +249,7 @@ public static void PlaceElement(string LessonNumber, string branch, string teach
ReplacementTextBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFFFF"));
ReplacementTextBlock.FontSize = 16;
ReplacementTextBlock.TextAlignment = TextAlignment.Center;
ReplacementTextBlock.VerticalAlignment = VerticalAlignment.Center;
ReplacementTextBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center;
ReplacementGrid.Children.Add(ReplacementTextBlock);
HandlerPanel.Children.Add(ReplacementGrid);

Expand All @@ -195,7 +261,7 @@ public static void PlaceElement(string LessonNumber, string branch, string teach
ClassroomTextBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFFFF"));
ClassroomTextBlock.FontSize = 16;
ClassroomTextBlock.TextAlignment = TextAlignment.Center;
ClassroomTextBlock.VerticalAlignment = VerticalAlignment.Center;
ClassroomTextBlock.VerticalAlignment = System.Windows.VerticalAlignment.Center;
Rectangle ClassroomBackground = new Rectangle();
ClassroomBackground.RadiusX = 5;
ClassroomBackground.RadiusY = 5;
Expand Down
2 changes: 1 addition & 1 deletion zstio-tv/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
<!-- Mark:Zastępstwo -->

<Grid Width="180" HorizontalAlignment="Left" Height="20">
<TextBlock FontFamily="/Font/InterBold/#Inter" Foreground="White" Text="Sala" TextAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock FontFamily="/Font/InterBold/#Inter" Foreground="White" Text="Poprzednia sala" TextAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
<!-- Mark:Sala -->
</StackPanel>
Expand Down
18 changes: 1 addition & 17 deletions zstio-tv/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ private void WindowLoaded(object sender, RoutedEventArgs e)
}

// Reload the Replacements functionality, start the replacements scrolling
ReplacementsGETAPI_Tick(null, null);
ReplacementsCALC_Tick(null, null);
GetWeatherTick(null, null);
ClockTimerTick(null, null);
Expand Down Expand Up @@ -85,7 +84,7 @@ private void WindowLoaded(object sender, RoutedEventArgs e)
TabTimer.Tick += TabTimerTick;
TabTimer.Start();
DispatcherTimer ReplacementsCALC = new DispatcherTimer();
ReplacementsCALC.Interval = TimeSpan.FromSeconds(10);
ReplacementsCALC.Interval = TimeSpan.FromMinutes(5);
ReplacementsCALC.Tick += ReplacementsCALC_Tick;
ReplacementsCALC.Start();
DispatcherTimer SpotifyCurrentPlaying = new DispatcherTimer();
Expand Down Expand Up @@ -226,21 +225,6 @@ private void TabTransition(float FromOpacity, float ToOpacity)
}

public static void ReplacementsCALC_Tick(object sender, EventArgs e) => IReplacements.ConfigureReplacements();

public static void ReplacementsGETAPI_Tick(object sender, EventArgs e)
{
using (HttpClient Client = new HttpClient())
{
try
{
LocalMemory.ReplacementsAPIResponse = Client.GetStringAsync(Config.ReplacementsAPI).Result;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
}

int PageTime = 0; int PageIndex = 0; public static int PageLength = 30, Pages = 2;
private void TabTimerTick(object sender, EventArgs e)
Expand Down
13 changes: 7 additions & 6 deletions zstio-tv/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Aspose.Zip" version="23.9.0" targetFramework="net48" />
<package id="Aspose.Zip" version="23.12.0" targetFramework="net48" />
<package id="Costura.Fody" version="5.7.0" targetFramework="net472" developmentDependency="true" />
<package id="Fody" version="6.8.0" targetFramework="net472" developmentDependency="true" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net48" />
<package id="HtmlAgilityPack" version="1.11.57" targetFramework="net48" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net48" />
<package id="Microsoft.NETCore.Platforms" version="7.0.4" targetFramework="net472" />
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net472" />
<package id="NETStandard.Library" version="2.0.3" targetFramework="net472" />
Expand All @@ -14,7 +15,7 @@
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net472" />
<package id="System.Console" version="4.3.1" targetFramework="net472" />
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net472" />
<package id="System.Diagnostics.DiagnosticSource" version="7.0.2" targetFramework="net472" />
<package id="System.Diagnostics.DiagnosticSource" version="8.0.0" targetFramework="net48" />
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net472" />
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net472" />
<package id="System.Globalization" version="4.3.0" targetFramework="net472" />
Expand Down Expand Up @@ -48,10 +49,10 @@
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net472" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net472" />
<package id="System.Text.Encoding" version="4.3.0" targetFramework="net472" />
<package id="System.Text.Encoding.CodePages" version="4.5.0" targetFramework="net48" />
<package id="System.Text.Encoding.CodePages" version="8.0.0" targetFramework="net48" />
<package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net472" />
<package id="System.Text.Encodings.Web" version="7.0.0" targetFramework="net48" />
<package id="System.Text.Json" version="7.0.2" targetFramework="net48" />
<package id="System.Text.Encodings.Web" version="8.0.0" targetFramework="net48" />
<package id="System.Text.Json" version="8.0.1" targetFramework="net48" />
<package id="System.Text.RegularExpressions" version="4.3.1" targetFramework="net472" />
<package id="System.Threading" version="4.3.0" targetFramework="net472" />
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net472" />
Expand Down
27 changes: 15 additions & 12 deletions zstio-tv/zstio-tv.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@
<ApplicationIcon>logo.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Aspose.Zip, Version=23.9.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
<HintPath>..\packages\Aspose.Zip.23.9.0\lib\net40\Aspose.Zip.dll</HintPath>
<Reference Include="Aspose.Zip, Version=23.12.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL">
<HintPath>..\packages\Aspose.Zip.23.12.0\lib\net40\Aspose.Zip.dll</HintPath>
</Reference>
<Reference Include="Costura, Version=5.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<Reference Include="HtmlAgilityPack, Version=1.11.57.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlAgilityPack.1.11.57\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
Expand All @@ -75,8 +78,8 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=7.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.7.0.2\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath>
<Reference Include="System.Diagnostics.DiagnosticSource, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.8.0.0\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Diagnostics.Tracing, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll</HintPath>
Expand Down Expand Up @@ -190,14 +193,14 @@
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Text.Encoding.CodePages, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encoding.CodePages.4.5.0\lib\net461\System.Text.Encoding.CodePages.dll</HintPath>
<Reference Include="System.Text.Encoding.CodePages, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encoding.CodePages.8.0.0\lib\net462\System.Text.Encoding.CodePages.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=7.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.7.0.2\lib\net462\System.Text.Json.dll</HintPath>
<Reference Include="System.Text.Json, Version=8.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.8.0.1\lib\net462\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Text.RegularExpressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.RegularExpressions.4.3.1\lib\net463\System.Text.RegularExpressions.dll</HintPath>
Expand Down

0 comments on commit a974b40

Please sign in to comment.