-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
103 lines (81 loc) · 2.48 KB
/
client.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""requests client library. glue between cli and server running the simulation"""
import requests
import json
import os
#path = "https://factorio-cli.replit.app/"
#path = "http://127.0.0.1:5000/"
path = os.getenv('SERVER_URL')
# todo some obvious way to client source code to correponding server source code
# why does source code not have hyperlinks to more code
# put the endpoint as its formatted on the server here, so it's easy to cross reference
def get_game_time():
# /time
r = requests.get(f'{path}time')
r.raise_for_status()
return float(r.text)
def launch():
r = requests.post(f'{path}launch')
return r.text
def clear():
# /clear
r = requests.post(f'{path}clear')
r.raise_for_status()
def spawn(item, amount):
# /spawn
r = requests.post(f'{path}spawn?item={item}&amount={amount}')
r.raise_for_status()
def get_inventory():
# /inventory
r = requests.get(f'{path}inventory')
r.raise_for_status()
return r.json()
def research(technology):
# /research
r = requests.post(f'{path}research?technology={technology}')
return r.text
def researchable(technology):
# /researchable
r = requests.post(f'{path}researchable?technology={technology}')
return r.text
def place(machine, item, amount):
r = requests.post(f'{path}place?machine={machine}&item={item}&amount={amount}')
return r.text
def next(minutes):
r = requests.post(f'{path}next?minutes={minutes}')
r.raise_for_status()
def craft(item, amount):
r = requests.post(f'{path}craft?item={item}&amount={amount}')
return r.text
def craftable(item, amount):
r = requests.get(f'{path}craftable?item={item}&amount={amount}')
return r.text
def mine(resource, amount):
r = requests.post(f'{path}mine?resource={resource}&amount={amount}')
return r.text
def cookbook():
r = requests.get(f'{path}cookbook')
return r.text
def limits():
r = requests.get(f'{path}limits')
return r.text
def suggest():
r = requests.get(f'{path}suggest')
return r.text
def production():
r = requests.get(f'{path}production')
return r.text
def limit(item, amount):
r = requests.post(f'{path}limit?item={item}&amount={amount}')
return r.text
def prio(machine,item,old,new):
r = requests.post(f'{path}prio?machine={machine}&item={item}&oldprio={old}&newprio={new}')
return r.text
def state():
r = requests.get(f'{path}state')
return r.text
def update(state):
headers = {
"Content-Type": "application/json"
}
r = requests.post(f'{path}update', data=json.dumps(state), headers=headers)
return r.text