elfsong commited on
Commit
a1561e0
β€’
1 Parent(s): bd3bfcd
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -1,8 +1,22 @@
 
1
  import streamlit as st
2
-
3
-
4
- def get_status():
5
- return True
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def activate_server():
8
  return True
@@ -10,7 +24,8 @@ def activate_server():
10
 
11
  st.title("Lucky Reactor")
12
 
13
- status = get_status()
 
14
 
15
  st.image("cover.jpg", caption="Reactor is currently " + "running πŸš€" if status else "sleeping 😴" + ".")
16
 
 
1
+ import os
2
  import streamlit as st
3
+ import googleapiclient.discovery
4
+ from google.oauth2 import service_account
5
+
6
+ def auth():
7
+ with open("/tmp/token.json", "w") as token_f:
8
+ token_f.write("Hello")
9
+ return credentials
10
+
11
+ def get_status(credentials):
12
+ status = False
13
+ client = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
14
+
15
+ result = client.instances().list(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-c').execute()
16
+ for item in result['items']:
17
+ if item["name"] == "oj":
18
+ status = True if item["status"] == "RUNNING" else False
19
+ return status
20
 
21
  def activate_server():
22
  return True
 
24
 
25
  st.title("Lucky Reactor")
26
 
27
+ credentials = auth()
28
+
29
 
30
  st.image("cover.jpg", caption="Reactor is currently " + "running πŸš€" if status else "sleeping 😴" + ".")
31