-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
56 lines (47 loc) · 1.64 KB
/
utils.py
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
from __future__ import print_function
import sys
import time
import requests
import settings
import pickle
# The printer function that should be used all through out the game.
def printer(text, end_pause=True):
for c in text:
if c == '\n':
raw_input()
print(c, end='')
sys.stdout.flush()
time.sleep(0.01)
if end_pause:
raw_input()
# api endpoint for activities (GET, POST)
def create_activity(text, kind):
try:
r = requests.post(settings.activities_url,
data={'text': text, 'kind': kind})
except:
return False
else:
return r.ok
# set up domain
def reset_base_url(reset=False):
server_domain_url = None
try:
with open(r'settings.pkl', 'rb') as f:
server_domain_url = pickle.load(f)
settings.domain_url = server_domain_url
settings.register_url = server_domain_url + 'register/'
settings.deactivate_url = server_domain_url + 'deactivate/'
settings.activities_url = server_domain_url + 'activities/'
except IOError:
pass
if reset or server_domain_url is None:
template = "What is your server domain url?\n" +\
"(e.g. http://localhost:8888/)\n"
server_domain_url = raw_input(template)
settings.domain_url = server_domain_url
settings.register_url = server_domain_url + 'register/'
settings.deactivate_url = server_domain_url + 'deactivate/'
settings.activities_url = server_domain_url + 'activities/'
with open(r'settings.pkl', 'wb') as f:
pickle.dump(settings.domain_url, f)