Spaces:
Sleeping
Sleeping
Update sheets_integration.py
Browse files- sheets_integration.py +38 -14
sheets_integration.py
CHANGED
@@ -41,33 +41,57 @@ class SheetsLogger:
|
|
41 |
self.gc = None
|
42 |
self.sheet = None
|
43 |
|
44 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
"""Log a request to Google Sheets"""
|
46 |
if not self.sheet:
|
47 |
-
print("Sheet not initialized")
|
48 |
return False
|
49 |
|
50 |
try:
|
51 |
-
# Prepare row data
|
52 |
row = [
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
62 |
]
|
63 |
|
64 |
-
# Append row to sheet
|
65 |
self.sheet.append_row(row)
|
66 |
return True
|
67 |
|
68 |
except Exception as e:
|
69 |
print(f"Error logging to sheet: {str(e)}")
|
70 |
-
return False
|
71 |
|
72 |
def get_all_requests(self):
|
73 |
"""Get all requests from the sheet"""
|
|
|
41 |
self.gc = None
|
42 |
self.sheet = None
|
43 |
|
44 |
+
def initialize_sheet(self):
|
45 |
+
"""Initialize sheet with headers if needed"""
|
46 |
+
headers = [
|
47 |
+
"Timestamp",
|
48 |
+
"Name",
|
49 |
+
"Employee ID",
|
50 |
+
"Email",
|
51 |
+
"Department",
|
52 |
+
"Request Details",
|
53 |
+
"Frequency",
|
54 |
+
"Urgency",
|
55 |
+
"User Summary",
|
56 |
+
"Technical Analysis",
|
57 |
+
"Status", # For tracking request status
|
58 |
+
"Notes" # For additional comments
|
59 |
+
]
|
60 |
+
|
61 |
+
try:
|
62 |
+
# Check if headers exist
|
63 |
+
existing_headers = self.sheet.row_values(1)
|
64 |
+
if not existing_headers:
|
65 |
+
self.sheet.insert_row(headers, 1)
|
66 |
+
except Exception as e:
|
67 |
+
print(f"Error initializing headers: {str(e)}")
|
68 |
+
|
69 |
+
def log_request(self, data):
|
70 |
"""Log a request to Google Sheets"""
|
71 |
if not self.sheet:
|
|
|
72 |
return False
|
73 |
|
74 |
try:
|
|
|
75 |
row = [
|
76 |
+
data.get('timestamp', ''),
|
77 |
+
data.get('name', ''),
|
78 |
+
data.get('employee_id', ''),
|
79 |
+
data.get('email', ''),
|
80 |
+
data.get('department', ''),
|
81 |
+
data.get('request_details', ''),
|
82 |
+
data.get('frequency', ''),
|
83 |
+
data.get('urgency', ''),
|
84 |
+
data.get('user_summary', ''),
|
85 |
+
data.get('system_analysis', ''),
|
86 |
+
'New', # Initial status
|
87 |
+
'' # Empty notes
|
88 |
]
|
89 |
|
|
|
90 |
self.sheet.append_row(row)
|
91 |
return True
|
92 |
|
93 |
except Exception as e:
|
94 |
print(f"Error logging to sheet: {str(e)}")
|
|
|
95 |
|
96 |
def get_all_requests(self):
|
97 |
"""Get all requests from the sheet"""
|