Skip to content

Commit

Permalink
Formatting code
Browse files Browse the repository at this point in the history
  • Loading branch information
bossoq committed Sep 15, 2022
1 parent f8d4dce commit f1106c7
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions TwitchChannelPointsMiner/classes/Twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@


class Twitch(object):
__slots__ = ["cookies_file", "user_agent", "twitch_login", "running", "device_id", "integrity", "integrity_expire"]
__slots__ = [
"cookies_file",
"user_agent",
"twitch_login",
"running",
"device_id",
"integrity",
"integrity_expire"
]

def __init__(self, username, user_agent, password=None):
cookies_path = os.path.join(Path().absolute(), "cookies")
Expand All @@ -52,7 +60,9 @@ def __init__(self, username, user_agent, password=None):
CLIENT_ID, username, self.user_agent, password=password
)
self.running = True
self.device_id = ''.join(random.choices(string.ascii_letters + string.digits, k=26))
self.device_id = ''.join(
random.choices(string.ascii_letters + string.digits, k=26)
)
self.integrity = None
self.integrity_expire = 0

Expand Down Expand Up @@ -255,7 +265,10 @@ def post_gql_request(self, json_data):
# Request for Integrity Token
# Twitch needs Authorization, Client-Id, X-Device-Id to generate JWT which is used for authorize gql requests
def post_integrity(self):
if datetime.now().timestamp() * 1000 - self.integrity_expire < 0 and self.integrity is not None:
if (
datetime.now().timestamp() * 1000 - self.integrity_expire < 0
and self.integrity is not None
):
return self.integrity
try:
response = requests.post(
Expand All @@ -271,8 +284,8 @@ def post_integrity(self):
logger.debug(
f"Data: [], Status code: {response.status_code}, Content: {response.text}"
)
self.integrity = response.json().get('token', None)
self.integrity_expire = response.json().get('expiration', 0)
self.integrity = response.json().get("token", None)
self.integrity_expire = response.json().get("expiration", 0)
return self.integrity
except requests.exceptions.RequestException as e:
logger.error(f"Error with post_integrity: {e}")
Expand Down

0 comments on commit f1106c7

Please sign in to comment.