Commit 90f622dd authored by nanahira's avatar nanahira

check every tweet instead of one

parent 0d755dee
Pipeline #18764 passed with stage
in 39 seconds
...@@ -248,10 +248,14 @@ def searchban(screen_name): ...@@ -248,10 +248,14 @@ def searchban(screen_name):
replies = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["UserTweetsAndReplies"], "UserTweetsAndReplies"), params=get_reply_param) replies = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["UserTweetsAndReplies"], "UserTweetsAndReplies"), params=get_reply_param)
# print(replies.text) # print(replies.text)
try: try:
ghostban = True
ghostTweetId = None
ghostReplyId = None
showmore = False
showmoreTweetId = None
showmoreReplyId = None
repliesJson = replies.json() repliesJson = replies.json()
# print(repliesJson)
maindata = repliesJson["data"]["user"]["result"]["timeline"]["timeline"]["instructions"] maindata = repliesJson["data"]["user"]["result"]["timeline"]["timeline"]["instructions"]
for d in maindata: for d in maindata:
if d["type"] == "TimelineAddEntries": if d["type"] == "TimelineAddEntries":
...@@ -260,95 +264,101 @@ def searchban(screen_name): ...@@ -260,95 +264,101 @@ def searchban(screen_name):
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: if "in_reply_to_status_id_str" in tmp:
reply = tmp reply = tmp
# print("Found a reply!", tmp["full_text"]) tweetId = reply["in_reply_to_status_id_str"]
break if ghostTweetId is None:
ghostTweetId = tweetId
if reply is None: ghostReplyId = reply["id_str"]
returnjson["tests"]["ghost"] = {} if showmoreTweetId is None:
returnjson["tests"]["more_replies"] = {} showmoreTweetId = tweetId
else: showmoreReplyId = reply["id_str"]
tweet_detail_vars = { tweet_detail_vars = {
"focalTweetId": reply["in_reply_to_status_id_str"], "focalTweetId": tweetId,
"includePromotedContent":False, "includePromotedContent":False,
"withBirdwatchNotes":False, "withBirdwatchNotes":False,
"withSuperFollowsUserFields":False, "withSuperFollowsUserFields":False,
"withDownvotePerspective":False, "withDownvotePerspective":False,
"withReactionsMetadata":False, "withReactionsMetadata":False,
"withReactionsPerspective":False, "withReactionsPerspective":False,
"withSuperFollowsTweetFields":False, "withSuperFollowsTweetFields":False,
"withVoice":False, "withVoice":False,
} }
tweetdetails = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["TweetDetail"], "TweetDetail"), params={"variables": json.dumps(tweet_detail_vars), "features": FeaturesJson}) tweetdetails = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["TweetDetail"], "TweetDetail"), params={"variables": json.dumps(tweet_detail_vars), "features": FeaturesJson})
tweetData = tweetdetails.json()["data"]
insts = tweetdetails.json()["data"]["threaded_conversation_with_injections"]["instructions"] if "threaded_conversation_with_injections" not in tweetData:
ghostban = True continue
inReplyToGhost = reply["id_str"] insts = tweetdetails.json()["data"]["threaded_conversation_with_injections"]["instructions"]
inReplyToShowMore = reply["id_str"] for inst in insts:
showmore = False if not ghostban and showmore:
for inst in insts: # all checks done
if inst["type"] == "TimelineAddEntries":
for ent in inst["entries"]:
print("Current entry of {} is: {}".format(screen_name, ent["entryId"]))
if ent["entryId"].startswith("conversationthread") and ghostban:
for item in ent["content"]["items"]:
#print("Current sub entry of {} {} is: {}".format(screen_name, ent["entryId"], item["item"]["itemContent"]))
if "tweet_results" in item["item"]["itemContent"] and item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id:
validId = item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]
returnjson["tests"]["ghost"] = {"ban": False, "in_reply_to": validId}
ghostban = False
print("Found valid reply {}, so {} is not ghost banned.".format(validId, screen_name))
break break
if ent["entryId"].startswith("cursor-bottom"): if inst["type"] == "TimelineAddEntries":
print("{}'s test touched bottom.".format(screen_name)) for ent in inst["entries"]:
#returnjson["tests"]["ghost"] = {} if not ghostban and showmore:
#returnjson["tests"]["more_replies"] = {} # all checks done
break break
print("Current entry of {} is: {}".format(screen_name, ent["entryId"]))
if ent["entryId"].startswith("cursor-showmorethreadsprompt") and not showmore: if ent["entryId"].startswith("conversationthread") and ghostban:
# showmore = True for item in ent["content"]["items"]:
cursor_vars = tweet_detail_vars if "tweet_results" in item["item"]["itemContent"] and item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id:
cursor_vars["cursor"] = ent["content"]["itemContent"]["value"] replyId = item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]
cursor = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["TweetDetail"], "TweetDetail"), params={"variables": json.dumps(cursor_vars), "features": FeaturesJson}) returnjson["tests"]["ghost"] = {"ban": False, "tweet": tweetId, "in_reply_to": replyId}
ghostban = False
cursor_insts = cursor.json()["data"]["threaded_conversation_with_injections"]["instructions"] print("Found valid reply {} => {}, so {} is not ghost banned.".format(tweetId, replyId, screen_name))
for c_i in cursor_insts:
if c_i["type"] == "TimelineAddEntries":
if len(c_i["entries"]) == 0:
returnjson["tests"]["more_replies"] = {"ban": True}
showmore = True
break
for c_ent in c_i["entries"]:
if c_ent["entryId"].startswith("conversationthread"):
# more = True
print("Checking more contents of {}".format(screen_name))
for c_item in c_ent["content"]["items"]:
if c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id:
inReplyToShowMore = c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]
# returnjson["tests"]["ghost"] = {"ban": False, "in_reply_to": inReplyToShowMore}
returnjson["tests"]["more_replies"] = {"ban": True, "in_reply_to": inReplyToShowMore}
print("{} is reply deboosted because of {}.".format(screen_name, inReplyToShowMore))
showmore = True
# more = False
break break
#if more: if ent["entryId"].startswith("cursor-showmorethreadsprompt") and not showmore:
# print("{} is both ghost banned and reply deboosted.".format(screen_name)) # showmore = True
# returnjson["tests"]["ghost"] = {"ban": True} cursor_vars = tweet_detail_vars
# returnjson["tests"]["more_replies"] = {"ban": True} cursor_vars["cursor"] = ent["content"]["itemContent"]["value"]
if ghostban: cursor = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["TweetDetail"], "TweetDetail"), params={"variables": json.dumps(cursor_vars), "features": FeaturesJson})
print("{} is ghost banned.".format(screen_name))
returnjson["tests"]["ghost"] = {"ban": True, "in_reply_to": inReplyToGhost} cursor_insts = cursor.json()["data"]["threaded_conversation_with_injections"]["instructions"]
if not showmore: for c_i in cursor_insts:
returnjson["tests"]["more_replies"] = { if c_i["type"] == "TimelineAddEntries":
"ban": False, if len(c_i["entries"]) == 0:
"in_reply_to": inReplyToShowMore, returnjson["tests"]["more_replies"] = {"ban": True}
} showmore = True
replyTweet = reply["in_reply_to_status_id_str"] break
for testField in ["ghost", "more_replies"]: for c_ent in c_i["entries"]:
if testField in returnjson["tests"]: if c_ent["entryId"].startswith("conversationthread"):
returnjson["tests"][testField]["tweet"] = replyTweet print("Checking more contents of {} by {}".format(tweetId, screen_name))
for c_item in c_ent["content"]["items"]:
if c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id:
replyId = c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]
returnjson["tests"]["more_replies"] = {"ban": True, "in_reply_to": replyId, "tweet": tweetId}
print("{} is reply deboosted because of {} => {}.".format(screen_name, tweetId, replyId))
showmore = True
break
if ghostban:
print("{} is ghost banned.".format(screen_name))
returnjson["tests"]["ghost"] = {
"ban": True,
"tweet": ghostTweetId,
"in_reply_to": ghostReplyId
}
if not showmore:
returnjson["tests"]["more_replies"] = {
"ban": False,
"in_reply_to": showmoreReplyId,
"tweet": showmoreTweetId
}
# No search ban || more replies => No ghost ban
if returnjson["tests"]["search"] and returnjson["tests"]["search"] != "_error" and "ban" in returnjson["tests"]["ghost"] and returnjson["tests"]["ghost"]["ban"] == True or "ban" in returnjson["tests"]["more_replies"] and returnjson["tests"]["more_replies"]["ban"] == True:
returnjson["tests"]["ghost"] = {
"ban": False,
"tweet": ghostTweetId,
"in_reply_to": ghostReplyId
}
# No ghost ban && unknown more replies => No more replies ban
if "ban" not in returnjson["tests"]["more_replies"] and "ban" in returnjson["tests"]["ghost"] and returnjson["tests"]["ghost"]["ban"] == False:
returnjson["tests"]["more_replies"] = {
"ban": False,
"in_reply_to": showmoreReplyId,
"tweet": showmoreTweetId
}
except KeyError as e: except KeyError as e:
print("Errored testing {}".format(screen_name)) print("Errored testing {}".format(screen_name))
# print(Exception.with_traceback(e)) print(e)
returnjson["tests"]["ghost"] = {} returnjson["tests"]["ghost"] = {}
returnjson["tests"]["more_replies"] = {} returnjson["tests"]["more_replies"] = {}
...@@ -357,13 +367,7 @@ def searchban(screen_name): ...@@ -357,13 +367,7 @@ def searchban(screen_name):
#print("ban" in returnjson["tests"]["ghost"]) #print("ban" in returnjson["tests"]["ghost"])
#print(returnjson["tests"]["ghost"]) #print(returnjson["tests"]["ghost"])
# No search ban => No ghost ban
if returnjson["tests"]["search"] and returnjson["tests"]["search"] != "_error" and "ban" in returnjson["tests"]["ghost"] and returnjson["tests"]["ghost"]["ban"] == True:
returnjson["tests"]["ghost"]["ban"] = False
# No ghost ban && unknown more replies => No more replies ban
if "ban" not in returnjson["tests"]["more_replies"] and "ban" in returnjson["tests"]["ghost"] and returnjson["tests"]["ghost"]["ban"] == False:
returnjson["tests"]["more_replies"] = {"ban": False}
print("Result of {}: {}".format(screen_name, json.dumps(returnjson))) print("Result of {}: {}".format(screen_name, json.dumps(returnjson)))
return returnjson return returnjson
......
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