diff --git a/api/heart_beat.py b/api/heart_beat.py index 8a322ad..59ca6bb 100644 --- a/api/heart_beat.py +++ b/api/heart_beat.py @@ -17,4 +17,4 @@ def heart_beat(): } } - requests.post('https://swap.labrie.ca/api/ping/', json = data) \ No newline at end of file + requests.post('https://swap.labrie.ca/api/ping/', json = data, timeout = 5) \ No newline at end of file diff --git a/api/labrie_check.py b/api/labrie_check.py index 0ae88c0..f0370ac 100644 --- a/api/labrie_check.py +++ b/api/labrie_check.py @@ -9,7 +9,7 @@ def labrie_check(shaketag: str, type: str) -> dict: 'step': type } - response = requests.post('https://swap.labrie.ca/api/', json = data) + response = requests.post('https://swap.labrie.ca/api/', json = data, timeout = 5) if (response.ok): response = response.json() @@ -25,7 +25,7 @@ def labrie_check_multi(shaketags: list, type: str) -> dict: 'step': type } - response = requests.post('https://swap.labrie.ca/api/multi/', json = data) + response = requests.post('https://swap.labrie.ca/api/multi/', json = data, timeout = 5) if (response.ok): response = response.json() diff --git a/api/login.py b/api/login.py index 9b0f666..ef0e630 100644 --- a/api/login.py +++ b/api/login.py @@ -1,20 +1,38 @@ import requests import json +import socket import globals from api.exception import raise_exception from utilities.log import log +login_headers = { + 'X-Device-Brand': 'bot', + 'X-Device-Model': socket.gethostname(), + 'X-Device-System-Name': 'burntbot', + 'X-Device-System-Version': str(globals.version), + 'X-Device-Carrier': '', + 'X-Device-Mac-Address': 'AA:BB:CC:DD:EE:FF', + 'X-Device-Manufacturer': '@burnttoaster', + 'X-Device-Id': '', + 'X-Device-Ip-Address': '10.0.0.1', + 'X-Device-Locale': 'en-CA', + 'X-Device-Country': 'CA', + 'X-Device-Name': f'@burnttoaster bot v{globals.version}', + 'X-Device-Total-Disk-Capacity': '138764288', + 'X-Device-Total-Memory': '37019976576', + 'X-Device-Is-Tablet': 'false', + 'X-Device-Has-Notch': 'false', + 'X-Notification-Token': '', + 'Content-Type': 'application/json' +} + # returns False on email verification # returns accessToken for 2FA on success def pre_login(email: str, password: str): - # copy headers to append content type - local_headers = globals.headers.copy() - local_headers['Content-Type'] = 'application/json' - local_headers['X-Device-Model'] = 'SM-G930W8' - local_headers['X-Device-System-Name'] = 'Android' - local_headers['X-Device-System-Version'] = '8.0.0' + # copy global headers so that we can append our own headers without affecting global + local_headers = {**globals.headers, **login_headers} # pre 2FA POST response = requests.post('https://api.shakepay.com/authentication', headers = local_headers, data = json.dumps({ @@ -22,7 +40,7 @@ def pre_login(email: str, password: str): 'strategy': 'local', 'totpType': 'sms', 'username': email - })) + }), timeout = 5) if (response.status_code == 403): return False @@ -35,19 +53,15 @@ def pre_login(email: str, password: str): return response['accessToken'] def mfa_login(code: str, pre_token: str) -> str: - # copy headers to append content type - local_headers = globals.headers.copy() - local_headers['Content-Type'] = 'application/json' + # copy global headers so that we can append our own headers without affecting global + local_headers = {**globals.headers, **login_headers} local_headers['Authorization'] = pre_token - local_headers['X-Device-Model'] = 'SM-G930W8' - local_headers['X-Device-System-Name'] = 'Android' - local_headers['X-Device-System-Version'] = '8.0.0' # 2FA POST response = requests.post('https://api.shakepay.com/authentication', headers = local_headers, data = json.dumps({ 'mfaToken': code, 'strategy': 'mfa' - })) + }), timeout = 5) # make sure we have 2xx status if (not response.ok): diff --git a/api/shakingsats.py b/api/shakingsats.py index e4e3506..573a312 100644 --- a/api/shakingsats.py +++ b/api/shakingsats.py @@ -1,33 +1,35 @@ import requests import json +import socket import globals from utilities.log import log def shaking_sats(): - # all these headers are required for shaking sats - local_headers = globals.headers.copy() - local_headers['X-Device-Brand'] = 'samsung' - local_headers['X-Device-Model'] = 'SM-G930W8' - local_headers['X-Device-System-Name'] = 'Android' - local_headers['X-Device-System-Version'] = '8.0.0' - local_headers['X-Device-Carrier'] = 'Bell' - local_headers['X-Device-Mac-Address'] = 'AA:BB:CC:DD:EE:FF' - local_headers['X-Device-Manufacturer'] = 'samsung' - local_headers['X-Device-Id'] = 'universal8890' - local_headers['X-Device-Ip-Address'] = '10.0.0.0' - local_headers['X-Device-Locale'] = 'en-CA' - local_headers['X-Device-Country'] = 'CA' - local_headers['X-Device-Name'] = f'@burnttoaster bot v{globals.version}' - local_headers['X-Device-Total-Disk-Capacity'] = '138764288' - local_headers['X-Device-Total-Memory'] = '37019976576' - local_headers['X-Device-Is-Tablet'] = 'false' - local_headers['X-Device-Has-Notch'] = 'false' - local_headers['X-Notification-Token'] = '' - local_headers['Content-Type'] = 'application/json' + # copy global headers so that we can append our own headers without affecting global + local_headers = {**globals.headers, **{ + 'X-Device-Brand': 'bot', + 'X-Device-Model': socket.gethostname(), + 'X-Device-System-Name': 'burntbot', + 'X-Device-System-Version': str(globals.version), + 'X-Device-Carrier': '', + 'X-Device-Mac-Address': 'AA:BB:CC:DD:EE:FF', + 'X-Device-Manufacturer': '@burnttoaster', + 'X-Device-Id': '', + 'X-Device-Ip-Address': '10.0.0.1', + 'X-Device-Locale': 'en-CA', + 'X-Device-Country': 'CA', + 'X-Device-Name': f'@burnttoaster bot v{globals.version}', + 'X-Device-Total-Disk-Capacity': '138764288', + 'X-Device-Total-Memory': '37019976576', + 'X-Device-Is-Tablet': 'false', + 'X-Device-Has-Notch': 'false', + 'X-Notification-Token': '', + 'Content-Type': 'application/json' + }} - response = requests.post('https://api.shakepay.com/shaking-sats', headers = local_headers, data = json.dumps({})) + response = requests.post('https://api.shakepay.com/shaking-sats', headers = local_headers, data = json.dumps({}), timeout = 5) log(f'shaking-sats code: {response.status_code}', True) log(f'shaking-sats data: {response.json()}', True) \ No newline at end of file diff --git a/api/transactions.py b/api/transactions.py index d294fd2..23fe896 100644 --- a/api/transactions.py +++ b/api/transactions.py @@ -19,7 +19,7 @@ def send_transaction(amount: float, shaketag: str, note: str) -> dict: 'toType': 'user' } - response = requests.post('https://api.shakepay.com/transactions', headers = local_headers, data = json.dumps(body)) + response = requests.post('https://api.shakepay.com/transactions', headers = local_headers, data = json.dumps(body), timeout = 5) # make sure we have 2xx status if (not response.ok): @@ -33,7 +33,7 @@ def get_transactions(params: dict) -> tuple: # copy headers to append content type local_headers = globals.headers.copy() - response = requests.get('https://api.shakepay.com/transactions/history', headers = local_headers, params = params) + response = requests.get('https://api.shakepay.com/transactions/history', headers = local_headers, params = params, timeout = 5) headers = response.headers # make sure we have 2xx status diff --git a/api/users.py b/api/users.py index d3588c7..29d912c 100644 --- a/api/users.py +++ b/api/users.py @@ -6,7 +6,7 @@ from utilities.log import log def users(user_id: str) -> dict: - response = requests.get(f'https://api.shakepay.com/users/{user_id}', headers = globals.headers) + response = requests.get(f'https://api.shakepay.com/users/{user_id}', headers = globals.headers, timeout = 5) # make sure we have 2xx status if (not response.ok): @@ -23,7 +23,7 @@ def search(shaketag: str) -> list: if (local_shaketag[0] == '@'): local_shaketag = shaketag[1:] if (shaketag != ''): - response = requests.get(f'https://api.shakepay.com/users?username={local_shaketag}', headers = globals.headers) + response = requests.get(f'https://api.shakepay.com/users?username={local_shaketag}', headers = globals.headers, timeout = 5) if (not response.ok): log('Something went wrong when fetching users: {}'.format(response.text)) diff --git a/api/version.py b/api/version.py index ab156f7..1c6359b 100644 --- a/api/version.py +++ b/api/version.py @@ -6,7 +6,7 @@ from utilities.log import log def get_master_version() -> bool: - response = requests.get('https://raw.githubusercontent.com/itslupus/burntbot/master/.version') + response = requests.get('https://raw.githubusercontent.com/itslupus/burntbot/master/.version', timeout = 5) # make sure we have 2xx status if (not response.ok): diff --git a/api/waitlist.py b/api/waitlist.py index 219448f..7f83c3b 100644 --- a/api/waitlist.py +++ b/api/waitlist.py @@ -1,4 +1,5 @@ import requests +import time import globals @@ -11,12 +12,15 @@ def update_waitlist(): Update the local cache containing waitlist details (position, points, etc) ''' + # dont check waitlist if its been < 5 minutes since last check + if (globals.waitlist_last_check + (60 * 5) > time.time()): return + local_headers = globals.headers.copy() # use etags to prevent redundant data transfer if (globals.waitlist_etag): local_headers['If-None-Match'] = globals.waitlist_etag - response = requests.get('https://api.shakepay.com/card/waitlist', headers = local_headers) + response = requests.get('https://api.shakepay.com/card/waitlist', headers = local_headers, timeout = 5) # make sure we have 2xx status if (not response.ok): diff --git a/api/wallet.py b/api/wallet.py index 2692c2e..fa38bde 100644 --- a/api/wallet.py +++ b/api/wallet.py @@ -6,7 +6,7 @@ from utilities.log import log def get_wallet(): - response = requests.get('https://api.shakepay.com/wallets', headers = globals.headers) + response = requests.get('https://api.shakepay.com/wallets', headers = globals.headers, timeout = 5) # make sure we have 2xx status if (not response.ok): diff --git a/classes/heartbeat.py b/classes/heartbeat.py index e9ecef2..fe1fcb6 100644 --- a/classes/heartbeat.py +++ b/classes/heartbeat.py @@ -17,6 +17,7 @@ def run(self): while (not self.stop.is_set()) and (db.get_key_value('heart_beat', False)) and (SwapBot.bot_state) and (not globals.bot_flags['listen']): heart_beat() - self.stop.wait(60 * 5) + # ping swapper database every 45 seconds + self.stop.wait(45) db.close() \ No newline at end of file diff --git a/globals.py b/globals.py index f152df8..d432c40 100644 --- a/globals.py +++ b/globals.py @@ -15,6 +15,7 @@ waitlist_points = 0 waitlist_paddles = [] waitlist_swaps = 0 +waitlist_last_check = 0 # bot specific flags bot_flags = {