forked from HeroCC/RedditSteamGameInfo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKeyhub.py
52 lines (46 loc) · 1.72 KB
/
Keyhub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import time
import re
import requests
from bs4 import BeautifulSoup
class Keyhub:
def __init__(self, url, source):
self.url = url.replace("share.", "")
self.g_id = re.findall(r'\d+', self.url)
if self.g_id:
# Get key amount
self.key_amount = self.key_info()
if self.key_amount != "0" and source == "new":
# request page to get steam level requirement
self.level = self.level_info()
else:
return None
def key_info(self):
self.giveawaycount_url = "https://api.key-hub.eu/?type=giveawaycount&data=" + self.g_id[0]
while True:
try:
headers = {"Origin": "https://key-hub.eu"}
self.giveawaycount = requests.get(
self.giveawaycount_url,
headers=headers,
timeout=10).json().get("data")
break
except requests.exceptions.RequestException:
print("Keyhub timeout: sleep for 10 seconds and try again")
time.sleep(10)
return str(self.giveawaycount)
def level_info(self):
level = 0
while True:
try:
self.giveawayPage = BeautifulSoup(requests.get(
self.url,
timeout=10).text,
"html.parser")
break
except requests.exceptions.RequestException:
print("Keyhub timeout: sleep for 10 seconds and try again")
time.sleep(10)
level_span = self.giveawayPage.find("span", class_="friendPlayerLevelNum")
if level_span is not None:
level = level_span.text
return str(level)