-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathices.py
44 lines (40 loc) · 1.33 KB
/
ices.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
import sys
import http.client, urllib.parse
conn = None
key = "somecoolkey" # Don't forget to also change this in the webserver
webserver = "localhost"
# Function called to initialize your python environment.
# Should return 1 if ok, and 0 if something went wrong.
def ices_init ():
conn = http.client.HTTPSConnection(webserver)
data = urllib.parse.urlencode({'key': key})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn.request("POST","/hook/init",data,headers)
response = conn.getresponse()
conn.close()
if response.status == 200:
return 1
else:
return 0
# Function called to shutdown your python enviroment.
# Return 1 if ok, 0 if something went wrong.
def ices_shutdown ():
conn = http.client.HTTPSConnection(webserver)
data = urllib.parse.urlencode({'key': key})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn.request("POST","/hook/shutdown",data,headers)
response = conn.getresponse()
conn.close()
if response.status == 200:
return 1
else:
return 0
# Function called to get the next filename to stream.
# Should return a string.
def ices_get_next ():
conn = http.client.HTTPSConnection(webserver)
conn.request("GET","/hook/next")
response = conn.getresponse()
data = response.read()
conn.close()
return data.decode("utf-8").strip('\x00')