start work on generating thoughts

This commit is contained in:
Lynne Megido 2019-07-20 08:21:59 +10:00
parent d8babf206a
commit 556bcefa33

46
post.py Normal file → Executable file
View file

@ -16,19 +16,39 @@
from mastodon import Mastodon from mastodon import Mastodon
import json, random import json, random
try: # try:
cfg = json.load(open('config.json', 'r')) # cfg = json.load(open('config.json', 'r'))
except: # except:
print("Couldn't load config.json. Make sure you run main.py first!\n-----") # print("Couldn't load config.json. Make sure you run main.py first!\n-----")
raise # raise
meta = json.load(open('meta.json', 'r')) # meta = json.load(open('meta.json', 'r'))
# log in # # log in
client = Mastodon( # client = Mastodon(
client_id=cfg['client']['id'], # client_id=cfg['client']['id'],
client_secret=cfg['client']['secret'], # client_secret=cfg['client']['secret'],
access_token=cfg['secret'], # access_token=cfg['secret'],
api_base_url=cfg['site']) # api_base_url=cfg['site'])
# make a post! # 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)