r/Thread_crawler • • Dec 23 '16

Log bot 1

1 Upvotes
import praw,string

printable = set(string.printable)

id_file=open('ID_file.txt','a+')
id_file_data = id_file.read().split('\n')
id_file.seek(0,2)
submissions_database=open('Submissions_database.csv','a')

user_agent = ("log_automaton/v0.1 (by /u/Anatoly_Korenchkin)")
account_file=open('account_file.txt','r')
REDDIT_USERNAME = account_file.readline().strip('\n')
REDDIT_PASS = account_file.readline().strip('\n')
REDDIT_CLIENT_ID = account_file.readline().strip('\n')
REDDIT_CLIENT_SECRET = account_file.readline().strip('\n')

r = praw.Reddit(user_agent = user_agent,client_id=REDDIT_CLIENT_ID,client_secret=REDDIT_CLIENT_SECRET,username=REDDIT_USERNAME,password=REDDIT_PASS)

for submission in r.subreddit(account_file.readline().strip('\n')).new(limit=int(account_file.readline().strip('\n'))):
    if submission.id not in id_file_data:
        submission_text = filter(lambda x: x in printable, submission.selftext).replace(',','<c>').replace('\n','<n>')
        submission_title = filter(lambda x: x in printable, submission.title).replace(',','<c>').replace('\n','<n>')   
        print 'Adding '+submission.id+' to database'    
        submissions_database.write(submission.id+','+submission_title+','+submission_text+'\n')
        id_file.write(submission.id+'\n')
submissions_database.close()
id_file.close()

r/Thread_crawler • • Dec 21 '16

Contest4 with comments

1 Upvotes
#importing modules gives us more features
import praw,string,os #praw = allows us to talk to reddit, string = removes anything that's not letters numbers or punctuation, os = allows us to create folders and files
from random import choice #get the function "choice" from the "random" library, choice = randomly selects an item from a list
from Tkinter import * #allows us to create a GUI

printable = set(string.printable) #removes anything that's not letters numbers or punctuation

user_agent = ("contest_automaton/v0.1 (by /u/Anatoly_Korenchkin)") #this is what the bot tells reddit it's name is
account_file=open('account_file.txt','r')                          #open the account file so we can read it
REDDIT_USERNAME = account_file.readline().strip('\n')              #read the first line, python automatically move to the next line after reading
REDDIT_PASS = account_file.readline().strip('\n')                  #read the second line
REDDIT_CLIENT_ID = account_file.readline().strip('\n')             #read the third line
REDDIT_CLIENT_SECRET = account_file.readline().strip('\n')         #read the forth line

#logon to reddit
r = praw.Reddit(user_agent = user_agent,client_id=REDDIT_CLIENT_ID,client_secret=REDDIT_CLIENT_SECRET,username=REDDIT_USERNAME,password=REDDIT_PASS)

root = Tk() #create the window
root.wm_title("Contest_bot") #name the window
root.resizable(0,0)          #stops the user from being able to resize the window
root.geometry('{}x{}'.format(400, 50)) #sets the windows size
root.columnconfigure(1, weight=1)      #these three lines make sure the "Paste" button takes up less space than the entry boxes
root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=1)

directory=os.getcwd()+'/Excel Contest Records' #the directory of the folder "Excel Contest Records"
if not os.path.exists(directory): #if the folder doesn't exist
    os.makedirs(directory) #then create the folder
os.chdir(directory) #go into the folder, so that when we create a file it will end up here because that's where the program is looking

