private static IncomeItem PickIncomeItem(Regex regex, string html) { Match match = regex.Match(html); if (match.Success) { IncomeItem incomeItem = new IncomeItem() { DataCode = match.Groups["dataCode"].Value, CoinCode = match.Groups["coinCode"].Value, SpeedUnit = match.Groups["speedUnit"].Value }; if (incomeItem.DataCode == "grin-29") { incomeItem.CoinCode = "grin"; incomeItem.SpeedUnit = "h/s"; } else if (incomeItem.DataCode == "grin-31") { incomeItem.CoinCode = "grin31"; incomeItem.SpeedUnit = "h/s"; } double.TryParse(match.Groups["speed"].Value, out double speed); incomeItem.Speed = speed; double.TryParse(match.Groups["incomeCoin"].Value, out double incomeCoin); incomeItem.IncomeCoin = incomeCoin; double.TryParse(match.Groups["incomeUsd"].Value, out double incomeUsd); incomeItem.IncomeUsd = incomeUsd; return(incomeItem); } return(null); }
private static IncomeItem PickVDSIncomeItem(string vdsUUHtml, string vdsZtHtml, double usdCny) { const string pattern = "\"symbol\":\"vds\",.+,\"hr\":\"(?<netSpeed>[\\d\\.]+)\\s(?<netSpeedUnit>\\w+)\",\"est\":\"(?<incomeCoin>[\\d\\.]+) VDS\\\\/(?<speedUnit>\\w+)\","; IncomeItem result = new IncomeItem { CoinCode = "VDS", DataCode = "VDS", Speed = 1, }; var regex = VirtualRoot.GetRegex(pattern); var match = regex.Match(vdsUUHtml); if (match.Success) { string incomeCoinText = match.Groups["incomeCoin"].Value; result.SpeedUnit = match.Groups["speedUnit"].Value + "h/s"; string netSpeedText = match.Groups["netSpeed"].Value; result.NetSpeedUnit = match.Groups["netSpeedUnit"].Value + "h/s"; double incomeCoin; if (double.TryParse(incomeCoinText, out incomeCoin)) { result.IncomeCoin = incomeCoin; } double netSpeed; if (double.TryParse(netSpeedText, out netSpeed)) { result.NetSpeed = netSpeed; } } const string pattern1 = "\"VDS\",.+?,\"last\":\"(?<incomeCny>[\\d\\.]+)\""; regex = VirtualRoot.GetRegex(pattern1); match = regex.Match(vdsZtHtml); if (match.Success) { string incomeCnyText = match.Groups["incomeCny"].Value; double incomeCny; if (double.TryParse(incomeCnyText, out incomeCny)) { result.IncomeCny = incomeCny * result.IncomeCoin; result.IncomeUsd = result.IncomeCny / usdCny; } } return(result); }
private static IncomeItem PickVDSIncomeItem(string vdsUUHtml, string vdsZtHtml, double usdCny) { string pattern = "\"symbol\":\"vds\",.+,\"est\":\"(?<incomeCoin>[\\d\\.]+) VDS\\\\/(?<speedUnit>\\w+)\","; IncomeItem result = new IncomeItem { CoinCode = "VDS", DataCode = "VDS", Speed = 1, }; var match = Regex.Match(vdsUUHtml, pattern); if (match.Success) { string incomeCoinText = match.Groups["incomeCoin"].Value; string speedUnit = match.Groups["speedUnit"].Value; result.SpeedUnit = speedUnit + "h/s"; double incomeCoin; if (double.TryParse(incomeCoinText, out incomeCoin)) { result.IncomeCoin = incomeCoin; } } pattern = "\"VDS\",.+?,\"last\":\"(?<incomeCny>[\\d\\.]+)\""; match = Regex.Match(vdsZtHtml, pattern); if (match.Success) { string incomeCnyText = match.Groups["incomeCny"].Value; double incomeCny; if (double.TryParse(incomeCnyText, out incomeCny)) { result.IncomeCny = incomeCny * result.IncomeCoin; result.IncomeUsd = result.IncomeCny / usdCny; } } return(result); }
private static void UpdateAsync() { Task.Factory.StartNew(() => { try { var vdsUUDataTask = GetHtmlAsync("https://uupool.cn/api/getAllInfo.php"); var vdsZtDataTask = GetHtmlAsync("https://www.zt.com/api/v1/symbol"); var htmlDataTask = GetHtmlAsync("https://www.f2pool.com/"); byte[] htmlData = null; byte[] vdsUUData = null; byte[] vdsZtData = null; try { Task.WaitAll(new Task[] { vdsUUDataTask, vdsZtDataTask, htmlDataTask }, 30 * 1000); htmlData = htmlDataTask.Result; vdsUUData = vdsUUDataTask.Result; vdsZtData = vdsZtDataTask.Result; } catch { } if (htmlData != null && htmlData.Length != 0) { Write.UserOk($"{DateTime.Now} - 鱼池首页html获取成功"); string html = Encoding.UTF8.GetString(htmlData); string vdsUUHtml = string.Empty; string vdsZtHtml = string.Empty; if (vdsUUData != null && vdsUUData.Length != 0) { vdsUUHtml = Encoding.UTF8.GetString(vdsUUData); } if (vdsZtData != null && vdsZtData.Length != 0) { vdsZtHtml = Encoding.UTF8.GetString(vdsZtData); } double usdCny = PickUsdCny(html); Write.UserInfo($"usdCny={usdCny}"); List <IncomeItem> incomeItems = PickIncomeItems(html); IncomeItem vdsIncomeItem = PickVDSIncomeItem(vdsUUHtml, vdsZtHtml, usdCny); if (vdsIncomeItem != null && incomeItems.All(a => a.CoinCode != "VDS")) { incomeItems.Add(vdsIncomeItem); } Write.UserInfo($"鱼池首页有{incomeItems.Count}个币种"); FillCny(incomeItems, usdCny); NeatenSpeedUnit(incomeItems); if (incomeItems != null && incomeItems.Count != 0) { Login(); OfficialServer.CalcConfigService.GetCalcConfigsAsync(data => { Write.UserInfo($"NTMiner有{data.Count}个币种"); HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (CalcConfigData calcConfigData in data) { IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase)); if (incomeItem != null) { coinCodes.Add(calcConfigData.CoinCode); calcConfigData.Speed = incomeItem.Speed; calcConfigData.SpeedUnit = incomeItem.SpeedUnit; calcConfigData.IncomePerDay = incomeItem.IncomeCoin; calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd; calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny; calcConfigData.ModifiedOn = DateTime.Now; } } OfficialServer.CalcConfigService.SaveCalcConfigsAsync(data, callback: (res, e) => { if (!res.IsSuccess()) { Write.UserFail(res.ReadMessage(e)); } }); foreach (IncomeItem incomeItem in incomeItems) { if (coinCodes.Contains(incomeItem.CoinCode)) { continue; } Write.UserInfo(incomeItem.ToString()); } foreach (var incomeItem in incomeItems) { if (!coinCodes.Contains(incomeItem.CoinCode)) { continue; } Write.UserOk(incomeItem.ToString()); } Write.UserOk($"更新了{coinCodes.Count}个币种:{string.Join(",", coinCodes)}"); int unUpdatedCount = data.Count - coinCodes.Count; Write.UserWarn($"{unUpdatedCount}个币种未更新{(unUpdatedCount == 0 ? string.Empty : ":" + string.Join(",", data.Select(a => a.CoinCode).Except(coinCodes)))}"); }); } } } catch (Exception e) { Logger.ErrorDebugLine(e); } }); }
private static void UpdateAsync() { Task.Factory.StartNew(() => { try { Task <byte[]> htmlDataTask = GetHtmlAsync("https://www.f2pool.com/"); byte[] htmlData = null; try { Task.WaitAll(new Task[] { htmlDataTask }, 60 * 1000); htmlData = htmlDataTask.Result; } catch { } if (htmlData != null && htmlData.Length != 0) { NTMinerConsole.UserOk($"{DateTime.Now.ToString()} - 鱼池首页html获取成功"); string html = Encoding.UTF8.GetString(htmlData); double usdCny = PickUsdCny(html); NTMinerConsole.UserInfo($"usdCny={usdCny.ToString()}"); List <IncomeItem> incomeItems = PickIncomeItems(html); NTMinerConsole.UserInfo($"鱼池首页有{incomeItems.Count.ToString()}个币种"); FillCny(incomeItems, usdCny); NeatenSpeedUnit(incomeItems); if (incomeItems != null && incomeItems.Count != 0) { RpcRoot.Login(new RpcUser(Config.RpcLoginName, HashUtil.Sha1(Config.RpcPassword))); RpcRoot.SetIsOuterNet(false); RpcRoot.OfficialServer.CalcConfigBinaryService.GetCalcConfigsAsync(data => { NTMinerConsole.UserInfo($"NTMiner有{data.Count.ToString()}个币种"); HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (CalcConfigData calcConfigData in data) { IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase)); if (incomeItem != null) { coinCodes.Add(calcConfigData.CoinCode); calcConfigData.Speed = incomeItem.Speed; calcConfigData.SpeedUnit = incomeItem.SpeedUnit; calcConfigData.NetSpeed = incomeItem.NetSpeed; calcConfigData.NetSpeedUnit = incomeItem.NetSpeedUnit; calcConfigData.IncomePerDay = incomeItem.IncomeCoin; calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd; calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny; calcConfigData.ModifiedOn = DateTime.Now; if (calcConfigData.ModifiedOn.AddMinutes(15) > calcConfigData.ModifiedOn.Date.AddDays(1)) { calcConfigData.BaseNetSpeed = calcConfigData.NetSpeed; calcConfigData.BaseNetSpeedUnit = calcConfigData.NetSpeedUnit; } else if (calcConfigData.BaseNetSpeed != 0) { if (calcConfigData.NetSpeedUnit == calcConfigData.BaseNetSpeedUnit) { calcConfigData.DayWave = (calcConfigData.NetSpeed - calcConfigData.BaseNetSpeed) / calcConfigData.BaseNetSpeed; } else { if (string.IsNullOrEmpty(calcConfigData.BaseNetSpeedUnit)) { calcConfigData.BaseNetSpeedUnit = calcConfigData.NetSpeedUnit; } var netSpeed = calcConfigData.NetSpeed.FromUnitSpeed(calcConfigData.NetSpeedUnit); var baseNetSpeed = calcConfigData.BaseNetSpeed.FromUnitSpeed(calcConfigData.BaseNetSpeedUnit); calcConfigData.DayWave = (netSpeed - baseNetSpeed) / baseNetSpeed; } } } } RpcRoot.OfficialServer.CalcConfigService.SaveCalcConfigsAsync(data, callback: (res, e) => { if (!res.IsSuccess()) { VirtualRoot.Out.ShowError(res.ReadMessage(e), autoHideSeconds: 4); } }); foreach (IncomeItem incomeItem in incomeItems) { if (coinCodes.Contains(incomeItem.CoinCode)) { continue; } NTMinerConsole.UserInfo(incomeItem.ToString()); } foreach (var incomeItem in incomeItems) { if (!coinCodes.Contains(incomeItem.CoinCode)) { continue; } NTMinerConsole.UserOk(incomeItem.ToString()); } NTMinerConsole.UserOk($"更新了{coinCodes.Count.ToString()}个币种:{string.Join(",", coinCodes)}"); int unUpdatedCount = data.Count - coinCodes.Count; NTMinerConsole.UserWarn($"{unUpdatedCount.ToString()}个币种未更新{(unUpdatedCount == 0 ? string.Empty : ":" + string.Join(",", data.Select(a => a.CoinCode).Except(coinCodes)))}"); }); } } } catch (Exception e) { Logger.ErrorDebugLine(e); } }); }
private static void UpdateAsync() { Task.Factory.StartNew(() => { try { byte[] htmlData = GetHtmlAsync("https://www.f2pool.com/").Result; if (htmlData != null && htmlData.Length != 0) { Console.WriteLine($"{DateTime.Now} - 鱼池首页html获取成功"); string html = Encoding.UTF8.GetString(htmlData); double usdCny = PickUsdCny(html); Console.WriteLine($"usdCny={usdCny}"); List <IncomeItem> incomeItems = PickIncomeItems(html); Console.WriteLine($"鱼池首页有{incomeItems.Count}个币种"); FillCny(incomeItems, usdCny); NeatenSpeedUnit(incomeItems); if (incomeItems != null && incomeItems.Count != 0) { Login(); DataResponse <List <CalcConfigData> > response = OfficialServer.GetCalcConfigs(); Console.WriteLine($"NTMiner有{response.Data.Count}个币种"); HashSet <string> coinCodes = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (CalcConfigData calcConfigData in response.Data) { IncomeItem incomeItem = incomeItems.FirstOrDefault(a => string.Equals(a.CoinCode, calcConfigData.CoinCode, StringComparison.OrdinalIgnoreCase)); if (incomeItem != null) { coinCodes.Add(calcConfigData.CoinCode); calcConfigData.Speed = incomeItem.Speed; calcConfigData.SpeedUnit = incomeItem.SpeedUnit; calcConfigData.IncomePerDay = incomeItem.IncomeCoin; calcConfigData.IncomeUsdPerDay = incomeItem.IncomeUsd; calcConfigData.IncomeCnyPerDay = incomeItem.IncomeCny; calcConfigData.ModifiedOn = DateTime.Now; } } OfficialServer.SaveCalcConfigsAsync(response.Data, null); foreach (IncomeItem incomeItem in incomeItems) { if (coinCodes.Contains(incomeItem.CoinCode)) { continue; } Console.WriteLine(incomeItem.ToString()); } Console.ForegroundColor = ConsoleColor.Green; foreach (var incomeItem in incomeItems) { if (!coinCodes.Contains(incomeItem.CoinCode)) { continue; } Console.WriteLine(incomeItem.ToString()); } Console.ResetColor(); Console.WriteLine($"更新了{coinCodes.Count}个币种:{string.Join(",", coinCodes)}"); int unUpdatedCount = response.Data.Count - coinCodes.Count; Console.WriteLine($"{unUpdatedCount}个币种未更新{(unUpdatedCount == 0 ? string.Empty: ":" + string.Join(",", response.Data.Select(a => a.CoinCode).Except(coinCodes)))}"); } } } catch (Exception e) { PrintError(e); } }); }