1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 16:48:58 +00:00

Compare commits

..

3 commits

2 changed files with 14 additions and 4 deletions

View file

@ -9,6 +9,14 @@ import functions
cfg = json.load(open('config.json')) cfg = json.load(open('config.json'))
def scrape_posts(account): def scrape_posts(account):
db = MySQLdb.connect(
host = cfg['db_host'],
user=cfg['db_user'],
passwd=cfg['db_pass'],
db=cfg['db_name'],
use_unicode=True,
charset="utf8mb4"
)
handle = account[0] handle = account[0]
outbox = account[1] outbox = account[1]
print("Scraping {}".format(handle)) print("Scraping {}".format(handle))
@ -78,12 +86,14 @@ def scrape_posts(account):
if r.status_code == 429: if r.status_code == 429:
# we are now being ratelimited, move on to the next user # we are now being ratelimited, move on to the next user
print("Hit rate limit while scraping {}".format(handle))
done = True done = True
else: else:
j = r.json() j = r.json()
db.commit() db.commit()
db.commit()
print("Finished scraping {}".format(handle)) print("Finished scraping {}".format(handle))
print("Establishing DB connection") print("Establishing DB connection")
@ -101,9 +111,9 @@ cursor = db.cursor()
print("Downloading posts") print("Downloading posts")
cursor.execute("SELECT `handle`, `outbox` FROM `fedi_accounts` ORDER BY RAND()") cursor.execute("SELECT `handle`, `outbox` FROM `fedi_accounts` ORDER BY RAND()")
accounts = cursor.fetchall() accounts = cursor.fetchall()
cursor.close()
db.close()
with Pool(cfg['service_threads']) as p: with Pool(cfg['service_threads']) as p:
p.map(scrape_posts, accounts) p.map(scrape_posts, accounts)
db.commit()
print("Done!") print("Done!")

View file

@ -287,7 +287,7 @@ def bot_accounts_add():
if r.status_code == 200: if r.status_code == 200:
j = r.json() j = r.json()
if 'is_pro' in j['contact_account']: if 'contact_account' in j and 'is_pro' in j['contact_account']:
# gab instance # gab instance
error = "Gab instances are not supported." error = "Gab instances are not supported."
return render_template("bot_accounts_add.html", error = error) return render_template("bot_accounts_add.html", error = error)
@ -395,7 +395,7 @@ def bot_create():
session['instance_type'] = "Pleroma" session['instance_type'] = "Pleroma"
session['step'] += 1 session['step'] += 1
else: else:
if 'is_pro' in j['contact_account']: if 'contact_account' in j and 'is_pro' in j['contact_account']:
# gab instance # gab instance
session['error'] = "Gab instances are not supported." session['error'] = "Gab instances are not supported."
else: else: