mirror of
https://github.com/cquest/tootbot.git
synced 2025-05-02 09:03:35 +00:00
pep8
This commit is contained in:
parent
720aff1abd
commit
184ab026f4
13
tootbot.py
13
tootbot.py
@ -9,13 +9,14 @@ from mastodon import Mastodon
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
if len(sys.argv) < 4:
|
if len(sys.argv) < 4:
|
||||||
print("Usage: python3 tootbot.py twitter_account mastodon_login mastodon_passwd mastodon_instance")
|
print("Usage: python3 tootbot.py twitter_account mastodon_login mastodon_passwd mastodon_instance") # noqa
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# sqlite db to store processed tweets (and corresponding toots ids)
|
# sqlite db to store processed tweets (and corresponding toots ids)
|
||||||
sql = sqlite3.connect('tootbot.db')
|
sql = sqlite3.connect('tootbot.db')
|
||||||
db = sql.cursor()
|
db = sql.cursor()
|
||||||
db.execute('''CREATE TABLE IF NOT EXISTS tweets (tweet text, toot text, twitter text, mastodon text, instance text)''')
|
db.execute('''CREATE TABLE IF NOT EXISTS tweets (tweet text, toot text,
|
||||||
|
twitter text, mastodon text, instance text)''')
|
||||||
|
|
||||||
if len(sys.argv) > 4:
|
if len(sys.argv) > 4:
|
||||||
instance = sys.argv[4]
|
instance = sys.argv[4]
|
||||||
@ -37,7 +38,7 @@ d = feedparser.parse('http://twitrss.me/twitter_user_to_rss/?user='+twitter)
|
|||||||
|
|
||||||
for t in reversed(d.entries):
|
for t in reversed(d.entries):
|
||||||
# check if this tweet has been processed
|
# check if this tweet has been processed
|
||||||
db.execute('SELECT * FROM tweets WHERE tweet = ? AND twitter = ? and mastodon = ? and instance = ?',(t.id, twitter, mastodon, instance))
|
db.execute('SELECT * FROM tweets WHERE tweet = ? AND twitter = ? and mastodon = ? and instance = ?', (t.id, source, mastodon, instance)) # noqa
|
||||||
last = db.fetchone()
|
last = db.fetchone()
|
||||||
|
|
||||||
# process only unprocessed tweets less than 1 day old
|
# process only unprocessed tweets less than 1 day old
|
||||||
@ -99,7 +100,11 @@ for t in reversed(d.entries):
|
|||||||
c = c.replace('\xa0…',' ')
|
c = c.replace('\xa0…',' ')
|
||||||
|
|
||||||
if toot_media is not None:
|
if toot_media is not None:
|
||||||
toot = mastodon_api.status_post(c, in_reply_to_id=None, media_ids=toot_media, sensitive=False, visibility='public', spoiler_text=None)
|
toot = mastodon_api.status_post(c, in_reply_to_id=None,
|
||||||
|
media_ids=toot_media,
|
||||||
|
sensitive=False,
|
||||||
|
visibility='public',
|
||||||
|
spoiler_text=None)
|
||||||
if "id" in toot:
|
if "id" in toot:
|
||||||
db.execute("INSERT INTO tweets VALUES ( ? , ? , ? , ? , ? )",
|
db.execute("INSERT INTO tweets VALUES ( ? , ? , ? , ? , ? )",
|
||||||
(t.id, toot["id"], twitter, mastodon, instance))
|
(t.id, toot["id"], twitter, mastodon, instance))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user