Commit 19ec4bd3 authored by nanahira's avatar nanahira

Merge branch 'steve' of git.mycard.moe:nanahira/shadowban-eu-backend into steve

parents c80a3172 6d5e363e
Pipeline #22777 passed with stages
in 43 seconds
...@@ -32,8 +32,12 @@ privateKey = os.getenv('TWITTER_AUTH_KEY') ...@@ -32,8 +32,12 @@ privateKey = os.getenv('TWITTER_AUTH_KEY')
if privateKey: if privateKey:
twitterKeys = privateKey.split(" ") twitterKeys = privateKey.split(" ")
cookie = os.getenv('COOKIE') cookies = [os.getenv('COOKIE')]
csrf = os.getenv('CSRF')
cookie_file = os.getenv('COOKIE_FILE')
if cookie_file:
with open(cookie_file, 'r') as f:
cookies = str.strip(f.read()).split("\n")
print("Booting") print("Booting")
ENDPOINT = { ENDPOINT = {
...@@ -73,9 +77,10 @@ def getTwitterSession(useCookie): ...@@ -73,9 +77,10 @@ def getTwitterSession(useCookie):
twitter_b = OAuth2Session() twitter_b = OAuth2Session()
twitter_b.headers["Authorization"] = "Bearer {}".format(random.choice(twitterKeys)) twitter_b.headers["Authorization"] = "Bearer {}".format(random.choice(twitterKeys))
twitter_b.headers['user-agent'] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" twitter_b.headers['user-agent'] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
if cookie and csrf: # and useCookie: cookie = random.choice(cookies)
if cookie: # and useCookie:
twitter_b.headers['cookie'] = cookie twitter_b.headers['cookie'] = cookie
twitter_b.headers['x-csrf-token'] = csrf twitter_b.headers['x-csrf-token'] = cookie.split("ct0=")[1].split(";")[0]
return twitter_b return twitter_b
def doSearch(screen_name): def doSearch(screen_name):
...@@ -346,7 +351,7 @@ def searchban(screen_name): ...@@ -346,7 +351,7 @@ def searchban(screen_name):
print("User ID of {}: {}".format(screen_name, user_id)) print("User ID of {}: {}".format(screen_name, user_id))
get_reply_vars = { get_reply_vars = {
"count": 20, "userId": user_id, "count": 200, "userId": user_id,
"includePromotedContent": False, "withSuperFollowsUserFields": False, "withBirdwatchPivots": False, "includePromotedContent": False, "withSuperFollowsUserFields": False, "withBirdwatchPivots": False,
"withDownvotePerspective": False, "withReactionsMetadata": False, "withDownvotePerspective": False, "withReactionsMetadata": False,
"withReactionsPerspective": False, "withSuperFollowsTweetFields": False, "withVoice": False, "withV2Timeline": False, "withReactionsPerspective": False, "withSuperFollowsTweetFields": False, "withVoice": False, "withV2Timeline": False,
...@@ -374,7 +379,7 @@ def searchban(screen_name): ...@@ -374,7 +379,7 @@ def searchban(screen_name):
if not ghostban: if not ghostban:
# all checks done # all checks done
break break
if ent["entryId"].startswith("tweet"): if ent["entryId"].startswith("tweet") and "legacy" in ent["content"]["itemContent"]["tweet_results"]["result"]:
tmp = ent["content"]["itemContent"]["tweet_results"]["result"]["legacy"] tmp = ent["content"]["itemContent"]["tweet_results"]["result"]["legacy"]
if "in_reply_to_status_id_str" in tmp and tmp["in_reply_to_status_id_str"] not in checkedTweets: if "in_reply_to_status_id_str" in tmp and tmp["in_reply_to_status_id_str"] not in checkedTweets:
reply = tmp reply = tmp
...@@ -414,7 +419,7 @@ def searchban(screen_name): ...@@ -414,7 +419,7 @@ def searchban(screen_name):
print("Current entry of {} is: {}".format(screen_name, ent["entryId"])) print("Current entry of {} is: {}".format(screen_name, ent["entryId"]))
if ent["entryId"].startswith("conversationthread") and ghostban: if ent["entryId"].startswith("conversationthread") and ghostban:
for item in ent["content"]["items"]: for item in ent["content"]["items"]:
if "tweet_results" in item["item"]["itemContent"] and item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id: if "tweet_results" in item["item"]["itemContent"] and "legacy" in item["item"]["itemContent"]["tweet_results"]["result"] and item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id:
replyId = item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"] replyId = item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]
returnjson["tests"]["ghost"] = {"ban": False, "tweet": tweetId, "in_reply_to": replyId} returnjson["tests"]["ghost"] = {"ban": False, "tweet": tweetId, "in_reply_to": replyId}
ghostban = False ghostban = False
...@@ -437,7 +442,7 @@ def searchban(screen_name): ...@@ -437,7 +442,7 @@ def searchban(screen_name):
if c_ent["entryId"].startswith("conversationthread"): if c_ent["entryId"].startswith("conversationthread"):
print("Checking more contents of {} by {}".format(tweetId, screen_name)) print("Checking more contents of {} by {}".format(tweetId, screen_name))
for c_item in c_ent["content"]["items"]: for c_item in c_ent["content"]["items"]:
if c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id: if "legacy" in c_item["item"]["itemContent"]["tweet_results"]["result"] and c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id:
replyId = c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"] replyId = c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]
returnjson["tests"]["more_replies"] = {"ban": True, "in_reply_to": replyId, "tweet": tweetId} returnjson["tests"]["more_replies"] = {"ban": True, "in_reply_to": replyId, "tweet": tweetId}
print("{} is reply deboosted because of {} => {}.".format(screen_name, tweetId, replyId)) print("{} is reply deboosted because of {} => {}.".format(screen_name, tweetId, replyId))
......
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