Commit b1f2d2c1 authored by Your Name's avatar Your Name

Something broke with profile API, so temporary fix

parent f5415618
web: python3 backend.py --port=$PORT --host=0.0.0.0 --cors-allow=*
\ No newline at end of file
web: python3 backend_requests.py
\ No newline at end of file
from flask import Flask
from flask_cors import CORS
from requests_oauthlib import OAuth1Session, OAuth2Session
import os
app = Flask(__name__)
CORS(app)
TWITTER_AUTH_KEY = 'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA'
@app.route('/{screen_name}')
def shadowban(screen_name):
# DO IT
pass
@app.route("/<screen_name>")
def searchban(screen_name):
returnjson = {
"profile": {
# "id": "7080152",
# "screenName": "TwitterJP",
# "protected": False,
# "suspended": False,
# "hasTweets": True,
"isExist": False,
"error": None
},
# "check": {
# "search": 1484727214419628037,
# "suggest": True,
# "ghost": {"ban": True},
# "reply": {"ban": False, "tweet": "1480819689898987523", "in_reply_to": "1369626114381901828"}
# }
}
# twitter = OAuth1Session(TWITTER_IPHONE_CK, TWITTER_IPHONE_CS)
twitter_b = OAuth2Session()
twitter_b.headers["Authorization"] = "Bearer {}".format(TWITTER_AUTH_KEY)
# check rate limit
# response = twitter_b.get("https://api.twitter.com/1.1/application/rate_limit_status.json")
# print(response.json())
# profile_url = "https://api.twitter.com/1.1/users/show.json"
# params = {"screen_name": screen_name}
# profile_info = twitter_b.get(profile_url, params=params)
# profile_json = profile_info.json()
# print(profile_json)
# if profile_info.status_code == 200:
# returnjson["profile"]["isExist"] = True
# returnjson["profile"]["id"] = profile_json["id_str"]
# returnjson["profile"]["screenName"] = profile_json["screen_name"]
# returnjson["profile"]["protected"] = profile_json["protected"]
# elif profile_info.status_code == 403:
# returnjson["profile"]["suspended"] = True
# return returnjson
# else:
# returnjson["profile"]["error"] = profile_json["errors"][0]["message"]
# # return returnjson
# if profile_json["protected"] == True:
# returnjson["profile"]["protected"] = True
# return returnjson
# if profile_json["statuses_count"] == 0:
# returnjson["profile"]["hasTweets"] = False
# return returnjson
# else:
# returnjson["profile"]["hasTweets"] = True
# check whether the user has any tweets
usertlurl = "https://api.twitter.com/1.1/statuses/user_timeline.json"
params = {"screen_name": screen_name, "count": 200}
usertl_b = twitter_b.get(usertlurl, params=params)
usertl = usertl_b
usertl_json = usertl.json()
# # print(usertlb)
# 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 len(usertl_json) == 0:
returnjson["profile"]["hasTweets"] = False
return returnjson
returnjson["profile"]["hasTweets"] = True
if usertl.status_code == 200:
returnjson["profile"]["isExist"] = True
returnjson["profile"]["id"] = usertl_json[0]["user"]["id_str"]
returnjson["profile"]["screenName"] = usertl_json[0]["user"]["screen_name"]
# returnjson["profile"]["protected"] = usertl_json["protected"]
elif usertl.status_code == 403:
returnjson["profile"]["suspended"] = True
return returnjson
else:
if "error" in usertl_json and usertl_json["error"] == "Not authorized.":
returnjson["profile"]["protected"] = True
returnjson["profile"]["suspended"] = True
returnjson["profile"]["hasTweets"] = False
return returnjson
returnjson["profile"]["error"] = usertl_json
return returnjson
# if usertl_json["protected"] == True:
# returnjson["profile"]["protected"] = True ## how do you determen protected and suspended
# return returnjson
# if usertl_json["statuses_count"] == 0:
# returnjson["profile"]["hasTweets"] = False
# return returnjson
# else:
# returnjson["profile"]["hasTweets"] = True
returnjson["test"] = {
"search": "ok",
"typeahead": True, ## suggest ban
"ghost": {"ban": True},
"more_replies": {"ban": False, "tweet": "-1", "in_reply_to": "-1"}
}
searchurl = "https://api.twitter.com/1.1/users/search.json"
params = {"q": "from:{}".format(screen_name), "count": 1}
search = twitter_b.get(searchurl, params=params).json()
# print(search)
if len(search) == 0:
returnjson["test"]["search"] = "ban"
return returnjson
else:
return returnjson
app.run(debug=False, port=os.environ.get("PORT", 5000), host="0.0.0.0")
aiohttp==3.7.4.post0
pymongo
bs4==0.0.1
daemon
# gunicorn
\ No newline at end of file
flask
requests_oauthlib
flask_cors
\ No newline at end of file
aiohttp==3.7.4.post0
pymongo
bs4==0.0.1
daemon
# gunicorn
\ No newline at end of file
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