|
@@ -29,8 +29,8 @@ mastinstance = config['mastodon']['instance'] |
|
|
mastuser = config['mastodon']['user'] |
|
|
mastuser = config['mastodon']['user'] |
|
|
mastpasswd = config['mastodon']['password'] |
|
|
mastpasswd = config['mastodon']['password'] |
|
|
|
|
|
|
|
|
twitter = config['sources']['twitter'] |
|
|
|
|
|
soup = config['sources']['soup'] |
|
|
|
|
|
|
|
|
twitteruser = config['sources']['twitter']['user'] |
|
|
|
|
|
soupuser = config['sources']['soup']['user'] |
|
|
|
|
|
|
|
|
dryrun = config['settings']['dryrun'] |
|
|
dryrun = config['settings']['dryrun'] |
|
|
days = config['settings']['days'] |
|
|
days = config['settings']['days'] |
|
@@ -80,13 +80,13 @@ def register_app(mastuser,mastpasswd,mastinstance,mastodon_api): |
|
|
|
|
|
|
|
|
print('====== TWITTER ======') |
|
|
print('====== TWITTER ======') |
|
|
|
|
|
|
|
|
t = feedparser.parse('http://twitrss.me/twitter_user_to_rss/?user='+twitter) |
|
|
|
|
|
|
|
|
t = feedparser.parse('http://twitrss.me/twitter_user_to_rss/?user='+twitteruser) |
|
|
|
|
|
|
|
|
for p in reversed(t.entries): |
|
|
for p in reversed(t.entries): |
|
|
# check if this tweet has been processed |
|
|
# check if this tweet has been processed |
|
|
db.execute( |
|
|
db.execute( |
|
|
'SELECT * FROM posts WHERE srcpost = ? AND srcuser = ? AND mastuser = ? AND mastinstance = ?', |
|
|
'SELECT * FROM posts WHERE srcpost = ? AND srcuser = ? AND mastuser = ? AND mastinstance = ?', |
|
|
(p.id, twitter, mastuser, mastinstance) |
|
|
|
|
|
|
|
|
(p.id, twitteruser, mastuser, mastinstance) |
|
|
) |
|
|
) |
|
|
last = db.fetchone() |
|
|
last = db.fetchone() |
|
|
|
|
|
|
|
@@ -113,7 +113,7 @@ for p in reversed(t.entries): |
|
|
|
|
|
|
|
|
c = p.title |
|
|
c = p.title |
|
|
|
|
|
|
|
|
if p.author != '(%s)' % twitter: |
|
|
|
|
|
|
|
|
if p.author != '(%s)' % twitteruser: |
|
|
c = ("RT %s\n" % p.author[1:-1]) + c |
|
|
c = ("RT %s\n" % p.author[1:-1]) + c |
|
|
toot_media = [] |
|
|
toot_media = [] |
|
|
# get the pictures... |
|
|
# get the pictures... |
|
@@ -145,10 +145,10 @@ for p in reversed(t.entries): |
|
|
print(c) |
|
|
print(c) |
|
|
|
|
|
|
|
|
if (not dryrun): |
|
|
if (not dryrun): |
|
|
toot = mastodon_api.status_post(c, in_reply_to_id=None, media_ids=toot_media, sensitive=False, visibility='unlisted', spoiler_text=None) |
|
|
|
|
|
|
|
|
toot = mastodon_api.status_post(c, in_reply_to_id=None, media_ids=toot_media, sensitive=False, visibility=config['sources']['twitter']['visibility'], spoiler_text=None) |
|
|
print( '--> toot posted!') |
|
|
print( '--> toot posted!') |
|
|
try: |
|
|
try: |
|
|
db.execute("INSERT INTO posts VALUES ( ? , ? , ? , ? , ? )", (p.id, twitter, toot.id, mastuser, mastinstance)) |
|
|
|
|
|
|
|
|
db.execute("INSERT INTO posts VALUES ( ? , ? , ? , ? , ? )", (p.id, twitteruser, toot.id, mastuser, mastinstance)) |
|
|
sql.commit() |
|
|
sql.commit() |
|
|
except: |
|
|
except: |
|
|
print('database execution failed.') |
|
|
print('database execution failed.') |
|
@@ -170,13 +170,13 @@ h.ignore_links = True |
|
|
h.ignore_images = True |
|
|
h.ignore_images = True |
|
|
h.body_width = 0 |
|
|
h.body_width = 0 |
|
|
|
|
|
|
|
|
s = feedparser.parse('http://'+soup+'/rss') |
|
|
|
|
|
|
|
|
s = feedparser.parse('http://'+soupuser+'/rss') |
|
|
|
|
|
|
|
|
for p in reversed(s.entries): |
|
|
for p in reversed(s.entries): |
|
|
# check if this tweet has been processed |
|
|
# check if this tweet has been processed |
|
|
db.execute( |
|
|
db.execute( |
|
|
'SELECT * FROM posts WHERE srcpost = ? AND srcuser = ? AND mastuser = ? AND mastinstance = ?', |
|
|
'SELECT * FROM posts WHERE srcpost = ? AND srcuser = ? AND mastuser = ? AND mastinstance = ?', |
|
|
(p.id, soup, mastuser, mastinstance) |
|
|
|
|
|
|
|
|
(p.id, soupuser, mastuser, mastinstance) |
|
|
) |
|
|
) |
|
|
last = db.fetchone() |
|
|
last = db.fetchone() |
|
|
|
|
|
|
|
@@ -190,23 +190,23 @@ for p in reversed(s.entries): |
|
|
j = json.loads(p.soup_attributes) |
|
|
j = json.loads(p.soup_attributes) |
|
|
|
|
|
|
|
|
# get status id and user if twitter is source |
|
|
# get status id and user if twitter is source |
|
|
twitterstatus = None |
|
|
|
|
|
twitteruser = None |
|
|
|
|
|
|
|
|
tweet_id = None |
|
|
|
|
|
tweet_author = None |
|
|
if (isinstance(j['source'], str)): |
|
|
if (isinstance(j['source'], str)): |
|
|
if ( j['source'].startswith('https://twitter.com/') or j['source'].startswith('https://mobile.twitter.com/')): |
|
|
if ( j['source'].startswith('https://twitter.com/') or j['source'].startswith('https://mobile.twitter.com/')): |
|
|
twitterurl = j['source'].split('/') |
|
|
twitterurl = j['source'].split('/') |
|
|
twitteruser = twitterurl[3] |
|
|
|
|
|
|
|
|
tweet_author = twitterurl[3] |
|
|
if ( twitterurl[4] == 'status'): |
|
|
if ( twitterurl[4] == 'status'): |
|
|
twitterstatus = twitterurl[5] |
|
|
|
|
|
|
|
|
tweet_id = twitterurl[5] |
|
|
|
|
|
|
|
|
# get all tweeted statuses |
|
|
# get all tweeted statuses |
|
|
db.execute('SELECT srcpost FROM posts where srcuser = ?', (twitter,)) |
|
|
|
|
|
|
|
|
print(twitteruser) |
|
|
|
|
|
db.execute('SELECT srcpost FROM posts where srcuser = ?', (twitteruser,)) |
|
|
postedtweets = [] |
|
|
postedtweets = [] |
|
|
for postedtweet in db.fetchall(): |
|
|
for postedtweet in db.fetchall(): |
|
|
postedtweets.append(postedtweet[0].split('/')[-1]) |
|
|
postedtweets.append(postedtweet[0].split('/')[-1]) |
|
|
|
|
|
|
|
|
# check if already tweeted |
|
|
# check if already tweeted |
|
|
if twitterstatus in postedtweets: |
|
|
|
|
|
|
|
|
if tweet_id in postedtweets: |
|
|
print('Already tweeted: ', j['source']) |
|
|
print('Already tweeted: ', j['source']) |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
@@ -258,11 +258,11 @@ for p in reversed(s.entries): |
|
|
|
|
|
|
|
|
if (not dryrun): |
|
|
if (not dryrun): |
|
|
# post toot |
|
|
# post toot |
|
|
toot = mastodon_api.status_post(text, in_reply_to_id=None, media_ids=toot_media, sensitive=False, visibility='public', spoiler_text=None) |
|
|
|
|
|
|
|
|
toot = mastodon_api.status_post(text, in_reply_to_id=None, media_ids=toot_media, sensitive=False, visibility=config['sources']['soup']['visibility'], spoiler_text=None) |
|
|
|
|
|
|
|
|
# add entry to database |
|
|
# add entry to database |
|
|
if "id" in toot: |
|
|
if "id" in toot: |
|
|
db.execute("INSERT INTO posts VALUES ( ? , ? , ? , ? , ? )", (p.id, soup, toot.id, mastuser, mastinstance)) |
|
|
|
|
|
|
|
|
db.execute("INSERT INTO posts VALUES ( ? , ? , ? , ? , ? )", (p.id, soupuser, toot.id, mastuser, mastinstance)) |
|
|
sql.commit() |
|
|
sql.commit() |
|
|
print( '--> ', p.id, ' posted!') |
|
|
print( '--> ', p.id, ' posted!') |
|
|
else: |
|
|
else: |
|
|