mirror of
https://gitlab.com/jeancf/twoot.git
synced 2024-11-27 14:01:13 +00:00
Refined db structure
This commit is contained in:
parent
d610d57125
commit
c306187196
22
twoot.py
22
twoot.py
|
@ -158,19 +158,19 @@ def build_config(args):
|
||||||
TOML['options']['tweet_delay'] = float(args['d'])
|
TOML['options']['tweet_delay'] = float(args['d'])
|
||||||
if args['c'] is not None:
|
if args['c'] is not None:
|
||||||
TOML['options']['toot_cap'] = int(args['c'])
|
TOML['options']['toot_cap'] = int(args['c'])
|
||||||
if args['p'] is True:
|
if args['q'] is True:
|
||||||
TOML['options']['update_profile'] = args['p']
|
TOML['options']['update_profile'] = args['q']
|
||||||
|
|
||||||
# Verify that we have a minimum config to run
|
# Verify that we have a minimum config to run
|
||||||
if 'twitter_account' not in TOML['config'].keys() or TOML['config']['twitter_account'] == "":
|
if 'twitter_account' not in TOML['config'].keys() or TOML['config']['twitter_account'] == "":
|
||||||
print('CRITICAL: Missing Twitter account')
|
print('CRITICAL: Missing Twitter account')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
if 'mastodon_instance' not in TOML['config'].keys() or TOML['config']['mastodon_instance'] == "":
|
if 'mastodon_instance' not in TOML['config'].keys() or TOML['config']['mastodon_instance'] == "":
|
||||||
print('CRITICAL: Missing Mastodon instance')
|
print('CRITICAL: Missing Mastodon instance')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
if 'mastodon_user' not in TOML['config'].keys() or TOML['config']['mastodon_user'] == "":
|
if 'mastodon_user' not in TOML['config'].keys() or TOML['config']['mastodon_user'] == "":
|
||||||
print('CRITICAL: Missing Mastodon user')
|
print('CRITICAL: Missing Mastodon user')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
def update_profile(nitter_url, soup, sql, mast_password):
|
def update_profile(nitter_url, soup, sql, mast_password):
|
||||||
|
@ -196,7 +196,7 @@ def update_profile(nitter_url, soup, sql, mast_password):
|
||||||
new_banner_url = soup.find('div', class_='profile-banner').findChild('a').findChild('img').get('src')
|
new_banner_url = soup.find('div', class_='profile-banner').findChild('a').findChild('img').get('src')
|
||||||
|
|
||||||
# Get the original urls of the avatar and banner pictures on the account profile
|
# Get the original urls of the avatar and banner pictures on the account profile
|
||||||
db.execute("SELECT avatar_url, banner_url FROM profiles WHERE mastodon_account=?", (TOML['config']['mastodon_user'],))
|
db.execute("SELECT avatar_url, banner_url FROM profiles WHERE mastodon_instance=? AND mastodon_account=?", (TOML['config']['mastodon_instance'], TOML['config']['mastodon_user'],))
|
||||||
profile_in_db = db.fetchone()
|
profile_in_db = db.fetchone()
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
@ -215,7 +215,7 @@ def update_profile(nitter_url, soup, sql, mast_password):
|
||||||
logging.info('banner image changed on twitter profile')
|
logging.info('banner image changed on twitter profile')
|
||||||
else:
|
else:
|
||||||
# Mastodon user not found in database. Add new record
|
# Mastodon user not found in database. Add new record
|
||||||
db.execute("INSERT INTO profiles (mastodon_account, avatar_url, banner_url) VALUES (?, ?, ?)", (TOML['config']['mastodon_user'], "", ""))
|
db.execute("INSERT INTO profiles (mastodon_instance, mastodon_account, avatar_url, banner_url) VALUES (?, ?, ?, ?)", (TOML['config']['mastodon_instance'], TOML['config']['mastodon_user'], "", ""))
|
||||||
sql.commit()
|
sql.commit()
|
||||||
changed = True
|
changed = True
|
||||||
logging.debug("added new profile to database")
|
logging.debug("added new profile to database")
|
||||||
|
@ -249,7 +249,7 @@ def update_profile(nitter_url, soup, sql, mast_password):
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
else:
|
else:
|
||||||
# Add urls to database
|
# Add urls to database
|
||||||
db.execute("UPDATE profiles SET avatar_url=?, banner_url=? WHERE mastodon_account=?", (new_avatar_url, new_banner_url, TOML['config']['mastodon_user']))
|
db.execute("UPDATE profiles SET avatar_url=?, banner_url=? WHERE mastodon_instance=? AND mastodon_account=?", (new_avatar_url, new_banner_url, TOML['config']['mastodon_instance'], TOML['config']['mastodon_user']))
|
||||||
sql.commit()
|
sql.commit()
|
||||||
logging.debug("updated profile on database")
|
logging.debug("updated profile on database")
|
||||||
|
|
||||||
|
@ -712,7 +712,7 @@ def main(argv):
|
||||||
parser.add_argument('-u', action='store_true', help='Remove trackers from URLs')
|
parser.add_argument('-u', action='store_true', help='Remove trackers from URLs')
|
||||||
parser.add_argument('-v', action='store_true', help='Ingest twitter videos and upload to Mastodon instance')
|
parser.add_argument('-v', action='store_true', help='Ingest twitter videos and upload to Mastodon instance')
|
||||||
parser.add_argument('-o', action='store_true', help='Do not add reference to Original tweet')
|
parser.add_argument('-o', action='store_true', help='Do not add reference to Original tweet')
|
||||||
parser.add_argument('-p', action='store_true', help='update profile if changed')
|
parser.add_argument('-q', action='store_true', help='update profile if changed')
|
||||||
parser.add_argument('-a', metavar='<max age (in days)>', action='store', type=float)
|
parser.add_argument('-a', metavar='<max age (in days)>', action='store', type=float)
|
||||||
parser.add_argument('-d', metavar='<min delay (in mins)>', action='store', type=float)
|
parser.add_argument('-d', metavar='<min delay (in mins)>', action='store', type=float)
|
||||||
parser.add_argument('-c', metavar='<max # of toots to post>', action='store', type=int)
|
parser.add_argument('-c', metavar='<max # of toots to post>', action='store', type=int)
|
||||||
|
@ -785,8 +785,8 @@ def main(argv):
|
||||||
mastodon_account TEXT, tweet_id TEXT, toot_id TEXT)''')
|
mastodon_account TEXT, tweet_id TEXT, toot_id TEXT)''')
|
||||||
db.execute('''CREATE INDEX IF NOT EXISTS main_index ON toots (twitter_account,
|
db.execute('''CREATE INDEX IF NOT EXISTS main_index ON toots (twitter_account,
|
||||||
mastodon_instance, mastodon_account, tweet_id)''')
|
mastodon_instance, mastodon_account, tweet_id)''')
|
||||||
db.execute('''CREATE TABLE IF NOT EXISTS profiles (mastodon_account TEXT, avatar_url TEXT, banner_url TEXT)''')
|
db.execute('''CREATE TABLE IF NOT EXISTS profiles (mastodon_instance TEXT, mastodon_account TEXT, avatar_url TEXT, banner_url TEXT)''')
|
||||||
db.execute('''CREATE INDEX IF NOT EXIsTS profile_index ON profiles (mastodon_account)''')
|
db.execute('''CREATE INDEX IF NOT EXIsTS profile_index ON profiles (mastodon_instance, mastodon_account)''')
|
||||||
|
|
||||||
# Select random nitter instance to fetch updates from
|
# Select random nitter instance to fetch updates from
|
||||||
nitter_url = NITTER_URLS[random.randint(0, len(NITTER_URLS) - 1)]
|
nitter_url = NITTER_URLS[random.randint(0, len(NITTER_URLS) - 1)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user