first commit
This commit is contained in:
30
PoEco.Net/Web/PoBLua.cs
Normal file
30
PoEco.Net/Web/PoBLua.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PoEco.Net.Web
|
||||
{
|
||||
internal class PoBLua
|
||||
{
|
||||
public class LuaRoot
|
||||
{
|
||||
public List<string> lua { get; set; }
|
||||
}
|
||||
public static void GetLatestLUA()
|
||||
{
|
||||
if (!Directory.Exists(@"data\lua")) { Directory.CreateDirectory(@"data\lua"); }
|
||||
WebClient wc = new WebClient();
|
||||
LuaRoot lr = JsonConvert.DeserializeObject<LuaRoot>(File.ReadAllText(@"data\lua.json"));
|
||||
foreach (var l in lr.lua)
|
||||
{
|
||||
if(File.Exists($@"data\lua\{l}.lua")) { File.Delete($@"data\lua\{l}.lua"); }
|
||||
wc.DownloadFile($"https://github.com/PathOfBuildingCommunity/PathOfBuilding/raw/dev/src/Data/Bases/{l}.lua", $@"data\lua\{l}.lua");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
283
PoEco.Net/Web/PoENinja.cs
Normal file
283
PoEco.Net/Web/PoENinja.cs
Normal file
@@ -0,0 +1,283 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using Newtonsoft.Json;
|
||||
using PoEco.Net.DB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static PoEco.Net.JSON.Classes.Divination;
|
||||
|
||||
namespace PoEco.Net.Web
|
||||
{
|
||||
internal class PoENinja
|
||||
{
|
||||
public static void SaveData(string url, string path)
|
||||
{
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.Encoding = Encoding.UTF8;
|
||||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||
try
|
||||
{
|
||||
Uri address = new Uri(url);
|
||||
string contents = webClient.DownloadString(address);
|
||||
System.IO.File.AppendAllText(path, contents, Encoding.UTF8);
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
Utilities.Message.CMW(ex.Message, true, 3);
|
||||
Utilities.Message.CMW("URL: " + url, true, 3);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utilities.Message.CMW(ex.Message, true, 3);
|
||||
}
|
||||
}
|
||||
|
||||
public static void GenCurrency()
|
||||
{
|
||||
DeleteCurrencies();
|
||||
int curID = 1;
|
||||
double divineValue = 0;
|
||||
string cmdText = "";
|
||||
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/currency.json", Encoding.UTF8));
|
||||
foreach (var c in rcur.lines)
|
||||
{
|
||||
if (c.currencyTypeName == "Divine Orb") { divineValue = Convert.ToInt32(Math.Round(c.chaosEquivalent)); }
|
||||
}
|
||||
foreach (LineCurrency line in JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/currency.json", Encoding.UTF8)).lines)
|
||||
{
|
||||
string curType = line.currencyTypeName;
|
||||
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
cmdText = $"INSERT INTO poeco_currency(curid,name,vchaos,vdivine) VALUES ('{curID}','{MySql.Data.MySqlClient.MySqlHelper.EscapeString(line.currencyTypeName)}','{Math.Round(line.chaosEquivalent,10)}','{Math.Round(line.chaosEquivalent / divineValue, 2, MidpointRounding.AwayFromZero)}')";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
curID++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GenDivination()
|
||||
{
|
||||
DeleteDivinations();
|
||||
int divID = 1;
|
||||
string cmdText = "";
|
||||
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/divination.json", Encoding.UTF8));
|
||||
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/divination.json", Encoding.UTF8)).lines)
|
||||
{
|
||||
string curType = line.name;
|
||||
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
cmdText = $"INSERT INTO poeco_divination(divid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue,2)}','{line.divineValue}')";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
divID++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GenEssence()
|
||||
{
|
||||
DeleteEssences();
|
||||
int divID = 1;
|
||||
string cmdText = "";
|
||||
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/essence.json", Encoding.UTF8));
|
||||
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/essence.json", Encoding.UTF8)).lines)
|
||||
{
|
||||
string curType = line.name;
|
||||
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
cmdText = $"INSERT INTO poeco_essence(essid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
divID++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GenFragment()
|
||||
{
|
||||
DeleteFragments();
|
||||
int divID = 1;
|
||||
string cmdText = "";
|
||||
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/scarab.json", Encoding.UTF8));
|
||||
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/scarab.json", Encoding.UTF8)).lines)
|
||||
{
|
||||
string curType = line.name;
|
||||
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
cmdText = $"INSERT INTO poeco_fragment(fraid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
divID++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GenFossil()
|
||||
{
|
||||
DeleteFossils();
|
||||
int divID = 1;
|
||||
string cmdText = "";
|
||||
RootCurrency rcur = JsonConvert.DeserializeObject<RootCurrency>(File.ReadAllText("data/ninja/fossil.json", Encoding.UTF8));
|
||||
foreach (LineDivination line in JsonConvert.DeserializeObject<RootDivination>(File.ReadAllText("data/ninja/fossil.json", Encoding.UTF8)).lines)
|
||||
{
|
||||
string curType = line.name;
|
||||
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
cmdText = $"INSERT INTO poeco_fossil(fosid,name,vchaos,vdivine) VALUES ('{divID}','{MySqlHelper.EscapeString(line.name)}','{Math.Round(line.chaosValue)}','{line.divineValue}')";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
divID++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteCurrencies()
|
||||
{
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
string cmdText = $"DELETE FROM poeco_currency";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
}
|
||||
|
||||
public static void DeleteDivinations()
|
||||
{
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
string cmdText = $"DELETE FROM poeco_divination";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
}
|
||||
|
||||
public static void DeleteEssences()
|
||||
{
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
string cmdText = $"DELETE FROM poeco_essence";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
}
|
||||
|
||||
public static void DeleteFragments()
|
||||
{
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
string cmdText = $"DELETE FROM poeco_fragment";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
}
|
||||
|
||||
public static void DeleteFossils()
|
||||
{
|
||||
MySqlConnection con = DB.User.MxPoEDB();
|
||||
string cmdText = $"DELETE FROM poeco_fossil";
|
||||
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public class CurrencyDetail
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string icon { get; set; }
|
||||
public string name { get; set; }
|
||||
public string tradeId { get; set; }
|
||||
}
|
||||
|
||||
public class LanguageCurrency
|
||||
{
|
||||
public string name { get; set; }
|
||||
public TranslationsCurrency translations { get; set; }
|
||||
}
|
||||
|
||||
public class LineCurrency
|
||||
{
|
||||
public string currencyTypeName { get; set; }
|
||||
public Pay pay { get; set; }
|
||||
public Receive receive { get; set; }
|
||||
public double chaosEquivalent { get; set; }
|
||||
public LowConfidencePaySparkLine lowConfidencePaySparkLine { get; set; }
|
||||
public LowConfidenceReceiveSparkLine lowConfidenceReceiveSparkLine { get; set; }
|
||||
public string detailsId { get; set; }
|
||||
}
|
||||
|
||||
public class LowConfidencePaySparkLine
|
||||
{
|
||||
public List<object> data { get; set; }
|
||||
public double totalChange { get; set; }
|
||||
}
|
||||
|
||||
public class LowConfidenceReceiveSparkLine
|
||||
{
|
||||
public List<double?> data { get; set; }
|
||||
public double totalChange { get; set; }
|
||||
}
|
||||
|
||||
public class Pay
|
||||
{
|
||||
public int id { get; set; }
|
||||
public int league_id { get; set; }
|
||||
public int pay_currency_id { get; set; }
|
||||
public int get_currency_id { get; set; }
|
||||
public DateTime sample_time_utc { get; set; }
|
||||
public int count { get; set; }
|
||||
public double value { get; set; }
|
||||
public int data_point_count { get; set; }
|
||||
public bool includes_secondary { get; set; }
|
||||
public int listing_count { get; set; }
|
||||
}
|
||||
|
||||
public class PaySparkLine
|
||||
{
|
||||
public List<object> data { get; set; }
|
||||
public double totalChange { get; set; }
|
||||
}
|
||||
|
||||
public class Receive
|
||||
{
|
||||
public int id { get; set; }
|
||||
public int league_id { get; set; }
|
||||
public int pay_currency_id { get; set; }
|
||||
public int get_currency_id { get; set; }
|
||||
public DateTime sample_time_utc { get; set; }
|
||||
public int count { get; set; }
|
||||
public double value { get; set; }
|
||||
public int data_point_count { get; set; }
|
||||
public bool includes_secondary { get; set; }
|
||||
public int listing_count { get; set; }
|
||||
}
|
||||
|
||||
public class ReceiveSparkLine
|
||||
{
|
||||
public List<double> data { get; set; }
|
||||
public double totalChange { get; set; }
|
||||
}
|
||||
|
||||
public class RootCurrency
|
||||
{
|
||||
public List<LineCurrency> lines { get; set; }
|
||||
public List<CurrencyDetail> currencyDetails { get; set; }
|
||||
public LanguageCurrency language { get; set; }
|
||||
}
|
||||
|
||||
public class TranslationsCurrency
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
65
PoEco.Net/Web/PoEPrices.cs
Normal file
65
PoEco.Net/Web/PoEPrices.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PoEco.Net.Web
|
||||
{
|
||||
internal class PoEPrices
|
||||
{
|
||||
public static void GetItemJson(string iid, string b64)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||
string url = $"https://www.poeprices.info/api?l={JSON.Settings.GetLeague()}&i={b64}";
|
||||
WebClient webClient = new WebClient();
|
||||
try
|
||||
{
|
||||
webClient.DownloadFile(url, "tmp/" + iid + ".json");
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (ex.Message.Contains("The remote server returned an error: (504) Gateway Time-out."))
|
||||
{
|
||||
Utilities.Message.CMW("Failed. Retrying...", true, 3);
|
||||
GetItemJson(iid, b64);
|
||||
}
|
||||
//Utilities.Message.CMW(ex.Message, true, 3);
|
||||
//Utilities.Message.CMW("URL: " + url, true, 3);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utilities.Message.CMW(ex.Message, true, 3);
|
||||
}
|
||||
}
|
||||
|
||||
public static double GetMin(string iid)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<PoEPricesRoot>(File.ReadAllText("tmp/" + iid + ".json")).min;
|
||||
}
|
||||
|
||||
public static double GetMax(string iid)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<PoEPricesRoot>(File.ReadAllText("tmp/" + iid + ".json")).max;
|
||||
}
|
||||
|
||||
public static string GetCurType(string iid)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<PoEPricesRoot>(File.ReadAllText("tmp/" + iid + ".json")).currency;
|
||||
}
|
||||
|
||||
public class PoEPricesRoot
|
||||
{
|
||||
public double min { get; set; }
|
||||
|
||||
public double max { get; set; }
|
||||
|
||||
public string currency { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
57
PoEco.Net/Web/Stash.cs
Normal file
57
PoEco.Net/Web/Stash.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PoEco.Net.Web
|
||||
{
|
||||
internal class Stash
|
||||
{
|
||||
public static void DownloadStash(string token, string url, string path)
|
||||
{
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.Encoding = Encoding.UTF8;
|
||||
webClient.Headers.Add(HttpRequestHeader.Cookie, "POESESSID=" + token);
|
||||
webClient.Headers.Add("user-agent", $"PoEcoDB/{Program.version} (poeco@mxpoe.ovh)");
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
||||
try
|
||||
{
|
||||
Uri address = new Uri(url);
|
||||
webClient.DownloadFile(address, path);
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
Utilities.Message.CMW(ex.Message, true, 3);
|
||||
Utilities.Message.CMW("URL: " + url, true, 3);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utilities.Message.CMW(ex.Message,true,3);
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetStash(string token, string url, string path)
|
||||
{
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.Encoding = Encoding.UTF8;
|
||||
webClient.Headers.Add("Authorization", "Bearer " + token);
|
||||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||
try
|
||||
{
|
||||
Uri address = new Uri(url);
|
||||
webClient.DownloadFile(address, path);
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
Utilities.Message.CMW(ex.Message, true, 3);
|
||||
Utilities.Message.CMW("URL: " + url, true, 3);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utilities.Message.CMW(ex.Message, true, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user