Skip to content

Commit

Permalink
fix guest token retry #23
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu1845 committed Dec 18, 2021
1 parent 1cac5a5 commit f5e6abd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions twspace_dl/TwspaceDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ def from_user_url(cls, url: str, format_str: str):

@staticmethod
def guest_token() -> str:
response = requests.get("https://twitter.com/").text
guest_token = ""
for _ in range(5):
for i in range(5):
response = requests.get("https://twitter.com/").text
guest_token_list = re.findall(r"(?<=gt\=)\d{19}", response)
if len(guest_token_list) != 0:
guest_token = guest_token_list[0]
else:
print(f"trying to get guest token try number:{i}", end="\r")
time.sleep(1)
if not guest_token:
raise RuntimeError("No guest token found after five retry")
print()
logging.debug(guest_token)
return guest_token

Expand Down

0 comments on commit f5e6abd

Please sign in to comment.