mirror of
https://github.com/Lynnesbian/FediBooks/
synced 2024-11-25 08:38:59 +00:00
started work on service.py, the cron thing that actually downloads the posts
This commit is contained in:
parent
0294f8e004
commit
dd3679d8db
1 changed files with 33 additions and 0 deletions
33
service.py
33
service.py
|
@ -0,0 +1,33 @@
|
||||||
|
#!/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")
|
Loading…
Reference in a new issue