-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteamMakeBoosterPack.py
executable file
·108 lines (102 loc) · 4.68 KB
/
SteamMakeBoosterPack.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import configparser
import logging
import os
import sys
import steam
import steam.webauth
import steamfront
import json
import re
import time
import datetime
class get_info():
def __init__(self):
# Load config
if os.path.exists('config.ini'):
self.config_found = True
config = configparser.ConfigParser()
config.read('config.ini')
self.username = config['ACCOUNT INFO']['username']
self.password = config['ACCOUNT INFO']['password']
self.inventory_id = config['ACCOUNT INFO']['inventory_id']
self.game_id = json.loads(config['APP LIST']['game_id'])
self.client = steamfront.Client()
logging.info("Load config success!")
self.make_url = 'https://steamcommunity.com//tradingcards/ajaxcreatebooster'
self.unpack_url = 'https://steamcommunity.com/id/{}/ajaxunpackbooster/'.format(self.inventory_id)
self.headers = {
"Referer": "https://steamcommunity.com/tradingcards/boostercreator/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
}
else:
self.config_found = False
self.game_id = []
logging.info("Config file not detected, please create a new config file.")
# Start make booster pack
def login(self):
logging.info("Getting login information...")
self.account = steam.webauth.WebAuth(self.username, self.password)
# print("Enter steam mobile authenticator:")
twofactor_code_inp = sys.argv[1]
try:
self.account_session = self.account.login(twofactor_code=str(twofactor_code_inp))
logging.info("Login success!")
return True
except Exception as e:
logging.exception("Login failed, please check account info or authenticator code, error {}".format(e))
return False
# Set main work
def run(self):
login_status = self.login()
if not login_status:
return
while True:
params = {
"sessionid" : self.account.session_id,
"appid": -1,
"series": 1,
"tradability_preference" : 1
}
response = self.account_session.post(self.make_url, headers=self.headers, data=params)
try:
goo_amount = int(re.search(r'"goo_amount":"([^"]+)"', response.text).group(1))
except:
goo_amount = -1
logging.info("Steam gems stock right now : %d" % goo_amount)
if goo_amount <= 1000:
logging.warning("Steam gems stock low, please re-fill.")
logging.info("Current time :", str(datetime.datetime.now())[:19])
time.sleep(60 * 60 * 12)
else:
for gi in self.game_id:
time.sleep(0.1)
params = {
"sessionid" : self.account.session_id,
"appid": gi,
"series": 1,
"tradability_preference" : 1
}
response = self.account_session.post(self.make_url, headers=self.headers, data=params)
if response.text[2:18] != 'purchase_eresult':
logging.info("Puchase booster pack SUCCESS on game : %s-%s" % (gi, self.client.getApp(appid=gi).name))
search_result = re.search(r'"communityitemid":"([^"]+)"', response.text)
if search_result is None:
continue
item_id = search_result.group(1)
params = {
"appid": gi,
"communityitemid": item_id,
"sessionid" : self.account.session_id
}
self.account_session.post(self.unpack_url, headers=self.headers, data=params)
else:
try:
game_name = self.client.getApp(appid=gi).name
except:
game_name = "Unknown game"
logging.error("Purchase booster pack FAILED on game : %s-%s" % (gi, game_name))
logging.info("Current time : " + str(datetime.datetime.now())[:19])
time.sleep(60 * 60 * 6 + 60 * 5) # Retry after 4 hours and 5 minutes
if __name__ == "__main__":
main = get_info()
main.run()