-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteamClient.py
More file actions
91 lines (84 loc) · 3.21 KB
/
SteamClient.py
File metadata and controls
91 lines (84 loc) · 3.21 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import time
import decimal
import requests
from tqdm import tqdm
import steam.webauth as wa
from bs4 import BeautifulSoup
from urllib.parse import quote
from base64 import b64decode, b64encode
from steam.guard import SteamAuthenticator
class ApiException(Exception):
def __init__(self, error):
print(error)
def toNearest(num, tickSize):
tickDec = decimal.Decimal(str(tickSize))
return float((decimal.Decimal(round(num / tickSize, 0)) * tickDec))
class SteamClient:
def __init__(self, username, password, secrets=None, deviceId=None):
self.user = wa.WebAuth(username, password)
if secrets is not None:
self.mobile = wa.MobileWebAuth(username, password)
self.sa = SteamAuthenticator(secrets)
else:
self.mobile = None
self.sa = None
self.deviceId = deviceId
self.login()
self.baseURL = 'https://steamcommunity.com'
self.urlToId = {}
self.SIDDB = requests.Session()
print(f'Steam User: {self.user.steam_id.as_64} Logged.')
def login(self):
notDone = True
while notDone:
try:
self.user.login()
except wa.CaptchaRequired:
print(self.user.captcha_url)
self.user.login(captcha=input('Captcha: '))
notDone = False
except wa.EmailCodeRequired:
self.user.login(email_code=input('Email Code: '))
notDone = False
except wa.TwoFactorCodeRequired:
if self.sa is None:
self.user.login(twofactor_code=input('Two-Factor Code: '))
else:
self.user.login(twofactor_code=self.sa.get_code())
notDone = False
self.steamId = self.user.steam_id
if self.mobile is None:
return
timeToSleep = 30 - int(time.time() % 30) + 1
for i in tqdm(range(timeToSleep), desc='Waiting for next code'):
time.sleep(1)
notDone = True
while notDone:
try:
self.mobile.login()
except wa.CaptchaRequired:
print(self.mobile.captcha_url)
self.mobile.login(captcha=input('Captcha: '))
notDone = False
except wa.EmailCodeRequired:
self.mobile.login(email_code=input('Email Code: '))
notDone = False
except wa.TwoFactorCodeRequired:
self.mobile.login(twofactor_code=self.sa.get_code())
notDone = False
return
def validateWalletCode(self, code):
payload = {
'sessionid': self.user.session.cookies.get_dict()['sessionid'],
'wallet_code': code
}
return self.user.session.post('https://store.steampowered.com/account/validatewalletcode/', data=payload).json()
def redeemWalletCode(self, code):
payload = {
'sessionid': self.user.session.cookies.get_dict()['sessionid'],
'wallet_code': code
}
return self.user.session.post('https://store.steampowered.com/account/confirmredeemwalletcode/', data=payload).json()