Skip to content

Commit

Permalink
Fix U.GG provider and a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Jun 3, 2019
1 parent 5d4c9b5 commit 8b8f795
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
29 changes: 10 additions & 19 deletions Legendary Rune Maker/Data/Providers/UGGProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Legendary_Rune_Maker.Data.Providers
Expand All @@ -21,6 +22,7 @@ internal class UGGProvider : Provider

private const string UGGApiVersion = "1.1";
private const string UGGDataVersion = "1.2";
private const string UGGOverviewVersion = "1.2.5";

private readonly static IDictionary<int, Position> IdToPosition = new Dictionary<int, Position>
{
Expand All @@ -36,36 +38,25 @@ private async Task<string> GetLolUGGVersion()
{
if (_LolUGGVersion == null)
{
var url = $"https://u.gg/json/new_ugg_versions/{UGGDataVersion}.json";
var json = JObject.Parse(await WebCache.String(url));
_LolUGGVersion = (json.Children().First().Next as JProperty).Name;
}

return _LolUGGVersion;
}
var page = await WebCache.String("https://u.gg");
var scriptUrl = Regex.Match(page, @"(?<=<script src="").*main.*\.js").Value;

private string _UGGOverviewVersion;
private async Task<string> GetUGGOverviewVersion()
{
if (_UGGOverviewVersion == null)
{
var url = $"https://u.gg/json/new_ugg_versions/{UGGDataVersion}.json";

var json = JObject.Parse(await Client.DownloadStringTaskAsync(url));
var scriptText = await WebCache.String(scriptUrl);
var versionsJson = Regex.Match(scriptText, @"(?<=Ln=)\[.*?\]").Value;
var versions = JArray.Parse(versionsJson);

_UGGOverviewVersion = json["latest"]["overview"].ToObject<string>();
_LolUGGVersion = versions[0]["value"].ToObject<string>();
}

return _UGGOverviewVersion;

return _LolUGGVersion;
}

private IDictionary<int, JObject> ChampionData = new Dictionary<int, JObject>();
protected async Task<JObject> GetChampionData(int championId)
{
if (!ChampionData.TryGetValue(championId, out var data))
{
string url = $"https://stats2.u.gg/lol/{UGGApiVersion}/overview/{await GetLolUGGVersion()}/ranked_solo_5x5/{championId}/{await GetUGGOverviewVersion()}.json";
string url = $"https://stats2.u.gg/lol/{UGGApiVersion}/overview/{await GetLolUGGVersion()}/ranked_solo_5x5/{championId}/{UGGOverviewVersion}.json";

var json = JObject.Parse(await WebCache.String(url));
ChampionData[championId] = data = (JObject)json[OverviewWorld.ToString()][OverviewPlatPlus.ToString()];
Expand Down
2 changes: 1 addition & 1 deletion Legendary Rune Maker/Data/Rune.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static string Richify(string desc)
("<br>", "<LineBreak/>"),
(@"<b>(.*?)<\/b>", "<Bold>$1</Bold>"),
(@"<i>(.*?)<\/i>", "<Italic>$1</Italic>"),
(@"<hr><\/hr>", "<Line/>"),
(@"<hr\/?>(<\/hr>)?", "<Line/>"),
(@"<\/li>", "</li> "),
(@"<font color='(.*?)'>(.*?)<\/font>", "<Run Foreground=\"$1\">$2</Run>"),
(@"<(.*?)( .*?)?>(?<content>.*?)<\/\1>", "${content}"), //Replace all remaining XML tags with just their content
Expand Down

0 comments on commit 8b8f795

Please sign in to comment.