Spaces:
Runtime error
Runtime error
elfsong
commited on
Commit
β’
b5c6cc2
1
Parent(s):
786017a
Update
Browse files
app.py
CHANGED
@@ -12,27 +12,27 @@ def auth():
|
|
12 |
|
13 |
return credentials
|
14 |
|
15 |
-
def get_status(credentials,
|
16 |
status = False
|
17 |
client = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
18 |
|
19 |
-
result = client.instances().list(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-
|
20 |
for item in result['items']:
|
21 |
-
if item["name"] ==
|
22 |
status = True if item["status"] == "RUNNING" else False
|
23 |
return status
|
24 |
|
25 |
-
def activate_server(credentials,
|
26 |
service = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
27 |
-
request = service.instances().resume(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-
|
28 |
response = request.execute()
|
29 |
return response
|
30 |
|
31 |
st.title("Lucky Reactor")
|
32 |
|
33 |
-
|
34 |
credentials = auth()
|
35 |
-
status = get_status(credentials,
|
36 |
|
37 |
st.image("cover.jpg", caption="Lucky Reactor is currently " + ("running π" if status else "sleeping π΄") + ".")
|
38 |
|
@@ -43,5 +43,5 @@ if not status:
|
|
43 |
|
44 |
if submitted and token == os.getenv("EASY_TOKEN"):
|
45 |
st.write("Lucky Reactor has been ignited. Please wait a few minutes (3~5) to preceed...")
|
46 |
-
response = activate_server(credentials,
|
47 |
# st.write(response)
|
|
|
12 |
|
13 |
return credentials
|
14 |
|
15 |
+
def get_status(credentials, instance_name):
|
16 |
status = False
|
17 |
client = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
18 |
|
19 |
+
result = client.instances().list(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-c').execute()
|
20 |
for item in result['items']:
|
21 |
+
if item["name"] == instance_name:
|
22 |
status = True if item["status"] == "RUNNING" else False
|
23 |
return status
|
24 |
|
25 |
+
def activate_server(credentials, instance_name):
|
26 |
service = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
27 |
+
request = service.instances().resume(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-c', instance=instance_name)
|
28 |
response = request.execute()
|
29 |
return response
|
30 |
|
31 |
st.title("Lucky Reactor")
|
32 |
|
33 |
+
instance_name = "lucky-reactor"
|
34 |
credentials = auth()
|
35 |
+
status = get_status(credentials, instance_name)
|
36 |
|
37 |
st.image("cover.jpg", caption="Lucky Reactor is currently " + ("running π" if status else "sleeping π΄") + ".")
|
38 |
|
|
|
43 |
|
44 |
if submitted and token == os.getenv("EASY_TOKEN"):
|
45 |
st.write("Lucky Reactor has been ignited. Please wait a few minutes (3~5) to preceed...")
|
46 |
+
response = activate_server(credentials, instance_name)
|
47 |
# st.write(response)
|