Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,3 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
import gspread
|
3 |
from google.oauth2.service_account import Credentials
|
@@ -50,11 +119,16 @@ def get_panic_button_occurrences():
|
|
50 |
|
51 |
# Iterate through all rows in the data
|
52 |
for row in data:
|
53 |
-
panic_button
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
return {
|
60 |
"academic": academic_list,
|
|
|
1 |
+
# from fastapi import FastAPI
|
2 |
+
# import gspread
|
3 |
+
# from google.oauth2.service_account import Credentials
|
4 |
+
# from google.auth.exceptions import GoogleAuthError
|
5 |
+
# import os
|
6 |
+
|
7 |
+
# # Define the Academic and Non-Academic panic buttons
|
8 |
+
# academic_panic_buttons = ["MISSED CLASSES", "BACKLOGS", "LACK OF MOTIVATION", "NOT UNDERSTANDING", "BAD MARKS"]
|
9 |
+
# non_academic_panic_buttons = ["EMOTIONAL FACTORS", "PROCRASTINATE", "LOST INTEREST", "LACK OF FOCUS", "GOALS NOT ACHIEVED", "LACK OF DISCIPLINE"]
|
10 |
+
|
11 |
+
# app = FastAPI()
|
12 |
+
|
13 |
+
# # Function to fetch the credentials
|
14 |
+
# def get_credentials_from_env():
|
15 |
+
# service_account_info = {
|
16 |
+
# "type": os.getenv("SERVICE_ACCOUNT_TYPE"),
|
17 |
+
# "project_id": os.getenv("PROJECT_ID"),
|
18 |
+
# "private_key_id": os.getenv("PRIVATE_KEY_ID"),
|
19 |
+
# "private_key": os.getenv("PRIVATE_KEY").replace('\\n', '\n'),
|
20 |
+
# "client_email": os.getenv("CLIENT_EMAIL"),
|
21 |
+
# "client_id": os.getenv("CLIENT_ID"),
|
22 |
+
# "auth_uri": os.getenv("AUTH_URI"),
|
23 |
+
# "token_uri": os.getenv("TOKEN_URI"),
|
24 |
+
# "auth_provider_x509_cert_url": os.getenv("AUTH_PROVIDER_X509_CERT_URL"),
|
25 |
+
# "client_x509_cert_url": os.getenv("CLIENT_X509_CERT_URL"),
|
26 |
+
# "universe_domain": os.getenv("UNIVERSE_DOMAIN")
|
27 |
+
# }
|
28 |
+
|
29 |
+
# scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
30 |
+
# creds = Credentials.from_service_account_info(service_account_info, scopes=scope)
|
31 |
+
# return creds
|
32 |
+
|
33 |
+
# # Main function to fetch the panic button occurrences
|
34 |
+
# @app.get("/panic-button-occurances")
|
35 |
+
# def get_panic_button_occurrences():
|
36 |
+
# try:
|
37 |
+
# # Set up credentials
|
38 |
+
# creds = get_credentials_from_env()
|
39 |
+
# client = gspread.authorize(creds)
|
40 |
+
|
41 |
+
# # Open the Google Sheet
|
42 |
+
# sheet = client.open_by_url('https://docs.google.com/spreadsheets/d/1nFZGkCvRV6qS-mhsORhX3dxI0JSge32_UwWgWKl3eyw/edit?gid=0#gid=0').worksheet('Sheet1')
|
43 |
+
|
44 |
+
# # Get all values from the sheet
|
45 |
+
# data = sheet.get_all_values()
|
46 |
+
|
47 |
+
# # Initialize the lists with panic button names and 0 counts
|
48 |
+
# academic_list = {button: 0 for button in academic_panic_buttons}
|
49 |
+
# non_academic_list = {button: 0 for button in non_academic_panic_buttons}
|
50 |
+
|
51 |
+
# # Iterate through all rows in the data
|
52 |
+
# for row in data:
|
53 |
+
# panic_button = row[1] # Assuming the panic button values are in the second column
|
54 |
+
# if panic_button in academic_list:
|
55 |
+
# academic_list[panic_button] += 1
|
56 |
+
# elif panic_button in non_academic_list:
|
57 |
+
# non_academic_list[panic_button] += 1
|
58 |
+
|
59 |
+
# return {
|
60 |
+
# "academic": academic_list,
|
61 |
+
# "non_academic": non_academic_list
|
62 |
+
# }
|
63 |
+
|
64 |
+
# except GoogleAuthError as e:
|
65 |
+
# return {"error": f"Authentication error: {e}"}
|
66 |
+
# except gspread.exceptions.SpreadsheetNotFound:
|
67 |
+
# return {"error": "Spreadsheet not found. Please check the URL."}
|
68 |
+
# except Exception as e:
|
69 |
+
# return {"error": f"An error occurred: {e}"}
|
70 |
from fastapi import FastAPI
|
71 |
import gspread
|
72 |
from google.oauth2.service_account import Credentials
|
|
|
119 |
|
120 |
# Iterate through all rows in the data
|
121 |
for row in data:
|
122 |
+
for panic_button in row:
|
123 |
+
# Stop when an empty column is encountered
|
124 |
+
if not panic_button:
|
125 |
+
break
|
126 |
+
|
127 |
+
# Check and update counts for academic and non-academic panic buttons
|
128 |
+
if panic_button in academic_list:
|
129 |
+
academic_list[panic_button] += 1
|
130 |
+
elif panic_button in non_academic_list:
|
131 |
+
non_academic_list[panic_button] += 1
|
132 |
|
133 |
return {
|
134 |
"academic": academic_list,
|