1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-16 21:08:57 +00:00
FediBooks/service.py

33 lines
624 B
Python

#!/usr/bin/env python3
from mastodon import Mastodon
import MySQLdb
import requests
from multiprocessing import Pool
import json
cfg = json.load(open('config.json'))
def scrape_posts(handle, outbox):
# check for min_id
last_post = 0
r = requests.get(outbox)
j = r.json()
pleroma = 'next' not in j
if pleroma:
j = j['first']
else:
uri = "{}&min_id={}".format(outbox, last_post)
r = requests.get(uri)
j = r.json()
print("Establishing DB connection")
db = MySQLdb.connect(
host = cfg['db_host'],
user=cfg['db_user'],
passwd=cfg['db_pass'],
db=cfg['db_name']
)
c = db.cursor()
print("Downloading posts")