Commit c2a36243 authored by nanahira's avatar nanahira

update error handle

parent 55be7ef8
Pipeline #26556 passed with stages
in 57 seconds
......@@ -184,7 +184,20 @@ def checkCookies():
usertl_b = twitter_b.get(usertlurl, params=params)
usertl = usertl_b
usertl_json = usertl.json()
if usertl.status_code == 200 or not ("errors" in usertl_json and usertl_json["errors"][0]["message"] == "Could not authenticate you"):
possibleErrors = [
'Could not authenticate you',
'Authorization: Denied by access control: To protect our users from spam and other malicious activity, this account is temporarily locked. Please log in to https://twitter.com to unlock your account.'
]
matchError = False
if "errors" in usertl_json:
for error in possibleErrors:
for e in usertl_json["errors"]:
if e['message'].startswith(error):
matchError = True
break
if matchError:
break
if usertl.status_code == 200 or not matchError:
print(f"Good cookie {usertl.status_code}: " + cookie + " " + usertl.text, file=sys.stderr)
good.append(cookie)
else:
......@@ -283,12 +296,15 @@ def searchban(screen_name):
usertl_b = twitter_b.get(usertlurl, params=params)
usertl = usertl_b
usertl_json = usertl.json()
# # print(usertlb)
print(usertl_json)
# if "errors" in usertlb:
# return "An error occurred" # TODO: Better error handling
# if len(usertlb) == 0:
# return "No tweets found" # TODO: Better error handling
if 'errors' in usertl_json:
returnjson["profile"]["error"] = usertl_json["errors"][0]['message']
return returnjson
if len(usertl_json) == 0 or 'user' not in usertl_json['data']:
returnjson["profile"]["has_tweets"] = False
return returnjson
......@@ -552,12 +568,12 @@ def searchban(screen_name):
if __name__ == '__main__':
if os.getenv('CHECK_COOKIE'):
good, bad = checkCookies()
print("Good cookies:")
#print("Good cookies:")
for g in good:
print(g)
print("Bad cookies:")
for b in bad:
print(b)
#print("Bad cookies:")
#for b in bad:
# print(b)
# quit
else:
app.run(debug=True, port=os.environ.get("PORT", 5000), host="0.0.0.0")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment