Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
添加 steam 连通性检测
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiCoco committed Dec 13, 2020
1 parent e20fc74 commit 8ce4fbf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ChpStmScraper.WebApi/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ChpStmScraper.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions ChpStmScraper.WebApi/publish.sh
Original file line number Diff line number Diff line change
@@ -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
41 changes: 38 additions & 3 deletions ChpStmScraper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 id=""market_buynow_dialog_myaccountname"">).+(?=<\/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 =>
{
Expand Down Expand Up @@ -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&currency=23&item_nameid={marketId}&two_factor=0";
Expand Down

0 comments on commit 8ce4fbf

Please sign in to comment.