forked from douglasgibb/twitter-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
t.py
executable file
·89 lines (82 loc) · 2 KB
/
t.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /usr/env/python
import subprocess
import feedparser
import urllib
import re
import cStringIO
import os
import time
feed = "https://twitter.com/search?f=tweets&vertical=default&q=deutsch%20volk&src=typd"
database = []
sendnow = []
def start():
global sendnow
print "[+] Sending Tweets"
for name in sendnow:
befehl = "./tweet.sh " + name
print name
p = subprocess.Popen(befehl, shell=True, bufsize=0, stdout=subprocess.PIPE)
p.wait()
def scrape():
global database
print "[+] Reading feed"
response = urllib.urlopen(feed)
html = response.read()
#data-screen-name="!!!!! " data-name="
suchlist = []
mup = cStringIO.StringIO(html)
length = len(mup.read())
print "[+] Handling data"
while length != 0:
mup.seek(length)
map = mup.readline()
suchlist.append(map)
length = length - 1
print "[+] Searching usernames"
start = "data-screen-name=\""
end = "\" data-name=\""
for line in suchlist:
if re.search(start, line):
if re.search(end, line):
user = (line.split(start))[1].split(end)[0]
user = user + "\n"
if user not in database:
database.append(user)
puttofile()
def puttofile():
global database
global sendnow
send = []
print "[+] Syncing with database"
if not os.path.exists('database.txt'):
open('database.txt', 'w').close()
f = open("database.txt", "r+a")
stuff = f.readlines()
lol = stuff
if len(stuff) == 0:
stuff = stuff + database
send = database
else:
#for element in range(len(database)):
#database[element] = database[element] + "\n"
if lol[-1].find("\n") == -1:
lol[-1] = lol[-1] + "\n"
sim = list(set(database) - set(lol))
for all in sim:
send.append(all)
send = map(str.strip, send)
sendnow = send
send = "\n".join(send)
f.write(send + "\n")
f.close()
print send
start()
def loop():
while(1 == 1):
scrape()
wait = 300 # seconds how long the bot will wait until the next cr4wl
print "[+] Waiting for " + str(wait/60) + " minutes."
print
time.sleep(wait)
loop()
# start()