elfsong commited on
Commit
b5c6cc2
β€’
1 Parent(s): 786017a
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -12,27 +12,27 @@ def auth():
12
 
13
  return credentials
14
 
15
- def get_status(credentials, instance):
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-b').execute()
20
  for item in result['items']:
21
- if item["name"] == instance:
22
  status = True if item["status"] == "RUNNING" else False
23
  return status
24
 
25
- def activate_server(credentials, instance):
26
  service = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
27
- request = service.instances().resume(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-b', instance=instance)
28
  response = request.execute()
29
  return response
30
 
31
  st.title("Lucky Reactor")
32
 
33
- instance = "lucky-reactor"
34
  credentials = auth()
35
- status = get_status(credentials, instance)
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, instance)
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)