Merge branch 'master' of dl6tom.de:public/ticketfrei
This commit is contained in:
commit
2f3b3d27d4
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,6 @@
|
||||||
*.swp
|
*.swp
|
||||||
|
.idea/
|
||||||
|
last_rt
|
||||||
ticketfrei.cfg
|
ticketfrei.cfg
|
||||||
seen_toots.pickle
|
seen_toots.pickle
|
||||||
seen_toots.pickle.part
|
seen_toots.pickle.part
|
||||||
|
|
|
@ -35,15 +35,15 @@ $ pip3 install Mastodon.py pytoml
|
||||||
- [x] How to crawl mentions with the mastodon API
|
- [x] How to crawl mentions with the mastodon API
|
||||||
- [x] How to boost people with the mastodon API
|
- [x] How to boost people with the mastodon API
|
||||||
- [x] How to access the twitter API
|
- [x] How to access the twitter API
|
||||||
- [ ] How to crawl mentions with the twitter API
|
- [x] How to crawl mentions with the twitter API
|
||||||
- [ ] How to retweet people with the twitter API
|
- [x] How to retweet people with the twitter API
|
||||||
|
|
||||||
## to do
|
## to do
|
||||||
|
|
||||||
- [ ] Twitter: Crawl mentions
|
- [x] Twitter: Crawl mentions
|
||||||
- [ ] Mastodon: Crawl mentions
|
- [ ] Mastodon: Crawl mentions
|
||||||
- [ ] Write toots/tweets to database
|
- [ ] Write toots/tweets to database
|
||||||
- [ ] Twitter: retweet people
|
- [x] Twitter: retweet people
|
||||||
- [ ] Mastodon: boost people
|
- [ ] Mastodon: boost people
|
||||||
- [ ] Mastodon: toot who has been retweeted on twitter
|
- [ ] Mastodon: toot who has been retweeted on twitter
|
||||||
- [ ] Twitter: tweet who has been boosted on mastodon
|
- [ ] Twitter: tweet who has been boosted on mastodon
|
||||||
|
|
24
triggerwords
24
triggerwords
|
@ -0,0 +1,24 @@
|
||||||
|
kontrolle
|
||||||
|
ticketfrei
|
||||||
|
konti
|
||||||
|
db
|
||||||
|
zivil
|
||||||
|
sicherheit
|
||||||
|
uniform
|
||||||
|
station
|
||||||
|
bus
|
||||||
|
bahn
|
||||||
|
tram
|
||||||
|
linie
|
||||||
|
nuernberg
|
||||||
|
nbg
|
||||||
|
nürnberg
|
||||||
|
s1
|
||||||
|
s2
|
||||||
|
s3
|
||||||
|
u1
|
||||||
|
u2
|
||||||
|
u3
|
||||||
|
s4
|
||||||
|
u21
|
||||||
|
u11
|
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
__author__ = "b3yond"
|
__author__ = "b3yond"
|
||||||
|
|
||||||
import twitter
|
import twitter
|
||||||
|
import requests
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -9,10 +11,10 @@ How to get these keys is described in doc/twitter_api.md
|
||||||
|
|
||||||
After you received keys, store them in ../../api_keys, one at a line.
|
After you received keys, store them in ../../api_keys, one at a line.
|
||||||
"""
|
"""
|
||||||
with open("../../api_keys", "r") as file:
|
with open("../appkeys/ticketfrei@twitter.com", "r") as file:
|
||||||
keys = file.readlines()
|
keys = file.readlines()
|
||||||
for i in keys:
|
for status in keys:
|
||||||
print i,
|
print status,
|
||||||
|
|
||||||
|
|
||||||
# create an Api object
|
# create an Api object
|
||||||
|
@ -23,32 +25,61 @@ api = twitter.Api(consumer_key = keys[0].strip(),
|
||||||
|
|
||||||
|
|
||||||
# This counter is needed to keep track which was the last tweet you retweeted
|
# This counter is needed to keep track which was the last tweet you retweeted
|
||||||
last_rt = ""
|
# ACTUALLY it keeps track of the last mention, whether you retweeted it or not.
|
||||||
|
with open("../last_rt", "r+") as file:
|
||||||
|
last_rt = file.read()
|
||||||
|
|
||||||
|
|
||||||
# Words which have to be included into the tweets for the tweet to get retweeted
|
# Words which have to be included into the tweets for the tweet to get retweeted
|
||||||
with open("../triggerwords.txt", "r") as file:
|
with open("../triggerwords", "r") as file:
|
||||||
triggers = file.readlines()
|
triggers = [s.strip() for s in file.readlines()]
|
||||||
|
|
||||||
|
try:
|
||||||
|
while 1:
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
while 1:
|
# Store all mentions in a list of Status Objects
|
||||||
sleep(1)
|
done = False
|
||||||
|
while not done:
|
||||||
|
try:
|
||||||
|
mentions = api.GetMentions(since_id=last_rt)
|
||||||
|
done = True
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
print("[ERROR] Bad Connection.")
|
||||||
|
sleep(10)
|
||||||
|
|
||||||
# Store all mentions in a list of Status Objects
|
print mentions # debug
|
||||||
mentions = api.GetMentions(since_id=last_rt)
|
for status in mentions:
|
||||||
print mentions
|
|
||||||
for i in mentions:
|
|
||||||
print i.user.name, i.user.id, i.text # debug
|
|
||||||
|
|
||||||
# Is the Text of the Tweet in the triggerlist?
|
# Is the Text of the Tweet in the triggerlist?
|
||||||
for j in triggers:
|
should_retweet = False
|
||||||
if i.text.lower().find(j):
|
for triggerword in triggers:
|
||||||
|
if status.text.lower().find(triggerword):
|
||||||
|
should_retweet = True
|
||||||
|
break
|
||||||
|
|
||||||
# Retweet status, save the id so it doesn't get crawled again
|
# Retweet status
|
||||||
try:
|
if should_retweet:
|
||||||
feedback = api.PostRetweet(i.id)
|
done = False
|
||||||
print feedback
|
while not done:
|
||||||
except twitter.error.TwitterError:
|
try:
|
||||||
print("[ERROR] probably you already retweeted this tweet.")
|
api.PostRetweet(status.id)
|
||||||
last_rt = i.id
|
done = True
|
||||||
break
|
|
||||||
|
# This is an Error we need to get rid of. Why are tweets RTed twice?
|
||||||
|
# except twitter.error.TwitterError:
|
||||||
|
# print("[ERROR] probably you already retweeted this tweet.")
|
||||||
|
# done = True
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
print("[ERROR] Bad Connection.")
|
||||||
|
sleep(10)
|
||||||
|
|
||||||
|
# save the id so it doesn't get crawled again
|
||||||
|
last_rt = status.id
|
||||||
|
print last_rt
|
||||||
|
|
||||||
|
except:
|
||||||
|
print "[ERROR] Shit went wrong, closing down."
|
||||||
|
with open("../last_rt", "w") as file:
|
||||||
|
file.write(str(last_rt))
|
||||||
|
api.PostDirectMessage("Help! I broke down. restart me pls :$", "801098086005243904", "links_tech")
|
Loading…
Reference in a new issue