working on the actual posting functionality
This commit is contained in:
parent
edb0559aee
commit
16c4ffd712
3 changed files with 24 additions and 4 deletions
|
@ -4,5 +4,7 @@
|
||||||
"flask_key":"put a secure secret key here, and rename this file to 'meta.json'",
|
"flask_key":"put a secure secret key here, and rename this file to 'meta.json'",
|
||||||
"dbuser":"curiousgreg",
|
"dbuser":"curiousgreg",
|
||||||
"dbpass":"choose a good password for the mysql user and put it here",
|
"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
20
run.py
|
@ -18,4 +18,22 @@ dc = db.cursor(dictionary=True)
|
||||||
dc.execute("SELECT * FROM data")
|
dc.execute("SELECT * FROM data")
|
||||||
for row in dc.fetchall():
|
for row in dc.fetchall():
|
||||||
print(row)
|
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
4
web.py
|
@ -39,9 +39,9 @@ dc = db.cursor(dictionary=True)
|
||||||
# | latest_post | tinytext | YES | | NULL | |
|
# | latest_post | tinytext | YES | | NULL | |
|
||||||
# | last_check | tinytext | YES | | NULL | |
|
# | last_check | tinytext | YES | | NULL | |
|
||||||
# | time_between_checks | int(11) | 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 = Flask(cfg['name'])
|
||||||
app.secret_key = cfg['flask_key']
|
app.secret_key = cfg['flask_key']
|
||||||
|
|
Loading…
Reference in a new issue