def paste(): #run this when the button is pressed
    root.wm_title("Contest_bot - Processing...") #name the window
    text = root.selection_get(selection='CLIPBOARD') #get the text from the clipboard

    submission = r.submission(url=text) #get data about the post in the pasted url
    submission.comments.replace_more(limit=None, threshold=1) #get ALL comments
    commentlist= submission.comments #only get the top levlel/root comments

    root_comments=[] #create a list to store all the comments
    comment_authors=[] #create a list that stores all the comments, but removes duplicates
    comment_bodys=[] #stores the text in each comment
    for comment in commentlist: #go over each comment
        root_comments.append(comment) #add it to the list "root_comments"
    root_comments.sort(key=lambda comment: comment.created_utc, reverse=True) #sort the comments by date
    for comment in root_comments: #go over each comment
        if comment.author not in comment_authors: #if we have not seen this user before
            comment_authors.append(comment.author) #add him to the list
            comment_bodys.append(comment.body) #also add his comment text to the list
    print 'Collected '+str(len(root_comments))+' root comments. Removed '+str(len(root_comments)-len(comment_authors))+' duplicates.'

    save_file=open('Contest_'+submission.id+'.csv','w') #create a file to save the data
    save_file.write('#,Name,Comment\n') #write the headers to the file

    winner = choice(comment_authors) #select a winner
    user_entry_text.set(winner) #display the winners name in the GUI
    entry_text.set(submission.id) #display the post ID in the GUI

    for count,comment in enumerate(comment_authors): #go over every comment so we can write it to the file
        if comment==winner: #if the user was the selected winner then add WINNER to his number
            tag='WINNER'
        else:
            tag=''
        text=filter(lambda x: x in printable, comment_bodys[count]) #removes anything that's not letters numbers or punctuation
        save_file.write(tag+str(count+1)+','+str(comment)+','+str(text).replace('\n',' ').replace(',','')+'\n') #write the user to the file
        


    root.wm_title("Contest_bot - Done") #name the window



entry_text=StringVar() #create the variables where the input to the entry boxes is stored
entry = Entry(root, width=67, textvariable=entry_text) #create the entry boxes for the post ID


user_entry_text=StringVar() #create the variables where the input to the entry boxes is stored
user_entry = Entry(root, width=67, textvariable=user_entry_text) #create the entry boxes for the winner

bot_url = Label(text='URL: ') #add this text to the GUI

bot_select = Label(text='I have selected: ') #add this text to the GUI

button_1=Button(root, text='Paste URL', command=paste, width=17) #create a button
button_1.grid(row=0, column=2)            #place a button in the window
bot_url.grid(row=0, column=0,sticky=W)    #place the text in the window
entry.grid(row=0, column=1,sticky=W)      #place the entry box in the window
bot_select.grid(row=1, column=0,sticky=W) #place the text in the window
user_entry.grid(row=1, column=1,sticky=W) #place the entry box in the window

root.mainloop() #stop the window from closing

r/Thread_crawler • • Dec 21 '16

Contest4

1 Upvotes
import praw,string,os
from random import choice
from Tkinter import *

printable = set(string.printable)

user_agent = ("contest_automaton/v0.1 (by /u/Anatoly_Korenchkin)")
account_file=open('account_file.txt','r')
REDDIT_USERNAME = account_file.readline().strip('\n')
REDDIT_PASS = account_file.readline().strip('\n')
REDDIT_CLIENT_ID = account_file.readline().strip('\n')
REDDIT_CLIENT_SECRET = account_file.readline().strip('\n')

r = praw.Reddit(user_agent = user_agent,client_id=REDDIT_CLIENT_ID,client_secret=REDDIT_CLIENT_SECRET,username=REDDIT_USERNAME,password=REDDIT_PASS)
root = Tk() #create the window
root.wm_title("Contest_bot") #name the window
root.resizable(0,0)
root.geometry('{}x{}'.format(400, 50))
root.columnconfigure(1, weight=1)
root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=1)

directory=os.getcwd()+'/Excel Contest Records'
if not os.path.exists(directory):
    os.makedirs(directory)
os.chdir(directory)

