This commit is contained in:
35
twitfix.py
35
twitfix.py
@@ -290,9 +290,20 @@ def getTweetData(twitter_url,include_txt="false",include_rtf="false"):
|
||||
addVnfToLinkCache(twitter_url,tweetData)
|
||||
return tweetData
|
||||
|
||||
def getUserData(twitter_url):
|
||||
def getUserData(twitter_url,includeFeed=False):
|
||||
rawUserData = twExtract.extractUser(twitter_url,workaroundTokens=config['config']['workaroundTokens'].split(','))
|
||||
userData = getApiUserResponse(rawUserData)
|
||||
|
||||
if includeFeed:
|
||||
if userData['protected']:
|
||||
userData['latest_tweets']=[]
|
||||
else:
|
||||
feed = twExtract.extractUserFeedFromId(userData['id'],workaroundTokens=config['config']['workaroundTokens'].split(','))
|
||||
apiFeed = []
|
||||
for tweet in feed:
|
||||
apiFeed.append(getApiResponse(tweet))
|
||||
userData['latest_tweets'] = apiFeed
|
||||
|
||||
return userData
|
||||
|
||||
@app.route('/<path:sub_path>') # Default endpoint used by everything
|
||||
@@ -322,7 +333,15 @@ def twitfix(sub_path):
|
||||
username=sub_path.split("/")[0]
|
||||
extra = sub_path.split("/")[1]
|
||||
if extra in [None,"with_replies","media","likes","highlights","superfollows","media",''] and username != "" and username != None:
|
||||
userData = getUserData(f"https://twitter.com/{username}")
|
||||
try:
|
||||
userData = getUserData(f"https://twitter.com/{username}","with_tweets" in request.args)
|
||||
except twExtract.TwExtractError as e:
|
||||
if isApiRequest:
|
||||
status=500
|
||||
if 'not found' in e.msg:
|
||||
status=404
|
||||
return Response(json.dumps({"error": e.msg}), status=status,mimetype='application/json')
|
||||
return message("Error getting user data: "+str(e.msg))
|
||||
if isApiRequest:
|
||||
if userData is None:
|
||||
abort(404)
|
||||
@@ -351,6 +370,12 @@ def twitfix(sub_path):
|
||||
if 'qrtURL' in tweetData and tweetData['qrtURL'] is not None:
|
||||
qrt = getTweetData(tweetData['qrtURL'])
|
||||
tweetData['qrt'] = qrt
|
||||
|
||||
retweet = None
|
||||
if 'retweetURL' in tweetData and tweetData['retweetURL'] is not None:
|
||||
retweet = getTweetData(tweetData['retweetURL'])
|
||||
tweetData['retweet'] = retweet
|
||||
|
||||
tweetData = deepcopy(tweetData)
|
||||
log.success("Tweet Data Get success")
|
||||
if '?' in request.url:
|
||||
@@ -465,6 +490,12 @@ def api_v1_status(tweet_id):
|
||||
if 'qrtURL' in tweetData and tweetData['qrtURL'] is not None:
|
||||
qrt = getTweetData(tweetData['qrtURL'])
|
||||
tweetData['qrt'] = qrt
|
||||
|
||||
retweet = None
|
||||
if 'retweetURL' in tweetData and tweetData['retweetURL'] is not None:
|
||||
retweet = getTweetData(tweetData['retweetURL'])
|
||||
tweetData['retweet'] = retweet
|
||||
|
||||
if tweetData is None:
|
||||
abort(500) # this should cause Discord to fall back to the default embed
|
||||
return activitymg.tweetDataToActivity(tweetData,embedIndex)
|
||||
|
||||
Reference in New Issue
Block a user