-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathr34.py
49 lines (40 loc) · 1.08 KB
/
r34.py
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
# Aradiabot function for searching rule34.xxx
# As they don't have an API, this was easier to put in it's own file so I could organize everything.
import requests
from html.parser import HTMLParser
import random
import sys
counter = [10,9,8,7,6,5,4,3,2,1]
images = []
class booruparser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == 'a':
if any('id' in pairs for pairs in attrs):
try:
images.append(str(attrs[1][1]))
except:
pass
class imageparser(HTMLParser):
def handle_starttag(self, tag, attrs):
if ('id', 'image') in attrs:
print("http:" + attrs[2][1])
parser = booruparser()
imgparser = imageparser()
tags = ""
for arg in sys.argv:
if arg == sys.argv[0]:
pass
else:
tags = tags + arg + "+"
count = 0
while len(images) < 1:
if count < 10:
parser.feed(requests.get('http://rule34.xxx/index.php?page=post&s=list&tags=' + tags + '&pid=' + str(counter[count])).text)
count = count + 1
else:
break
if count != 10:
image = requests.get('http://rule34.xxx/' + random.choice(images)).text
imgparser.feed(image)
else:
print("0")