Created
July 28, 2018 23:26
-
-
Save Abrownn/9895973c2229295da321f59f15fb4cc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Aged Account Checker -- made by /u/Abrownn | |
import praw | |
import time | |
import AccountCheckerLogin | |
def postInvestigate(r, redditor): #Start post analysis | |
postList = [] | |
submissionPrelimList = [] | |
gap = 0 | |
minPostCheck = 0 | |
age = int(redditor.created_utc) | |
try: | |
for post in redditor.submissions.new(limit=2): #Min post check to see if this can be used as a measure of activity | |
latestPost = int(post.created) | |
latestPostID = str(post.id) | |
submissionPrelimList.append(latestPost) | |
minPostCheck += 1 | |
except: | |
pass | |
if minPostCheck == 0: #no posts, skipping to comment analysis | |
submissionStatus = 0 | |
submissionGapDays = 0 | |
return submissionStatus, submissionGapDays | |
elif minPostCheck == 1: #One post only, not enough to run post analysis -- gap between only post and account creation date | |
submissionStatus = 1 | |
submissionGapDays = int((int(submissionPrelimList[0]) - age)/86400) | |
return submissionStatus, submissionGapDays | |
else: | |
for post in redditor.submissions.new(limit=1): #establishing their first post (can't be merged because prevpost's value has to change at the end of the next loop, ) | |
prevPost = int(post.created) | |
prevPostID = str(post.id) | |
for post in redditor.submissions.new(limit=100): | |
currentPost = int(post.created) | |
currentPostID = str(post.id) | |
postList.append(currentPostID) | |
diff = prevPost - currentPost | |
if diff > gap: | |
preGap = str(currentPostID) | |
postGap = str(prevPostID) | |
gap = diff | |
prevPost = currentPost | |
prevPostID = currentPostID | |
preGapDate = r.submission(id = preGap).created | |
postGapDate = r.submission(id = postGap).created | |
firstPost= str(postList[-1]) | |
firstPostDate = int(r.submission(id = firstPost).created) | |
if len(postList) >= 99: | |
submissionReverseCheck = 0 #established account, no point in checking for first post age beyond 100 posts | |
else: | |
submissionReverseCheck = firstPostDate - age #How soon after the account made was the very first post | |
if submissionReverseCheck > gap: | |
submissionStatus = 2 | |
submissionGapDays = int(submissionReverseCheck/86400) #bigger gap between creation and first post than any previously identified regular post gap | |
else: | |
submissionStatus = 3 | |
submissionGapDays = int(int((postGapDate- preGapDate)/86400)) | |
return submissionStatus, submissionGapDays | |
def commentInvestigate(r, redditor): #Start comment analysis | |
commentList = [] | |
commentPrelimList = [] | |
gap = 0 | |
minCommentCheck = 0 | |
age = int(redditor.created_utc) | |
try: | |
for comment in redditor.comments.new(limit=2): #Min comment check to see if this can be used as a measure of activity | |
latestComment = int(comment.created) | |
latestCommentID = str(comment.id) | |
commentPrelimList.append(latestComment) | |
minCommentCheck += 1 | |
except: | |
pass | |
if minCommentCheck == 0: #no comments, can't be used as a measure of activity | |
commentStatus = 0 | |
commentGapDays = 0 | |
return commentStatus, commentGapDays | |
elif minCommentCheck == 1: #One comment only, not enough to run comment analysis, returning date of only comment | |
commentStatus = 1 | |
commentGapDays = int((int(commentPrelimList[0]) - age)/86400) | |
return commentStatus, commentGapDays | |
else: | |
for comment in redditor.comments.new(limit=1): #establishing their first post (can't be merged because prevpost's value has to change at the end of the next loop, ) | |
try: | |
prevComment = int(comment.created) | |
prevCommentID = str(comment.id) | |
except: | |
pass | |
for comment in redditor.comments.new(limit=100): | |
try: | |
currentComment = int(comment.created) | |
currentCommentID = str(comment.id) | |
commentList.append(currentCommentID) | |
diff = int(prevComment) - int(currentComment) | |
if diff > gap: | |
preGap = str(currentCommentID) | |
postGap = str(prevCommentID) | |
gap = diff | |
prevComment = currentComment | |
prevCommentID = currentCommentID | |
except: | |
continue | |
preGapDate = r.comment(id = preGap).created | |
postGapDate = r.comment(id = postGap).created | |
firstComment = str(commentList[-1]) | |
firstCommentDate = int(r.comment(id = firstComment).created) | |
if len(commentList) >= 99: #CHECK IF THEY HAVE AN EXTENSIVE HISTORY, FEEDS INTO ACCOUNT TYPE CHECKING BELOW | |
commentReverseCheck = 0 | |
else: | |
commentReverseCheck = firstCommentDate - age | |
if commentReverseCheck > gap: #LOGICAL CHECK TO FIGURE OUT WHHAT KIND OF ACCOUNT THEY ARE | |
commentStatus = 2 | |
commentGapDays = int(commentReverseCheck/86400) #days from account creation 'til first post. | |
else: | |
commentStatus = 3 | |
commentGapDays = int(int((postGapDate - preGapDate)/86400)) | |
return commentStatus, commentGapDays | |
def gapAnalyze(submissionStatus, submissionGapDays, commentStatus, commentGapDays): | |
#--- Tying them together/comparing -- cant be done in the respective functions, *MUST* be compared before acting!!! | |
print("Comment status: " + str(commentStatus) + " - comment gap days: " + str(commentGapDays)) | |
print("Post status : " + str(submissionStatus) + " - post gap days: " + str(submissionGapDays)) | |
if commentGapDays < submissionGapDays: | |
gap = commentGapDays | |
status = commentStatus | |
print("Bigger gap in comments: " + str(gap) + " - status: " + str(status)) | |
else: | |
gap = submissionGapDays | |
status = submissionStatus | |
print("Bigger gap in submissions: " + str(gap) + " - status: " + str(status)) | |
if status == 0: #defer to comment analysis or return False | |
action = False | |
return action, gap | |
elif status == 1: #One comment/post made after a massive gap (account manually created or nuked, went to sleep, woke up then posted -- set to 3 month gap min) | |
if gap > 90: #If True, remove post for review -- consider returning reverseCheck's gap value to use in custom report reasons | |
action = True #remove | |
return action, gap | |
else: | |
action = False | |
return action, gap | |
elif status == 2: #bigger gap between creation and first comment/post than any previously identified regular post gap | |
if gap > 90: | |
action = True | |
return action, gap | |
else: | |
action = False | |
return action, gap | |
elif status == 3: #established account w/ maxed comment/post count | |
if gap > 90: | |
action = True #If true, a 3+ month gap was found within the last 100 comments/posts and will be removed | |
return action, gap | |
else: | |
action = False | |
return action, gap | |
def main(): | |
r = praw.Reddit(username = "", | |
password = "", | |
client_id = "", | |
client_secret = "", | |
user_agent = "local single-sub deep investigation script to find hacked/stolen accounts") | |
nameList = [] | |
for post in r.subreddit("SUBREDDIT").new(limit=1000): | |
redditor = r.redditor(str(post.author)) | |
submissionStatus, submissionGapDays = postInvestigate(r, redditor) | |
commentStatus, commentGapDays = commentInvestigate(r, redditor) | |
action, gap = gapAnalyze(submissionStatus, submissionGapDays, commentStatus, commentGapDays) | |
# print("ANALYSIS FOR /u/" + str(post.author) + " COMPLETE -- Status code: " + str(status) + " - Action: " + str(action)) #uncomment for terminal output of action | |
if action == True: | |
with open ("NAMEDUMP.txt", 'a') as nameWrite: | |
nameWrite.write("/u/" + str(redditor) + " - Gap: " + str(gap) + "\n\n") | |
else: | |
time.sleep(1) | |
continue | |
exit() | |
while True: | |
try: | |
print("logged in, working") | |
main() | |
except Exception as e: | |
print("Error: " + str(e)) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment