-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (58 loc) · 2.36 KB
/
main.py
File metadata and controls
76 lines (58 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from bottle import route, run, template, static_file, request
import random
import json
@route("/", method="GET")
def index():
return template("adventure.html")
@route("/start", method="POST")
def start():
username = request.POST.get("name")
current_adv_id = request.POST.get("adventure_id")
user_id = 0 #todo check if exists and if not create it
current_story_id = 0 #todo change
next_steps_results = [
{"id": 1, "option_text": "I fight it"},
{"id": 2, "option_text": "I give him 10 coins"},
{"id": 3, "option_text": "I tell it that I just want to go home"},
{"id": 4, "option_text": "I run away quickly"}
]
#todo add the next step based on db
return json.dumps({"user": user_id,
"adventure": current_adv_id,
"current": current_story_id,
"text": "You meet a mysterious creature in the woods, what do you do?",
"image": "troll.png",
"options": next_steps_results
})
@route("/story", method="POST")
def story():
user_id = request.POST.get("user")
current_adv_id = request.POST.get("adventure")
next_story_id = request.POST.get("next") #this is what the user chose - use it!
next_steps_results = [
{"id": 1, "option_text": "I run!"},
{"id": 2, "option_text": "I hide!"},
{"id": 3, "option_text": "I sleep!"},
{"id": 4, "option_text": "I fight!"}
]
random.shuffle(next_steps_results) #todo change - used only for demonstration purpouses
#todo add the next step based on db
return json.dumps({"user": user_id,
"adventure": current_adv_id,
"text": "New scenario! What would you do?",
"image": "choice.jpg",
"options": next_steps_results
})
@route('/js/<filename:re:.*\.js$>', method='GET')
def javascripts(filename):
return static_file(filename, root='js')
@route('/css/<filename:re:.*\.css>', method='GET')
def stylesheets(filename):
return static_file(filename, root='css')
@route('/images/<filename:re:.*\.(jpg|png|gif|ico)>', method='GET')
def images(filename):
return static_file(filename, root='images')
def main():
run(host='localhost', port=9000)
if __name__ == '__main__':
main()