From 2361eeb927fc7bf371b95c9885debcd3a337589b Mon Sep 17 00:00:00 2001 From: Eliboll Date: Sun, 31 Mar 2024 23:30:22 -0500 Subject: [PATCH 1/3] working gui --- cardloader/loadcard.py | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 cardloader/loadcard.py diff --git a/cardloader/loadcard.py b/cardloader/loadcard.py new file mode 100644 index 0000000..53ba2f5 --- /dev/null +++ b/cardloader/loadcard.py @@ -0,0 +1,84 @@ +import tkinter as tk +from tkinter import ttk + +class CreditCardApp: + def __init__(self, root): + self.root = root + self.root.title("Credit Card Information") + self.current_category_row = 1 + self.current_merchant_row = 1 + + # Frames for categories and special merchants + self.category_frame = ttk.Frame(root) + self.category_frame.grid(row=2, column=0, sticky="w", columnspan=2, padx=5, pady=5) + + self.merchant_frame = ttk.Frame(root) + self.merchant_frame.grid(row=5, column=0, sticky="w", columnspan=2, padx=5, pady=5) + + # Labels and entry widgets for card information + tk.Label(root, text="Name of the Credit Card:").grid(row=0, column=0, sticky="w") + self.card_name_entry = tk.Entry(root) + self.card_name_entry.grid(row=0, column=1, padx=5, pady=5) + + tk.Label(root, text="Company offering the card:").grid(row=1, column=0, sticky="w") + self.card_company_entry = tk.Entry(root) + self.card_company_entry.grid(row=1, column=1, padx=5, pady=5) + + # Create labels and entry widgets for categories + tk.Label(self.category_frame, text="Categories:").grid(row=0, column=0, sticky="w") + + tk.Label(self.category_frame, text="Category").grid(row=1, column=0, sticky="w") + tk.Label(self.category_frame, text="Cashback Rate").grid(row=1, column=1, sticky="w") + self.add_category_row() # Add initial category row + + # Create button to add more categories + self.add_category_button = tk.Button(self.category_frame, text="Add Category", command=self.add_category_row) + self.add_category_button.grid(row=1, column=2, padx=5, pady=5) + + # Create labels and entry widgets for special merchants + tk.Label(self.merchant_frame, text="Special Merchants:").grid(row=0, column=0, sticky="w") + + tk.Label(self.merchant_frame, text="Merchant Name:").grid(row=1, column=0, sticky="w") + tk.Label(self.merchant_frame, text="Cashback Rate").grid(row=1, column=1, sticky="w") + + # Add initial special merchant row + self.add_special_row() + + # Create button to add more special merchants + self.add_special_button = tk.Button(self.merchant_frame, text="Add Special Merchant", command=self.add_special_row) + self.add_special_button.grid(row=1, column=2, padx=5, pady=5) + + def add_category_row(self): + # Create a new row for a category + self.current_category_row += 1 + category_label = ttk.Combobox(self.category_frame, state="readonly") + category_label.grid(row=self.current_category_row, column=0, padx=5, pady=5) + category_label['values'] = ['Placeholder1', 'Placeholder2', 'Placeholder3'] # Placeholder values + + cashback_entry = tk.Entry(self.category_frame) + cashback_entry.grid(row=self.current_category_row, column=1, padx=5, pady=5) + cashback_entry.config(validate="key", validatecommand=(self.root.register(self.validate_float), "%P")) + + def add_special_row(self): + # Create a new row for a special merchant + self.current_merchant_row += 1 + merchant_entry = tk.Entry(self.merchant_frame) + merchant_entry.grid(row=self.current_merchant_row, column=0, padx=5, pady=5) + + cashback_entry = tk.Entry(self.merchant_frame) + cashback_entry.grid(row=self.current_merchant_row, column=1, padx=5, pady=5) + cashback_entry.config(validate="key", validatecommand=(self.root.register(self.validate_float), "%P")) + + def validate_float(self, new_value): + try: + if new_value == "": + return True + float(new_value) + return True + except ValueError: + return False + +if __name__ == "__main__": + root = tk.Tk() + app = CreditCardApp(root) + root.mainloop() From 4e9db0ce562bae13de03c44899cf6f93e5351468 Mon Sep 17 00:00:00 2001 From: Eliboll Date: Mon, 1 Apr 2024 00:37:42 -0500 Subject: [PATCH 2/3] implement upload --- cardloader/loadcard.py | 106 +++++++++++++++++++++++++++++++++++- cardloader/readme.md | 29 ++++++++++ cardloader/requirements.txt | 2 + 3 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 cardloader/readme.md create mode 100644 cardloader/requirements.txt diff --git a/cardloader/loadcard.py b/cardloader/loadcard.py index 53ba2f5..c031cca 100644 --- a/cardloader/loadcard.py +++ b/cardloader/loadcard.py @@ -1,5 +1,8 @@ import tkinter as tk from tkinter import ttk +import json, boto3 +from decimal import Decimal + class CreditCardApp: def __init__(self, root): @@ -7,13 +10,15 @@ def __init__(self, root): self.root.title("Credit Card Information") self.current_category_row = 1 self.current_merchant_row = 1 + self.categories = [] + self.special_merchants = [] # Frames for categories and special merchants self.category_frame = ttk.Frame(root) - self.category_frame.grid(row=2, column=0, sticky="w", columnspan=2, padx=5, pady=5) + self.category_frame.grid(row=4, column=0, sticky="w", columnspan=2, padx=5, pady=5) self.merchant_frame = ttk.Frame(root) - self.merchant_frame.grid(row=5, column=0, sticky="w", columnspan=2, padx=5, pady=5) + self.merchant_frame.grid(row=7, column=0, sticky="w", columnspan=2, padx=5, pady=5) # Labels and entry widgets for card information tk.Label(root, text="Name of the Credit Card:").grid(row=0, column=0, sticky="w") @@ -23,6 +28,15 @@ def __init__(self, root): tk.Label(root, text="Company offering the card:").grid(row=1, column=0, sticky="w") self.card_company_entry = tk.Entry(root) self.card_company_entry.grid(row=1, column=1, padx=5, pady=5) + + tk.Label(root, text="Base Cashback Rate:").grid(row=2, column=0, sticky="w") + self.base_cashback_entry = tk.Entry(root) + self.base_cashback_entry.grid(row=2, column=1, padx=5, pady=5) + self.base_cashback_entry.config(validate="key", validatecommand=(self.root.register(self.validate_float), "%P")) + + tk.Label(root, text="Image URL").grid(row=3, column=0, sticky="w") + self.image_url = tk.Entry(root) + self.image_url.grid(row=3, column=1, padx=5, pady=5) # Create labels and entry widgets for categories tk.Label(self.category_frame, text="Categories:").grid(row=0, column=0, sticky="w") @@ -48,6 +62,10 @@ def __init__(self, root): self.add_special_button = tk.Button(self.merchant_frame, text="Add Special Merchant", command=self.add_special_row) self.add_special_button.grid(row=1, column=2, padx=5, pady=5) + # Create submit button + self.submit_button = tk.Button(root, text="Submit", command=self.submit_data) + self.submit_button.grid(row=8, column=0, columnspan=2, pady=10) + def add_category_row(self): # Create a new row for a category self.current_category_row += 1 @@ -59,6 +77,8 @@ def add_category_row(self): cashback_entry.grid(row=self.current_category_row, column=1, padx=5, pady=5) cashback_entry.config(validate="key", validatecommand=(self.root.register(self.validate_float), "%P")) + self.categories.append((category_label, cashback_entry)) + def add_special_row(self): # Create a new row for a special merchant self.current_merchant_row += 1 @@ -69,6 +89,8 @@ def add_special_row(self): cashback_entry.grid(row=self.current_merchant_row, column=1, padx=5, pady=5) cashback_entry.config(validate="key", validatecommand=(self.root.register(self.validate_float), "%P")) + self.special_merchants.append((merchant_entry, cashback_entry)) + def validate_float(self, new_value): try: if new_value == "": @@ -77,6 +99,86 @@ def validate_float(self, new_value): return True except ValueError: return False + + def submit_data(self): + card_name = self.card_name_entry.get() + card_company = self.card_company_entry.get() + cashback = self.base_cashback_entry.get() + image_url = self.image_url.get() + category_data = [(category[0].get(), category[1].get()) for category in self.categories] + merchant_data = [(merchant[0].get(), merchant[1].get()) for merchant in self.special_merchants] + try: + if card_name == '' or card_company == '' or cashback == '': + raise + category = [] + for cat in category_data: + if cat[0] == '': + continue + if cat[1] == '': + raise + category.append({cat[0]:float(cat[1])}) + specials = [] + for special in merchant_data: + if special[0] == '': + continue + if special[1] == '': + raise + specials.append({special[0]:float(special[1])}) + except: + # Display a popup on error + popup = tk.Toplevel(self.root) + popup.title("Error") + popup.geometry("400x100") + tk.Label(popup, text="There was an error parsing the data! please check for mistakes").pack(pady=20) + tk.Button(popup, text="OK", command=popup.destroy).pack() + return + + #create json + credit_card_data = { + "card_base": float(cashback), + "card_categories": category, + "card_company": card_company, + "card_name": card_name, + "card_specials": specials, + "image_url": image_url + } + #dynamoDB does not support floating point numbers so convert them to Decimal + credit_card_data['card_id'] = abs(hash(str(credit_card_data))) % (10 ** 12) + credit_card_data = json.loads(json.dumps(credit_card_data), parse_float=Decimal) + #upload data + try: + dynamodb = boto3.resource('dynamodb') + table = dynamodb.Table('cards') + table.put_item(Item=credit_card_data) + except Exception as E: + # Display a popup for error + popup = tk.Toplevel(self.root) + popup.title("Error") + popup.geometry("400x100") + tk.Label(popup, text="There was an error uploading the data").pack(pady=20) + tk.Label(popup, text=str(E)).pack(pady=20) + tk.Button(popup, text="OK", command=popup.destroy).pack() + return + + # Clear the data + self.card_name_entry.delete(0, tk.END) + self.card_company_entry.delete(0, tk.END) + self.base_cashback_entry.delete(0, tk.END) + self.image_url.delete(0, tk.END) + for category in self.categories: + category[0].delete(0, tk.END) + category[1].delete(0, tk.END) + for merchant in self.special_merchants: + merchant[0].delete(0, tk.END) + merchant[1].delete(0, tk.END) + + # Display a popup for success + popup = tk.Toplevel(self.root) + popup.title("Upload Successful") + popup.geometry("200x100") + tk.Label(popup, text="Upload Successful!").pack(pady=20) + tk.Button(popup, text="OK", command=popup.destroy).pack() + if __name__ == "__main__": root = tk.Tk() diff --git a/cardloader/readme.md b/cardloader/readme.md new file mode 100644 index 0000000..13b0bb1 --- /dev/null +++ b/cardloader/readme.md @@ -0,0 +1,29 @@ +# Running Instructions + +You must be using python. + +Install the python dependencies: + +```console +pip install -r requirements.txt +``` +or +```console +python3 -m pip install -r requirements.txt +``` +install the aws cli + +https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html + +configure the cli +```console +aws configure +``` + +Using the credentials from the discord + +run the program + +```console +python3 carrdloader/loadcard.py +``` \ No newline at end of file diff --git a/cardloader/requirements.txt b/cardloader/requirements.txt new file mode 100644 index 0000000..2a7bfeb --- /dev/null +++ b/cardloader/requirements.txt @@ -0,0 +1,2 @@ +tk +boto3 \ No newline at end of file From 644a8ec92590596594faf914949de9f84c6fd687 Mon Sep 17 00:00:00 2001 From: Eliboll Date: Mon, 1 Apr 2024 01:48:10 -0500 Subject: [PATCH 3/3] speed up api by removing photos and switch type to just establishment --- backend/database_query.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/backend/database_query.py b/backend/database_query.py index 26048ce..1b831ec 100644 --- a/backend/database_query.py +++ b/backend/database_query.py @@ -258,16 +258,8 @@ def nearest_locations(latitude, longitude): places_result = gmaps.places_nearby( location=location, - radius=None, - keyword=None, - language=None, - min_price=None, - max_price=None, - name=None, - open_now=False, rank_by=how_to_rank, - type=valid_types, - page_token=None + type='establishment', ) results = places_result['results'][:max_results] @@ -286,17 +278,17 @@ def nearest_locations(latitude, longitude): } # Check if the place has photos - if 'photos' in place: - # Get the reference of the first photo - photo_reference = place['photos'][0]['photo_reference'] - # Construct the photo URL using the reference - unsanitized_photo_url = f"https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference={photo_reference}&key={get_google_api_key()}" + # if 'photos' in place: + # # Get the reference of the first photo + # photo_reference = place['photos'][0]['photo_reference'] + # # Construct the photo URL using the reference + # unsanitized_photo_url = f"https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference={photo_reference}&key={get_google_api_key()}" - # Resolve photo URL - photo_url = get_resolved_url(unsanitized_photo_url) + # # Resolve photo URL + # photo_url = get_resolved_url(unsanitized_photo_url) - # Add the photo URL to the location information - location_info['photo_url'] = photo_url + # # Add the photo URL to the location information + # location_info['photo_url'] = photo_url nearby_locations.append(location_info) return nearby_locations