From dd3679d8db4051d2570bf506b5346ede123030ea Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 3 Sep 2019 14:29:45 +1000 Subject: [PATCH] started work on service.py, the cron thing that actually downloads the posts --- service.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/service.py b/service.py index e69de29..d335be8 100644 --- a/service.py +++ b/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")