]> Devi Nivas Git - 4180kiosk.git/commitdiff
Add S3 exception dialog
authorAdvaith Menon <noreply-git@bp4k.net>
Fri, 30 Jan 2026 23:35:51 +0000 (18:35 -0500)
committerAdvaith Menon <noreply-git@bp4k.net>
Fri, 30 Jan 2026 23:35:51 +0000 (18:35 -0500)
ohdisp/exception_dialog.py
ohdisp/views.py

index 5bbdafce0235fcf43ba8ee338da0ae482931379e..6659745f9435b53f2afef7e8357c8addcaa57edd 100644 (file)
@@ -1,22 +1,31 @@
 import os
 import sys
 import threading
+import time
+import uuid
 
 import tkinter as tk
 from tkinter import messagebox
+from tkinter import simpledialog
 from tkinter.font import Font
 
+import urllib3
+
 
 class ExceptionDialog(tk.Toplevel):
     def __init__(self, parent, txt, *args, **kwargs):
         super().__init__(parent, *args, **kwargs);
 
         self.title("Unhandled Exception");
-        self.attributes("-topmost", True);
+        # self.attributes("-topmost", True);
+        # self.grab_set()
         self.wm_protocol("WM_DELETE_WINDOW", self.destroy)
 
+        self.ex_txt = txt
+
         tit_lbl = tk.Label(self, text=("An unhandled exception has occured!\n"
-                                   "Send a screenshot to advaith@gatech.edu\n"
+                                   "Try uploading logs to S3\n"
+                       "If that fails, Send a screenshot to advaith@gatech.edu\n"
                             "Press Quit to quit/restart the "
                                        "application."),
                            anchor='w', padx=2, pady=2, justify='left')
@@ -45,6 +54,41 @@ class ExceptionDialog(tk.Toplevel):
                              padx=5, pady=5)
         self.expand_btn.pack(side='right')
 
+        self.upload_btn = tk.Button(self, text="Upload to S3",
+                               command=self.w_upload_to_s3,
+                             padx=5, pady=5);
+        self.upload_btn.pack(side='right')
+
     def w_maximize(self):
         self.state("zoomed");
         self.expand_btn.destroy();
+
+    def w_upload_to_s3(self):
+        filename = hex(uuid.getnode())[2:].upper() \
+                + "-" + str(time.time()) \
+                + "-" + uuid.uuid4().hex \
+                + ".txt";
+        comment = ""
+        while not comment:
+            comment = simpledialog.askstring("Unhandled Exception",
+                       "Enter what last happened.\n"
+                       "This includes anything that was said and heard.");
+
+        try:
+            urllib3.request("PUT",
+                  "https://w94n7w8zq5.execute-api.us-east-1.amazonaws.com/dev/"
+                  + filename,
+                  body="User comment: {}\n\n\n{}".format(comment,
+                                                         self.ex_txt),
+                  headers={"Content-Type": "text/plain"})
+        except:
+            messagebox.showerror("Upload Failed",
+                                 "Upload Failed.\n"
+                                 "Send a screenshot to advaith@gatech.edu "
+                                 "instead");
+        else:
+            messagebox.showinfo("Upload Success",
+                                "Uploaded to:\n" + filename
+                            + "\nPlease send this name to advaith@gatech.edu");
+        finally:
+            self.upload_btn.destroy()
index cfb35c0de57d99f951ce6e52d7f6d7727705b5e4..6c6e31f52e1f3ec3dd160ae25ae7f9eb233c98ed 100644 (file)
@@ -1,6 +1,7 @@
 import os
 import sys
 import threading
+import traceback
 
 import tkinter as tk
 from tkinter import messagebox