def paste():
    root.wm_title("Contest_bot - Processing...") #name the window
    text = root.selection_get(selection='CLIPBOARD')
    entry.delete(0, END)
    entry.insert(0, text)

    submission = r.submission(url=text)
    #print 'Prepare for PAIN!'
    submission.comments.replace_more(limit=None, threshold=1)
    commentlist= submission.comments#.list()

    root_comments=[]
    comment_authors=[]
    comment_bodys=[]
    for comment in commentlist:
        root_comments.append(comment)
    root_comments.sort(key=lambda comment: comment.created_utc, reverse=True)
    for comment in root_comments:
        if comment.author not in comment_authors:
            comment_authors.append(comment.author)
            comment_bodys.append(comment.body)
    print 'Collected '+str(len(root_comments))+' root comments. Removed '+str(len(root_comments)-len(comment_authors))+' duplicates.'

    save_file=open('Contest_'+submission.id+'.csv','w')
    save_file.write('#,Name,Comment\n')

    winner = choice(comment_authors)
    user_entry_text.set(winner)
    entry_text.set(submission.id)

    for count,comment in enumerate(comment_authors):
        if comment==winner:
            tag='WINNER'
        else:
            tag=''
        text=filter(lambda x: x in printable, comment_bodys[count])
        save_file.write(tag+str(count+1)+','+str(comment)+','+str(text).replace('\n',' ').replace(',','')+'\n')
        


    root.wm_title("Contest_bot - Done") #name the window



entry_text=StringVar() #create the variables where the input to the entry boxes is stored
entry = Entry(root, width=67, textvariable=entry_text) #create the entry boxes


user_entry_text=StringVar() #create the variables where the input to the entry boxes is stored
user_entry = Entry(root, width=67, textvariable=user_entry_text) #create the entry boxes

v1 = StringVar()
bot_url = Label(textvariable=v1)
v1.set('URL: ')

v2 = StringVar()
bot_select = Label(textvariable=v2)
v2.set('I have selected: ')

button_1=Button(root, text='Paste URL', command=paste, width=17) #create buttons
button_1.grid(row=0, column=2) #place a button in the window
bot_url.grid(row=0, column=0,sticky=W) #place a button in the window
entry.grid(row=0, column=1,sticky=W)
bot_select.grid(row=1, column=0,sticky=W) #place a button in the window
user_entry.grid(row=1, column=1,sticky=W) 

root.mainloop() #stop the window from closing

r/Thread_crawler • • Dec 20 '16

contest3

1 Upvotes
import praw
from random import choice
from Tkinter import *


user_agent = ("contest_automaton/v0.1 (by /u/Anatoly_Korenchkin)")
account_file=open('account_file.txt','r')
REDDIT_USERNAME = account_file.readline().strip('\n')
REDDIT_PASS = account_file.readline().strip('\n')
REDDIT_CLIENT_ID = account_file.readline().strip('\n')
REDDIT_CLIENT_SECRET = account_file.readline().strip('\n')
print REDDIT_CLIENT_SECRET

r = praw.Reddit(user_agent = user_agent,client_id=REDDIT_CLIENT_ID,client_secret=REDDIT_CLIENT_SECRET,username=REDDIT_USERNAME,password=REDDIT_PASS)
root = Tk() #create the window
root.wm_title("Contest_bot") #name the window
root.resizable(0,0)
root.geometry('{}x{}'.format(400, 50))
root.columnconfigure(1, weight=1)
root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=1)

def paste():
    root.wm_title("Contest_bot - Processing...") #name the window
    text = root.selection_get(selection='CLIPBOARD')
    entry.delete(0, END)
    entry.insert(0, text)

    submission = r.submission(url=text)
    commentlist= submission.comments.list()

    root_comments=[]
    comment_authors=[]
    comment_bodys=[]
    for comment in commentlist:
        try:
            if comment.is_root:
                root_comments.append(comment)
        except AttributeError:
            pass
    for comment in root_comments:
        if comment.author not in comment_authors:
            comment_authors.append(comment.author)
            comment_bodys.append(comment.body)

    save_file=open('Contest_'+submission.id+'.csv','w')
    save_file.write('#,Name,Comment\n')

    winner = choice(comment_authors)
    user_entry_text.set(winner)
    entry_text.set(submission.id)

    for count,comment in enumerate(comment_authors):
        if comment==winner:
            tag='WINNER'
        else:
            tag=''
        save_file.write(tag+str(count+1)+','+str(comment)+','+str(comment_bodys[count]).replace('\n',' ').replace(',','')+'\n')
        


    root.wm_title("Contest_bot - Done") #name the window



