From 589fd4fe1ca81373aac260a2bf4130b9509bdb2e Mon Sep 17 00:00:00 2001 From: Lynne Date: Sat, 20 Jul 2019 10:23:16 +1000 Subject: [PATCH] finish thought generation --- data.json | 6 +++--- post.py | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/data.json b/data.json index 1456555..dcbb417 100644 --- a/data.json +++ b/data.json @@ -51,12 +51,12 @@ "I can't afford {}.", "I'm not paying that much for {}!" ], - "items-other": [ - "I've already got a {}." - ], "items-edible": [ "I've not finished my {} yet." ], + "items-other": [ + "I've already got a {}." + ], "stalls": [ "I can't find {}!" ], diff --git a/post.py b/post.py index 63ee958..869076b 100755 --- a/post.py +++ b/post.py @@ -39,6 +39,23 @@ def get_object(kind): return "{} {}".format(random.choice(data['objects']['thrilling-rides'] + data['objects']['gentle-rides']), num) elif kind in ["gentle-rides", "thrilling-rides"]: return "{} {}".format(random.choice(data['objects'][kind]), num) + elif kind == "items": + return random.choice(list(data['objects']['stalls']['edible'].values()) + list(data['objects']['stalls']['other'].values())) + elif kind == "items-edible": + return random.choice(list(data['objects']['stalls']['edible'].values())) + elif kind == "items-other": + return random.choice(list(data['objects']['stalls']['other'].values())) + elif kind == "stalls": + return "{} {}".format(random.choice(list(data['objects']['stalls']['edible'].keys()) + list(data['objects']['stalls']['other'].keys())), num) + elif kind == "item-stall": + stalls_weighted = [] + for key in data['objects']['stalls']: + for i in range(len(data['objects']['stalls'][key])): + stalls_weighted.append(key) + stall_type = random.choice(stalls_weighted) + choice = random.choice(list(data['objects']['stalls'][stall_type].items()))[::-1] + stall = "{} {}".format(choice[1], num) + return (choice[0], stall) thoughts_weighted = [] for key in data['thoughts']: @@ -46,11 +63,15 @@ for key in data['thoughts']: thoughts_weighted.append(key) thought_type = random.choice(thoughts_weighted) -thought_type = "rides" thought = random.choice(data['thoughts'][thought_type]) -if thought_type in ['rides', 'gentle-rides', 'thrilling-rides']: +if thought_type == "plain": + pass +elif thought_type == "item-stall": + objects = get_object(thought_type) + thought = thought.format(objects[0], objects[1]) +else: thought = thought.format(get_object(thought_type)) print(thought)