Skip to content

Commit

Permalink
Fixed issue #2.
Browse files Browse the repository at this point in the history
Updated libraries.
  • Loading branch information
josago97 committed Jul 25, 2023
1 parent 1da1b06 commit fe172ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions RAE/RAE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/josago97/RAE.NET</RepositoryUrl>
<PackageTags>RAE, Diccionario, España, Español, Lengua, Dictionary, Spain, Spanish, Language</PackageTags>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.49" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.50" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
19 changes: 7 additions & 12 deletions RAE/RAEAPI.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -57,16 +55,13 @@ public async Task<string[]> GetKeysAsync(string query)
public async Task<Word> GetRandomWordAsync()
{
string response = await _httpClient.GetStringAsync($"{URLBASE}/random");
XmlDocument xml = new XmlDocument();
xml.LoadXml($"<root>{response}</root>");

string idFormat = "article id=\"";
Match idMatch = Regex.Match(response, $@"{idFormat}\w+");
string id = Regex.Replace(idMatch.Value, idFormat, "");
string id = xml.DocumentElement.SelectSingleNode("//article").Attributes["id"].Value;
string content = xml.DocumentElement.SelectSingleNode("//header").InnerText;

string contentFormat = "class=\"f\".*?>";
Match contentMatch = Regex.Match(response, $@"{contentFormat}\w[\,\s\w]*");
string content = Regex.Replace(contentMatch.Value, contentFormat, "");

return new Word(id, HtmlDecode(content));
return new Word(id, content);
}

public async Task<Word> GetWordOfTheDayAsync()
Expand Down

0 comments on commit fe172ac

Please sign in to comment.