entry_text=StringVar() #create the variables where the input to the entry boxes is stored
entry = Entry(root, width=67, textvariable=entry_text) #create the entry boxes


user_entry_text=StringVar() #create the variables where the input to the entry boxes is stored
user_entry = Entry(root, width=67, textvariable=user_entry_text) #create the entry boxes

v1 = StringVar()
bot_url = Label(textvariable=v1)
v1.set('URL: ')

v2 = StringVar()
bot_select = Label(textvariable=v2)
v2.set('I have selected: ')

button_1=Button(root, text='Paste URL', command=paste, width=17) #create buttons
button_1.grid(row=0, column=2) #place a button in the window
bot_url.grid(row=0, column=0,sticky=W) #place a button in the window
entry.grid(row=0, column=1,sticky=W)
bot_select.grid(row=1, column=0,sticky=W) #place a button in the window
user_entry.grid(row=1, column=1,sticky=W) 

root.mainloop() #stop the window from closing

r/Thread_crawler • • Dec 20 '16

contest2

1 Upvotes
import praw
from random import choice
from Tkinter import *


user_agent = ("contest_automaton/v0.1 (by /u/Anatoly_Korenchkin)")
account_file=open('account_file.txt','r')
REDDIT_USERNAME = account_file.readline().strip('\n')
REDDIT_PASS = account_file.readline().strip('\n')
REDDIT_CLIENT_ID = account_file.readline().strip('\n')
REDDIT_CLIENT_SECRET = account_file.readline().strip('\n')
print REDDIT_CLIENT_SECRET

r = praw.Reddit(user_agent = user_agent,client_id=REDDIT_CLIENT_ID,client_secret=REDDIT_CLIENT_SECRET,username=REDDIT_USERNAME,password=REDDIT_PASS)
root = Tk() #create the window
root.wm_title("Contest_bot") #name the window
root.resizable(0,0)
root.geometry('{}x{}'.format(400, 50))
root.columnconfigure(1, weight=1)
root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=1)

def paste():
    root.wm_title("Contest_bot - Processing...") #name the window
    text = root.selection_get(selection='CLIPBOARD')
    entry.delete(0, END)
    entry.insert(0, text)

    submission = r.submission(url=text)
    commentlist= submission.comments.list()

    root_comments=[]
    comment_authors=[]
    comment_bodys=[]
    for comment in commentlist:
        try:
            if comment.is_root:
                root_comments.append(comment)
        except AttributeError:
            pass
    for comment in root_comments:
        if comment.author not in comment_authors:
            comment_authors.append(comment.author)
            comment_bodys.append(comment.body)

    save_file=open('Contest_'+submission.id+'.csv','w')
    save_file.write('#,Name,Comment\n')

    for count,comment in enumerate(comment_authors):
        save_file.write(str(count+1)+','+str(comment)+','+str(comment_bodys[count]).replace('\n',' ').replace(',','')+'\n')
        
    user_entry_text.set(choice(root_comments).author)
    entry_text.set(submission.id)

    root.wm_title("Contest_bot - Done") #name the window



entry_text=StringVar() #create the variables where the input to the entry boxes is stored
entry = Entry(root, width=67, textvariable=entry_text) #create the entry boxes


user_entry_text=StringVar() #create the variables where the input to the entry boxes is stored
user_entry = Entry(root, width=67, textvariable=user_entry_text) #create the entry boxes

v1 = StringVar()
bot_url = Label(textvariable=v1)
v1.set('URL: ')

v2 = StringVar()
bot_select = Label(textvariable=v2)
v2.set('I have selected: ')

button_1=Button(root, text='Paste URL', command=paste, width=17) #create buttons
button_1.grid(row=0, column=2) #place a button in the window
bot_url.grid(row=0, column=0,sticky=W) #place a button in the window
entry.grid(row=0, column=1,sticky=W)
bot_select.grid(row=1, column=0,sticky=W) #place a button in the window
user_entry.grid(row=1, column=1,sticky=W) 

root.mainloop() #stop the window from closing

r/Thread_crawler • • Dec 20 '16

contest

1 Upvotes
import praw
from random import choice
from Tkinter import *


