2019-09-03 04:29:45 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import MySQLdb
|
|
|
|
from multiprocessing import Pool
|
2019-09-10 02:07:53 +00:00
|
|
|
import json
|
2019-09-06 02:38:50 +00:00
|
|
|
import functions
|
2019-09-03 04:29:45 +00:00
|
|
|
|
|
|
|
cfg = json.load(open('config.json'))
|
|
|
|
|
|
|
|
print("Establishing DB connection")
|
|
|
|
db = MySQLdb.connect(
|
|
|
|
host = cfg['db_host'],
|
|
|
|
user=cfg['db_user'],
|
|
|
|
passwd=cfg['db_pass'],
|
|
|
|
db=cfg['db_name']
|
|
|
|
)
|
|
|
|
|
2019-09-07 09:37:48 +00:00
|
|
|
print("Cleaning up database")
|
|
|
|
# delete any fedi accounts we no longer need
|
2019-09-06 02:38:50 +00:00
|
|
|
cursor = db.cursor()
|
2019-09-10 02:07:53 +00:00
|
|
|
cursor.execute("DELETE FROM fedi_accounts WHERE handle NOT IN (SELECT fedi_id FROM bot_learned_accounts)")
|
2019-09-06 02:47:39 +00:00
|
|
|
|
2019-09-07 03:31:11 +00:00
|
|
|
print("Generating posts")
|
2019-09-10 01:50:55 +00:00
|
|
|
cursor.execute("SELECT handle FROM bots WHERE enabled = TRUE AND TIMESTAMPDIFF(MINUTE, last_post, CURRENT_TIMESTAMP()) > post_frequency")
|
2019-09-07 03:31:11 +00:00
|
|
|
bots = cursor.fetchall()
|
|
|
|
|
|
|
|
with Pool(8) as p:
|
2019-09-09 03:39:28 +00:00
|
|
|
p.map(functions.make_post, bots)
|
2019-09-07 03:31:11 +00:00
|
|
|
|
2019-09-06 02:47:39 +00:00
|
|
|
#TODO: other cron tasks should be done here, like updating profile pictures
|