diff --git a/ChpStmScraper.WebApi/.vscode/launch.json b/ChpStmScraper.WebApi/.vscode/launch.json index 59999d8..1197ded 100644 --- a/ChpStmScraper.WebApi/.vscode/launch.json +++ b/ChpStmScraper.WebApi/.vscode/launch.json @@ -11,7 +11,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/net5.0/ChpStmScraper.WebApi.dll", + "program": "bin/Debug/net5.0/ChpStmScraper.WebApi", "args": [], "cwd": "${workspaceFolder}", "stopAtEntry": false, diff --git a/ChpStmScraper.WebApi/Program.cs b/ChpStmScraper.WebApi/Program.cs index 0a85a1e..1233818 100644 --- a/ChpStmScraper.WebApi/Program.cs +++ b/ChpStmScraper.WebApi/Program.cs @@ -27,7 +27,7 @@ public static void Init() if(!File.Exists("ChpStmScraper.db")) File.Copy("ChpStmScraper.Template.db","ChpStmScraper.db"); if(string.IsNullOrEmpty(Configuration.ProxyUrl)) - Console.WriteLine("检测到未设置代理,是否已能够访问 https://steamcommunity.com/ ?您可能需要开启加速器加速 steam 社区"); + Console.WriteLine("检测到未设置代理,是否已能够访问 https://steamcommunity.com/ ?"); if(string.IsNullOrEmpty(Configuration.SteamCookies)){ Console.WriteLine("Steam Cookie 未设置,程序关闭"); Process.GetCurrentProcess().Kill(); diff --git a/ChpStmScraper.WebApi/publish.sh b/ChpStmScraper.WebApi/publish.sh new file mode 100644 index 0000000..070cfb9 --- /dev/null +++ b/ChpStmScraper.WebApi/publish.sh @@ -0,0 +1,10 @@ +version="1.0.1" + +dotnet publish --runtime linux-x64 -p:PublishSingleFile=true --self-contained true -o ./bin/Release/WebApi/${version}/CheapSteam-${version}-linux-x64 -c Release +dotnet publish --runtime osx-x64 -p:PublishSingleFile=true --self-contained true -o ./bin/Release/WebApi/${version}/CheapSteam-${version}-macOS-x64 -c Release +dotnet publish --runtime win-x64 -p:PublishSingleFile=true --self-contained true -o ./bin/Release/WebApi/${version}/CheapSteam-${version}-win-x64 -c Release + +cd ./bin/Release/WebApi/${version}/ +zip -r CheapSteam-${version}-linux-x64.zip CheapSteam-${version}-linux-x64 +zip -r CheapSteam-${version}-macOS-x64.zip CheapSteam-${version}-macOS-x64 +zip -r CheapSteam-${version}-win-x64.zip CheapSteam-${version}-win-x64 \ No newline at end of file diff --git a/ChpStmScraper/Program.cs b/ChpStmScraper/Program.cs index 942d6dd..dfa2d49 100644 --- a/ChpStmScraper/Program.cs +++ b/ChpStmScraper/Program.cs @@ -49,9 +49,45 @@ public static void Init() private static int maxPageNum = 2333; private static int currentSyncThread = 0; private static string lastScraperName = ""; + + private static void CheckIfSteamCommunity() + { + + HttpService httpService = new HttpService(); + if (!string.IsNullOrEmpty(Configuration.ProxyUrl)) + { + httpService = new HttpService(Configuration.ProxyUrl); + } + try + { + Console.WriteLine("正在检测 steam 社区连通性..."); + httpService.GetWithCookie("https://steamcommunity.com/market/", Configuration.SteamCookies, result => + { + //判断是否可以访问 steam 社区 + Regex regex = new Regex(@"(?<=).+(?=<\/span>)"); + var match = regex.Matches(result.Content.ReadAsStringAsync().Result); + if (match.Count() == 0) + { + Console.WriteLine($"Steam Cookie 无效或已失效,退出程序"); + Process.GetCurrentProcess().Kill(); + } + else + { + Console.WriteLine($"当前 steam 账户为 {match[0].Value}"); + } + }); + } + catch (System.Exception ex) + { + Console.WriteLine("访问 steam 社区出现错误,是否已开启代理?"); + Console.WriteLine(ex.StackTrace); + Process.GetCurrentProcess().Kill(); + } + + } public static void Start() { - //BUFF + CheckIfSteamCommunity(); var baseAddress = new Uri(Helper.GetBaseUrl(Configuration.BuffUrl)); Timer timer = new Timer(state => { @@ -153,9 +189,8 @@ public static void Start() var marketId = regex.Match(marketResult).Value; if (string.IsNullOrEmpty(marketId)) { - //太快了 Thread.Sleep(TimeSpan.FromSeconds(10)); - throw new Exception("错误:找不到MarketID"); + throw new Exception("错误:找不到MarketID,可能是爬取速度过快"); } string steamApiUrl = $"https://steamcommunity.com/market/itemordershistogram?country=CN&language=schinese¤cy=23&item_nameid={marketId}&two_factor=0";