From 556bcefa337fceadbd3efe925fe56e30c0632fe6 Mon Sep 17 00:00:00 2001 From: Lynne Date: Sat, 20 Jul 2019 08:21:59 +1000 Subject: [PATCH] start work on generating thoughts --- post.py | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) mode change 100644 => 100755 post.py diff --git a/post.py b/post.py old mode 100644 new mode 100755 index 0e32637..aa3d114 --- a/post.py +++ b/post.py @@ -16,19 +16,39 @@ from mastodon import Mastodon import json, random -try: - cfg = json.load(open('config.json', 'r')) -except: - print("Couldn't load config.json. Make sure you run main.py first!\n-----") - raise -meta = json.load(open('meta.json', 'r')) +# try: +# cfg = json.load(open('config.json', 'r')) +# except: +# print("Couldn't load config.json. Make sure you run main.py first!\n-----") +# raise +# meta = json.load(open('meta.json', 'r')) -# log in -client = Mastodon( - client_id=cfg['client']['id'], - client_secret=cfg['client']['secret'], - access_token=cfg['secret'], - api_base_url=cfg['site']) +# # log in +# client = Mastodon( +# client_id=cfg['client']['id'], +# client_secret=cfg['client']['secret'], +# access_token=cfg['secret'], +# api_base_url=cfg['site']) # make a post! -# if you delete this line, you can also remove the random module from the imports list. +data = json.load(open('data.json', 'r')) + +def get_object(kind): + num = random.choice([1, 1, 1, 1, 1, 2, 2, 3]) + if kind == "rides": + return "{} {}".format(random.choice(data['objects']['thrilling-rides'] + data['objects']['gentle-rides']), num) + +thoughts_weighted = [] +for key in data['thoughts']: + for i in range(len(data['thoughts'][key])): + thoughts_weighted.append(key) + +thought_type = random.choice(thoughts_weighted) +thought_type = "rides" + +thought = random.choice(data['thoughts'][thought_type]) + +if thought_type == "rides": + thought = thought.format(get_object('rides')) + +print(thought)