working on the actual posting functionality

This commit is contained in:
Lynne Megido 2018-11-13 20:12:19 +10:00
父節點 edb0559aee
當前提交 16c4ffd712
簽署人: lynnesbian
GPG Key ID: FB7B970303ACE499
共有 3 個文件被更改,包括 24 次插入4 次删除

查看文件

@ -4,5 +4,7 @@
"flask_key":"put a secure secret key here, and rename this file to 'meta.json'",
"dbuser":"curiousgreg",
"dbpass":"choose a good password for the mysql user and put it here",
"dbname":"curiousgreg"
"dbname":"curiousgreg",
"min_time_between_checks":1,
"max_time_between_checks":60
}

20
run.py
查看文件

@ -18,4 +18,22 @@ dc = db.cursor(dictionary=True)
dc.execute("SELECT * FROM data")
for row in dc.fetchall():
print(row)
t = int(time.time())
next_check = row['last_check'] + row['time_between_checks'] * 60
if next_check > t:
row['time_between_checks'] = cfg['min_time_between_checks']
#time to check
if row['cc'] != "None" and row['cc'] != None:
r = requests.get("https://curiouscat.me/api/v2/profile?username={}&count=100&min_timestamp={}".format(row['cc'], row['latest_post']))
j = r.json()
if len(j['posts'] > 0):
#they've made some new posts, log in to masto
client = Mastodon(client_id=row['client_id'], client_secret=row['client_secret'], access_token=row['secret'], api_base_url=row['instance'])
for post in j['posts']:
if post['senderData']['id'] == False:
sender = "Anonymous user"
else:
sender = post['senderData']['username']
toot = "Curious cat question from {}: \"{}\"<br />My answer: {}\nView online at https://curiouscat.me/{}/post/{}".format(sender, post['comment'], post['reply'], row['cc'], post['id'])

4
web.py
查看文件

@ -39,9 +39,9 @@ dc = db.cursor(dictionary=True)
# | latest_post | tinytext | YES | | NULL | |
# | last_check | tinytext | YES | | NULL | |
# | time_between_checks | int(11) | YES | | NULL | |
# | settings | varchar(4096) | YES | | {'cw': False} | |
# | settings | varchar(4096) | YES | | {"cw": false} | |
# +---------------------+---------------+------+-----+------------------------------------------------+-------+
c.execute("CREATE TABLE IF NOT EXISTS `data` (username VARCHAR(64) NOT NULL, instance VARCHAR(128) NOT NULL, password TINYTEXT NOT NULL, avi TEXT NOT NULL, secret TINYTEXT NOT NULL, client_id VARCHAR(128) NOT NULL, client_secret TINYTEXT NOT NULL, cc TINYTEXT, ccavi VARCHAR(128) DEFAULT 'https://lynnesbian.space/res/ceres/cc-smol.png', latest_post TINYTEXT, last_check TINYTEXT, time_between_checks INT, settings VARCHAR(4096) DEFAULT \"{}\", PRIMARY KEY(username, instance))".format(settings))
c.execute("CREATE TABLE IF NOT EXISTS `data` (username VARCHAR(64) NOT NULL, instance VARCHAR(128) NOT NULL, password TINYTEXT NOT NULL, avi TEXT NOT NULL, secret TINYTEXT NOT NULL, client_id VARCHAR(128) NOT NULL, client_secret TINYTEXT NOT NULL, cc TINYTEXT, ccavi VARCHAR(128) DEFAULT 'https://lynnesbian.space/res/ceres/cc-smol.png', latest_post TINYTEXT, last_check TINYTEXT, time_between_checks INT, settings VARCHAR(4096) DEFAULT \"{}\", PRIMARY KEY(username, instance))".format(json.dumps(settings)))
app = Flask(cfg['name'])
app.secret_key = cfg['flask_key']