8
8
import os
9
9
import random
10
10
11
- USERNAME = '' #add in login details for bot..
12
- PASSWORD = ''
11
+ PASSWORD = 'password' #the password for the throwaway accounts..
13
12
14
- downvoters = [] #usernames to downvote and upvote..
15
- upvoters = []
13
+
14
+ accounts = ['random_throwaway1' , 'random_throwaway2' , 'etc' ]
15
+ downvoters = ['some' ,'user' ,'to' ,'downvote' ]
16
+ upvoters = ['some' ,'user' ,'to' ,'upvote' ]
16
17
17
18
n_upvotes = 0
18
19
n_downvotes = 0
19
20
20
21
already_comment_id = []
21
22
23
+ def r_login ():
24
+ while True :
25
+ try :
26
+ attempt = accounts [random .randint (0 ,len (accounts )- 1 )]
27
+ print 'attempt login with account:' , attempt
28
+ r .login (attempt , PASSWORD , disable_warning = True )
29
+ log (time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' login success: ' + attempt + '\n ' )
30
+ return
31
+ except praw .errors .InvalidUserPass as e :
32
+ print 'login failed - praw.errors.InvalidUserPass' , attempt
33
+ log (time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' ' + str (type (e ))+ attempt + '\n ' )
34
+ accounts .remove (attempt )
35
+ time .sleep (15 )
36
+ continue
37
+ except Exception as e :
38
+ print 'login failed' , type (e ), e .args , e
39
+ quickstart .ErrorSendEmail ()
40
+ exit ()
41
+
42
+
43
+
22
44
def log_work ():
23
45
global n_upvotes , n_downvotes
24
46
print "Emailing 24 hourly log file.."
25
47
print 'Upvotes ' ,str (n_upvotes ),' Downvotes ' , str (n_downvotes )
26
48
quickstart .CredsSendLog (n_upvotes , n_downvotes )
27
- os .rename ('log.txt' ,'log.old' + str (random .randint (0 ,65535 )))
49
+ os .rename ('./ log/log .txt' ,'./ log/log .old' + str (random .randint (0 ,6553500 )))
28
50
n_upvotes = 0
29
51
n_downvotes = 0
30
52
print "Saving old log file, creating new file.."
@@ -33,74 +55,81 @@ def log_work():
33
55
return
34
56
35
57
def log (string_data ):
36
- with open ("log.txt" , "a" ) as myfile :
58
+ with open ("./log/ log.txt" , "a" ) as myfile :
37
59
myfile .write (string_data )
38
60
return
39
61
40
62
41
- r = praw .Reddit (user_agent = 'Something random' ) #change this to a unique string..
42
63
43
- try :
44
- r .login (USERNAME , PASSWORD , disable_warning = True )
45
- except Exception as e :
46
- print 'login failure' , type (e ), e .args , e
47
- exit ()
64
+ r = praw .Reddit (user_agent = 'Some unique text not containing bot' )
65
+
66
+ r_login ()
48
67
49
- subreddit = r .get_subreddit ('test' ) #lazy so no need to exception raise .
68
+ subreddit = r .get_subreddit ('any subreddit you want' ) #lazy so no need to error check. .
50
69
51
70
print '>>>Reddit /r/bitcoin bot..<<<'
52
71
53
72
print 'Downvoting:' , downvoters
54
73
print 'Upvoting:' , upvoters
55
74
56
- print '>>>active - logging to /log.txt<<<'
75
+ print '>>>active - logging to ./log /log.txt<<<'
57
76
58
- schedule .every ().day .at ("07:00" ).do (log_work ) #scheduled log maintenance and emailing..
77
+ schedule .every ().day .at ("07:00" ).do (log_work )
59
78
schedule .every ().day .at ("19:00" ).do (log_work )
60
79
61
80
while True :
62
- try :
63
81
64
- subreddit_comments = subreddit .get_comments () #get the new comments..
82
+ try :
83
+ subreddit_comments = subreddit .get_comments ()
65
84
85
+ for comment in subreddit_comments :
66
86
67
- for comment in subreddit_comments : #make sure they havent been seen already..
68
-
69
- if comment .id in already_comment_id :
70
- pass
71
-
72
- else :
73
- already_comment_id .append (comment .id )
74
-
75
- chance = random .randint (1 ,4 ) #only vote manipulate 75% of time..
76
- if chance == 4 :
87
+ if comment .id in already_comment_id :
77
88
pass
78
-
79
- elif chance < 4 and comment .author .name in downvoters :
80
- print "downvoted: " , comment .author .name , comment .id
81
- comment .downvote ()
82
- n_downvotes += 1
83
- logstr = time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' downvoted ' + comment .author .name + ' ' + comment .id + '\n '
84
- log (logstr )
85
-
86
- elif chance < 4 and comment .author .name in upvoters :
87
- print 'match' , comment .author .name , comment .id
88
- logstr = time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' upvoted ' + comment .author .name + ' ' + comment .id + '\n '
89
- log (logstr )
90
- comment .upvote ()
91
- n_upvotes += 1
92
-
93
- sys .stdout .write ('.' )
94
- sys .stdout .flush ()
95
- schedule .run_pending ()
96
- time .sleep (random .randint (0 ,20 )) #randomly wait before scanning subreddit again..
97
-
89
+
90
+ else :
91
+ already_comment_id .append (comment .id )
92
+
93
+ if comment .author .name in downvoters :
94
+ #comment.reply('test')
95
+ print "downvoted: " , comment .author .name , comment .id
96
+ comment .downvote ()
97
+ n_downvotes += 1
98
+ logstr = time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' downvoted ' + comment .author .name + ' ' + comment .id + '\n '
99
+ log (logstr )
100
+
101
+
102
+ if comment .author .name in upvoters :
103
+ print 'match' , comment .author .name , comment .id
104
+ logstr = time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' upvoted ' + comment .author .name + ' ' + comment .id + '\n '
105
+ log (logstr )
106
+ comment .upvote ()
107
+ n_upvotes += 1
108
+
109
+
110
+ sys .stdout .write ('.' )
111
+ sys .stdout .flush ()
112
+ schedule .run_pending ()
113
+ time .sleep (random .randint (0 ,20 ))
114
+
115
+ except praw .errors .InvalidUserPass as e :
116
+ print 'login failed - praw.errors.InvalidUserPass'
117
+ log (time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' ' + str (type (e ))+ '\n ' )
118
+ time .sleep (15 )
119
+ r_login ()
120
+ continue
121
+ except praw .errors .LoginRequired as e :
122
+ print 'logged out - praw.errors.LoginRequired'
123
+ log (time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' ' + str (type (e ))+ '\n ' )
124
+ time .sleep (15 )
125
+ r_login ()
126
+ continue
98
127
except Exception as e :
99
128
print "Error" , type (e ), e .args , e
100
- log (" Error"+ type (e )+ e . args )
129
+ log (time . strftime ( "%Y-%m-%d %H:%M:%S" ) + " Error"+ str (e )+ " \n " )
101
130
time .sleep (20 )
102
131
continue
103
-
132
+
104
133
except KeyboardInterrupt :
105
134
print 'Exiting..upvotes: ' + str (n_upvotes ), ' downvotes: ' + str (n_downvotes )
106
135
log (time .strftime ("%Y-%m-%d %H:%M:%S" )+ ' manual shutdown CTRL-C..\n ' )
0 commit comments