-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
71 lines (55 loc) · 1.93 KB
/
bot.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# coding: utf-8
import twitter
from collections import defaultdict
import pdb
import time
import random
from lxml import etree
from StringIO import StringIO
import urllib2
from hentai_secret import *
def get_booru():
req = urllib2.Request('http://gelbooru.com/index.php?page=dapi&s=comment&q=index')
anime = urllib2.urlopen(req).read()
context = etree.iterparse(StringIO((anime)))
for action, elem in context:
if random.randint(1, 10) == 1:
words = elem.get('body').split(' ')
choice = ' '.join(random.sample(words, random.randint(1, 3)))
return choice
def replace_booru(string, inserting):
string = string.split(' ')
inserting = inserting.split(' ')
top = len(string) - len(inserting)
if top < 1:
return ' '.join(string)
index = random.randint(0, top)
i = 0
for item in inserting:
string[index + i] = item
i += 1
return ' '.join(string)
if __name__ == "__main__":
api = twitter.Api(consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET, access_token_key=ACCESS_TOKEN_KEY, access_token_secret=ACCESS_TOKEN_SECRET)
statuses = []
for i in range(1, 20):
next_statuses = api.GetUserTimeline(screen_name='hentaiphd', page=i, count=200)
for s in next_statuses:
statuses.append(s)
store = defaultdict(list)
for s in statuses:
words = s.text.split(' ')
for word in words:
if words.index(word) < len(words) - 1:
index = words.index(word) + 1
store[word].append(words[index])
while True:
word = random.choice(store.keys())
status = word
while len(status) < 50 and store[word]:
word = random.choice(store[word])
status += " %s" % (word,)
status = replace_booru(status, get_booru())
status = status.replace('@', '')
api.PostUpdate(status)
time.sleep(5*60)