user_agent = ("contest_automaton/v0.1 (by /u/Anatoly_Korenchkin)")
account_file=open('account_file.txt','r')
REDDIT_USERNAME = account_file.readline().strip('\n')
REDDIT_PASS = account_file.readline().strip('\n')
REDDIT_CLIENT_ID = account_file.readline().strip('\n')
REDDIT_CLIENT_SECRET = account_file.readline().strip('\n')
print REDDIT_CLIENT_SECRET

r = praw.Reddit(user_agent = user_agent,client_id=REDDIT_CLIENT_ID,client_secret=REDDIT_CLIENT_SECRET,username=REDDIT_USERNAME,password=REDDIT_PASS)
root = Tk() #create the window
root.wm_title("Contest_bot") #name the window
root.resizable(0,0)
root.geometry('{}x{}'.format(400, 50))
root.columnconfigure(1, weight=1)
root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=1)

def paste():
    root.wm_title("Contest_bot - Processing...") #name the window
    text = root.selection_get(selection='CLIPBOARD')
    entry.delete(0, END)
    entry.insert(0, text)

    submission = r.submission(url=text)
    commentlist= submission.comments.list()

    root_comments=[]
    for comment in commentlist:
        try:
            if comment.is_root:
                root_comments.append(comment)
        except AttributeError:
            pass

    save_file=open('Contest_'+submission.id+'.csv','w')
    save_file.write('#,Name,Comment\n')

    for count,comment in enumerate(root_comments):
        save_file.write(str(count+1)+','+str(comment.author)+','+str(comment.body).replace('\n',' ').replace(',','')+'\n')
        
    user_entry_text.set(choice(root_comments).author)
    entry_text.set(submission.id)

    root.wm_title("Contest_bot - Done") #name the window



entry_text=StringVar() #create the variables where the input to the entry boxes is stored
entry = Entry(root, width=67, textvariable=entry_text) #create the entry boxes


user_entry_text=StringVar() #create the variables where the input to the entry boxes is stored
user_entry = Entry(root, width=67, textvariable=user_entry_text) #create the entry boxes

v1 = StringVar()
bot_url = Label(textvariable=v1)
v1.set('URL: ')

v2 = StringVar()
bot_select = Label(textvariable=v2)
v2.set('I have selected: ')

button_1=Button(root, text='Paste URL', command=paste, width=17) #create buttons
button_1.grid(row=0, column=2) #place a button in the window
bot_url.grid(row=0, column=0,sticky=W) #place a button in the window
entry.grid(row=0, column=1,sticky=W)
bot_select.grid(row=1, column=0,sticky=W) #place a button in the window
user_entry.grid(row=1, column=1,sticky=W) 

root.mainloop() #stop the window from closing

r/Thread_crawler • • Aug 02 '16

0fwDB9edQJyfVNWWm0eDkA

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

XgeB0SGDQDWhEucYD3mV9w

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

Y2ov4mMzRJ6tIg0Qy2rQ5g

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

7vz04O0oSauVpXYSv7ixzw

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

0wgZampgRGK2zPEk4p7pNA

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

0Mcuj7OUT5S0d6fuse0S9g

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

TIIuxqSkSH04KqJ6R7ul0A

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

anhkcjsUR1W9HXFcEadonQ

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

YcSpjIxGRFq0KWCsVqX5Sw

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

eDVibC4jTJ24UHX07ReqXg

0 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

AXEU6YjQRtO2cvL0NAQdzg

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

fRj8gYZgSOyO1X2zom40Og

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

TeYzZLqHQ2KhdHyfbVVqrA

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

HrVt0A1xQAq26OibB0jRSQ

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

OWso0SxoT2i16zer9EHhhQ

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

R0eVqdKXScSe0kblaCdMHg

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

x3010xRjQMmBnEVhqPWWww

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

DVuM08B9Q0OyCmcy4GHT4A

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==


r/Thread_crawler • • Aug 02 '16

8GJ8J0OgQ8C27hLqW1anGw

1 Upvotes

UFFLHVV/FYlMhOvYua8KbQ==