public async Task Status(CommandContext ctx) { string HTML; using (WebClient wc = new()) { HTML = wc.DownloadString("https://ubistatic-a.akamaihd.net/0115/tc2/status.html"); } if (HTML.Contains("STATUS OK")) { await ctx.RespondAsync("The Crew 2 Server is Online"); } else { await ctx.RespondAsync("The Crew 2 Server is Offline"); } }
public void getStockSort() { //List<string> names = wh.GetAll(); //读取储存在本地的id string str = wh.Read("result\\IDresult.txt"); string[] temp = str.Split(','); for (int a = 0; a < temp.Length; a++) { fundsID.Add(temp[a]); } string content; string HTML; //string url; double deltas; double sum1, sum2; //每个基金内的股票数据 foreach (string ID in fundsID) { //content = wh.Read("..\\..\\stock\\" + ID + ".txt"); //content = content.Substring(content.IndexOf("持仓截止日期")); //content = content.Substring(content.IndexOf("href") + 6); //url = content.Substring(0, content.IndexOf("'")); //取得每个基金下的股票id content = wh.GetContent("http://fund.eastmoney.com/f10/FundArchivesDatas.aspx?type=jjcc&code=" + ID + "&topline=10&year=&month=&rt=0.6009964493629969"); if (!content.Contains("<tbody>")) { continue; } content = content.Substring(content.IndexOf("<tbody>")); content = content.Substring(0, content.IndexOf("</table>")); while (content.Contains("<tr>")) { content = content.Substring(content.IndexOf("<tr>")); //跳过无用数据 content = content.Substring(content.IndexOf("<td") + 3); content = content.Substring(content.IndexOf("<td") + 3); //找到id content = content.Substring(content.IndexOf("<")); string tmp1 = content.Substring(0, 2); if (tmp1 == "<a") { content = content.Substring(content.IndexOf(">") + 1); } string stockkID = content.Substring(0, content.IndexOf("<")); //找到name content = content.Substring(content.IndexOf("<td") + 1); content = content.Substring(content.IndexOf("<")); string tmp2 = content.Substring(0, 2); if (tmp1 == "<a") { content = content.Substring(content.IndexOf(">") + 1); } string stockkName = content.Substring(0, content.IndexOf("<")); //进入每个股票在每个基金下变动的页面,找到股票增持减持数据 HTML = wh.GetContent("http://fund.eastmoney.com/f10/F10DataApi.aspx?type=ggxq&code=" + ID + "&gpdm=" + stockkID + "&rt=0.29900780686763406"); if (!HTML.Contains("2017-09-30")) { continue; } HTML = HTML.Substring(HTML.IndexOf("2017-09-30")); //跳过无用数据 HTML = HTML.Substring(HTML.IndexOf("<td") + 3); HTML = HTML.Substring(HTML.IndexOf("<td") + 3); HTML = HTML.Substring(HTML.IndexOf("<td") + 3); HTML = HTML.Substring(HTML.IndexOf(">") + 1); String SUM1 = HTML.Substring(0, HTML.IndexOf("<")); sum1 = Convert.ToDouble(SUM1); if (HTML.Contains("2017-06-30")) { HTML = HTML.Substring(HTML.IndexOf("2017-06-30")); //跳过无用数据 HTML = HTML.Substring(HTML.IndexOf("<td") + 3); HTML = HTML.Substring(HTML.IndexOf("<td") + 3); HTML = HTML.Substring(HTML.IndexOf("<td") + 3); HTML = HTML.Substring(HTML.IndexOf(">") + 1); String SUM2 = HTML.Substring(0, HTML.IndexOf("<")); sum2 = Convert.ToDouble(SUM2); } else { sum2 = 0; } deltas = sum1 - sum2; deltas = Math.Round(deltas, 2); bool matchs = false; //判断是否已经存储,已有便累加数据,没有就add foreach (Stockk sto in stockks) { if (sto.id == stockkID) { sto.delta += deltas; matchs = true; break; } } if (!matchs) { Stockk st = new Stockk(); st.name = stockkName; st.id = stockkID; st.delta = deltas; stockks.Add(st); } } //排序 List <Stockk> tmp = new List <Stockk>(); bool IN; foreach (Stockk st in stockks) { IN = false; for (int i = 0; i < tmp.Count; i++) { if (tmp.ElementAt(i).delta < st.delta) { tmp.Insert(i, st); IN = true; break; } } if (!IN) { tmp.Add(st); } } //写入 string result = ""; for (int i = 0; i < tmp.Count; i++) { result += tmp.ElementAt(i).name + "," + tmp.ElementAt(i).delta + "\n"; } wh.inText(result, "result\\stockresult", "UTF8"); } }
public static void Main(string[] args) { /* * Target usage: DO_Dumper [SERVER] [DOSID] */ if (args.Length != 2 || args[1].Length != 32) { PrintError("Wrong args!"); return; } HTTPMgr HTTP = new HTTPMgr(); TimeSpan Elapsed; // Login into the game with SID. { string HTML; if (!HTTP.GET($"http://{args[0]}.darkorbit.bigpoint.com/indexInternal.es?action=internalHallofFame&view=User&dosid={args[1]}", out HTML)) { PrintError("Failed to get first website!"); return; } if (!HTML.Contains("p://darkorbit-22.ah.bpcdn.net/css/cdn/internalHallofFame.css")) { PrintError("Failed to load ranks site, maybe wrong sid?"); return; } } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Logged in with SID!"); string OutputPath = $"{Directory.GetCurrentDirectory()}\\dump_{args[0]}.sql"; if (File.Exists(OutputPath)) { File.Delete(OutputPath); } UTF8Encoding Encoder = new UTF8Encoding(false); DateTime StartTime = DateTime.Now; using (FileStream FS = new FileStream(OutputPath, FileMode.CreateNew)) { // Write credits header { string Header = $"-- Exported with DO_Dumper by NoobKillerPL\n-- Generated on {String.Format("{0:dd/MM/yyyy HH:mm:ss}", StartTime)}\n"; byte[] Bytes = Encoder.GetBytes(Header); FS.Write(Bytes, 0, Bytes.Length); } // Write SQL header { byte[] SQL_Header = Encoder.GetBytes(@" CREATE TABLE `players` ( `position` int(11) NOT NULL, `name` varchar(255) NOT NULL, `rank` varchar(64) NOT NULL, `points` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; SET ESCAPE '\' "); FS.Write(SQL_Header, 0, SQL_Header.Length); } // 100 pages of ranking... Parallel.For(1, 101, new ParallelOptions { MaxDegreeOfParallelism = 4 }, (i, loopState) => { LB_TRY_AGAIN: string HTML; if (!HTTP.GET($"http://{args[0]}.darkorbit.bigpoint.com/indexInternal.es?action=internalHallofFame&view=User&dps={i}", out HTML)) { PrintError($"Failed to load {i} page!"); return; } if (!HTML.Contains("p://darkorbit-22.ah.bpcdn.net/css/cdn/internalHallofFame.css")) { PrintError($"Failed to page #{i}! We'll try again in 4s..."); Thread.Sleep(4000); goto LB_TRY_AGAIN; } //Console.ForegroundColor = ConsoleColor.DarkGray; //Console.WriteLine($"Loaded {i}!"); // trim beginning & end (useless info) HTML = HTML.Substring(HTML.IndexOf("hof_ranking_table defaultRanking") + "hof_ranking_table defaultRanking".Length); HTML = HTML.Substring(HTML.IndexOf("<tr>")); HTML = HTML.Substring(0, HTML.IndexOf("</table>")); int Accs = 0; MatchCollection mc = Regex.Matches(HTML, @"<tr>\s*(.+?)</tr>", RegexOptions.Singleline); foreach (Match _Match in mc) { string AccData = _Match.Value; if (AccData.Contains("colspan")) { continue; //It's the separator entry } string Position, Name, Rank, Points; MatchCollection Matches; Matches = Regex.Matches(AccData, "56px;\">(.+?)</td>", RegexOptions.Singleline); if (Matches.Count != 1) { throw new Exception("Failed to parse rank number with regex!"); } Position = Matches[0].Groups[1].Value; Matches = Regex.Matches(AccData, "title=\"(.+?)\"", RegexOptions.Singleline); if (Matches.Count != 1) { throw new Exception("Failed to parse nickname with regex!"); } Name = Matches[0].Groups[1].Value; Matches = Regex.Matches(AccData, "6b;\">(.+?)</td>", RegexOptions.Singleline); if (Matches.Count != 1) { throw new Exception("Failed to parse rank of the player with regex!"); } Rank = Matches[0].Groups[1].Value; Matches = Regex.Matches(AccData, "30px;\">\\s*(.+?)\\s*</td>", RegexOptions.Singleline); if (Matches.Count != 1) { throw new Exception("Failed to parse rank of the player with regex!"); } Points = Matches[0].Groups[1].Value.Replace(",", ""); // Fix Name for bad characters Name = Name.Replace("'", ""); Name = Name.Replace("\"", ""); Name = Name.Replace(";", ""); Name = Name.Replace("[", "\\["); Name = Name.Replace("]", "\\]"); // Write a SQL string to file string SQL = $"{Environment.NewLine}INSERT INTO `players` (`position`, `name`, `rank`, `points`) VALUES ('{Position}', '{Name}', '{Rank}', '{Points}');"; byte[] SQL_Bytes = Encoder.GetBytes(SQL); FS.Write(SQL_Bytes, 0, SQL_Bytes.Length); Accs++; } Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine($"Parsed whole {i} page with {Accs} accs on it!"); }); Elapsed = DateTime.Now - StartTime; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\nDumped all players from main ranking table in {Elapsed} time!"); /* * Some notes for later: * - All honor & destroyed aliens / ships count have 100 pages limit. * - Experience on the other hand for some reason has >600 pages on int1. * - Ranks are often in different languages, would be cool to make a dictionary from all servers... #TODO */ // Experience? } Elapsed = DateTime.Now - StartTime; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\nExported results to 'dump_{args[0]}.sql' file in {Elapsed} time!"); Console.ReadKey(); }