added the twitter part of the bot. Still an exception to get rid of.

This commit is contained in:
b3yond 2017-06-17 17:52:48 +02:00
parent 491c8e49d3
commit 96e0847f1e
21 changed files with 73 additions and 3 deletions

View File

@ -47,7 +47,7 @@ $ pip3 install Mastodon.py
- [ ] Mastodon: boost people
- [ ] Mastodon: toot who has been retweeted on twitter
- [ ] Twitter: tweet who has been boosted on mastodon
- [ ] Twitter: access the API
- [x] Twitter: access the API
- [ ] Web UI that lets you easily delete toots/tweets per db id and mute the tweet author

24
triggerwords.txt Normal file
View File

@ -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

View File

@ -1,8 +1,54 @@
#!/usr/bin/env python3
#!/usr/bin/env python
__author__ = "b3yond"
import twitter
from time import sleep
api = twitter.Api()
"""
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.
"""
with open("../../api_keys", "r") as file:
keys = file.readlines()
for i in keys:
print i,
# create an Api object
api = twitter.Api(consumer_key = keys[0].strip(),
consumer_secret = keys[1].strip(),
access_token_key = keys[2].strip(),
access_token_secret = keys[3].strip())
# This counter is needed to keep track which was the last tweet you retweeted
last_rt = ""
# Words which have to be included into the tweets for the tweet to get retweeted
with open("../triggerwords.txt", "r") as file:
triggers = file.readlines()
while 1:
sleep(1)
# Store all mentions in a list of Status Objects
mentions = api.GetMentions(since_id=last_rt)
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?
for j in triggers:
if i.text.lower().find(j):
# Retweet status, save the id so it doesn't get crawled again
try:
feedback = api.PostRetweet(i.id)
print feedback
except twitter.error.TwitterError:
print("[ERROR] probably you already retweeted this tweet.")
last_rt = i.id
break