-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Weinig
committed
Apr 7, 2022
0 parents
commit 0068f4d
Showing
6 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sniper", "Sniper\Sniper.csproj", "{6D4469A4-05EF-4343-BC7A-9011A4426106}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6D4469A4-05EF-4343-BC7A-9011A4426106}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6D4469A4-05EF-4343-BC7A-9011A4426106}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6D4469A4-05EF-4343-BC7A-9011A4426106}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6D4469A4-05EF-4343-BC7A-9011A4426106}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Text.RegularExpressions; | ||
using System.Threading; | ||
using Telegram.Bot; | ||
|
||
namespace Sniper | ||
{ | ||
class Program | ||
{ | ||
private const string TELEGRAM_TOKEN = null; // TODO | ||
private static readonly long[] CHAT_IDS = null; | ||
static void Main(string[] args) | ||
{ | ||
//SendMsg("start test"); | ||
while (true) | ||
{ | ||
CheckAmdOverview(); | ||
//CheckAmd("5496921400","6700XT"); | ||
//CheckAmd("5458374000","6800"); | ||
//CheckAmd("5458374000","6800"); | ||
Thread.Sleep(TimeSpan.FromSeconds(20)); | ||
} | ||
} | ||
|
||
static void CheckAmdOverview() | ||
{ | ||
try | ||
{ | ||
var pageContent = LoadString("https://www.amd.com/en/direct-buy/de",null, false); | ||
var url = $"https://www.amd.com/en/direct-buy/products/de";//?rand={DateTime.Now.Ticks}"; | ||
var referer = $"https://www.amd.com/en/direct-buy/de"; | ||
var content = LoadString(url, referer); | ||
foreach (var part in content.Split("<div class=\"direct-buy\">")) | ||
{ | ||
var mTitle = Regex.Match(part, "<div class=\"shop-title\">(.+?)</div>", RegexOptions.Singleline); | ||
if(!mTitle.Success) continue; | ||
var title = mTitle.Groups[1].Value.Trim(); | ||
string name; | ||
if (title.Contains("RX 6700 XT Graphics", StringComparison.CurrentCultureIgnoreCase)) | ||
name = "O_6700XT"; | ||
else if (title.Contains("RX 6800 Graphics", StringComparison.CurrentCultureIgnoreCase)) | ||
name = "O_6800"; | ||
else | ||
{ | ||
continue; | ||
} | ||
HandleContent(part, name, url); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
SendMsg($"Overview error {ex.Message}"); | ||
} | ||
} | ||
|
||
static void HandleContent(string content, string name, string url) | ||
{ | ||
if (content.Contains("Out of stock", StringComparison.CurrentCultureIgnoreCase)) | ||
{ | ||
Log($"{name} out of stock"); | ||
} | ||
else if (content.Contains("Add to cart", StringComparison.CurrentCultureIgnoreCase)) | ||
{ | ||
SendMsg($"{name} AVAILABLE {url}"); | ||
} | ||
else | ||
{ | ||
SendMsg($"{name} known reply"); | ||
} | ||
} | ||
static void CheckAmd(string productId, string name) | ||
{ | ||
try | ||
{ | ||
var url = $"https://www.amd.com/en/direct-buy/products/{productId}/de";//?rand={DateTime.Now.Ticks}"; | ||
var referer = $"https://www.amd.com/en/direct-buy/{productId}/de"; | ||
var content = LoadString(url, referer); | ||
HandleContent(content, name, url); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
SendMsg($"{name} error {ex.Message}"); | ||
} | ||
// | ||
|
||
} | ||
|
||
static string LoadString(string url, string referer, bool jsReq=true) | ||
{ | ||
var request = (HttpWebRequest)WebRequest.Create(url); | ||
request.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); | ||
request.Headers.Add(HttpRequestHeader.UserAgent, | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36"); | ||
if(referer != null) | ||
request.Headers.Add(HttpRequestHeader.Referer, referer); | ||
//sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92" | ||
request.Headers.Add( | ||
"sec-ch-ua", "\" Not;A Brand\";v=\"99\", \"Google Chrome\";v=\"91\", \"Chromium\";v=\"91\""); | ||
request.Headers.Add("sec-ch-ua-mobile","?0"); | ||
request.Headers.Add("sec-fetch-dest",jsReq ? "empty" : "document"); | ||
request.Headers.Add("sec-fetch-mode", jsReq?"cors":"navigate"); | ||
request.Headers.Add("sec-fetch-site", jsReq?"same-origin":"none"); | ||
request.Headers.Add("sec-fetch-user", "?1"); | ||
request.Headers.Add("upgrade-insecure-requests", "1"); | ||
request.Headers.Add("x-requested-with","XMLHttpRequest"); | ||
request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.9"); | ||
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br"); | ||
request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); | ||
request.Timeout = 20000; | ||
request.ReadWriteTimeout = 20000; | ||
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; | ||
using var wresp = (HttpWebResponse)request.GetResponse(); | ||
using var reader = new StreamReader(wresp.GetResponseStream()); | ||
return reader.ReadToEnd(); | ||
} | ||
static void SendMsg(string msg) | ||
{ | ||
Log(msg); | ||
var text = $"##SNIPER {DateTime.Now} {msg}"; | ||
var bot = new TelegramBotClient(TELEGRAM_TOKEN); | ||
foreach (var chatId in CHAT_IDS) | ||
{ | ||
bot.SendTextMessageAsync(chatId, text).GetAwaiter().GetResult(); | ||
} | ||
} | ||
static void Log(string msg) | ||
{ | ||
Console.WriteLine($"{DateTime.Now} {msg}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Telegram.Bot" Version="16.0.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |