Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions backend/database_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
186 changes: 186 additions & 0 deletions cardloader/loadcard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import tkinter as tk
from tkinter import ttk
import json, boto3
from decimal import Decimal


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
self.categories = []
self.special_merchants = []

# Frames for categories and special merchants
self.category_frame = ttk.Frame(root)
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=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")
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)

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")

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)

# 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
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"))

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
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"))

self.special_merchants.append((merchant_entry, cashback_entry))

def validate_float(self, new_value):
try:
if new_value == "":
return True
float(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()
app = CreditCardApp(root)
root.mainloop()
29 changes: 29 additions & 0 deletions cardloader/readme.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 2 additions & 0 deletions cardloader/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tk
boto3