forked from Arctem/arcbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinks_n_shit.py
More file actions
84 lines (69 loc) · 2.53 KB
/
Copy pathlinks_n_shit.py
File metadata and controls
84 lines (69 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#-*- coding: utf-8 -*-
import requests
import random
base = r'https://www.reddit.com/'
title_list = ['I don\'t know how I feel about carjackers.',
'I can\'t believe how tall giraffes really are!',
'Do you have Die Hard™ on Blu-Ray?',
'Just give me two big ones, please.']
def login():
username = 'arcbot'
password = open('arc_pass.txt', 'r').read().strip()
payload = {'api_type' : 'json', 'passwd' : password, 'user' : username}
headers = {'user-agent': 'posting script for /u/arctem\'s /u/arcbot'}
client = requests.session()
client.headers = headers
r = client.post(base + r'api/login', data=payload)
j = r.json()
client.modhash = j['json']['data']['modhash']
print('Logged in as {}.'.format(username))
return client
def choose_link():
links = open('links.botdat', 'r').read().split('\n')
already_used = open('used_links.botdat', 'r').read().split('\n')
while True:
chosen = random.choice(links)
if chosen not in already_used:
break
already_used.append(chosen)
open('used_links.botdat', 'w').write('\n'.join(already_used).strip())
return chosen
def submit(link, client, subreddit='WordsNShit'):
captcha = validate_captcha(client)
if captcha:
captcha, iden = captcha
title = random.choice(title_list)
payload = {'api_type' : 'json', 'kind' : 'link', 'sendreplies' : True,
'sr' : subreddit, 'title' : title, 'uh' : client.modhash,
'url' : link}
if captcha:
payload['captcha'], payload['iden'] = captcha, iden
r = client.post(base + r'api/submit', data=payload)
j = r.json()
print(j)
for error in j['json']['errors']:
if error[0] == 'ALREADY_SUB':
return False
return True
def validate_captcha(client):
r = client.get(base + r'api/needs_captcha.json')
if r.text == 'true':
r = client.post(base + r'api/new_captcha', data={'api_type' : 'json'})
iden = r.json()['json']['data']['iden']
r = client.get(base + r'captcha/{}'.format(iden))
with open('captcha.png', 'wb') as f:
for chunk in r.iter_content():
f.write(chunk)
return input('answer for captcha in captcha.png? '), iden
else:
return False
def main():
client = login()
while True:
link = choose_link()
print(link)
if submit(link, client):
#quit if successfully submitted
break
if __name__ == '__main__':
main()