Skip to content

Commit

Permalink
fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
colin committed Dec 10, 2023
1 parent 6831ba9 commit 08dcd0d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 43 deletions.
30 changes: 0 additions & 30 deletions api/ini/favourites.ini

This file was deleted.

41 changes: 28 additions & 13 deletions helpers/favourites.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import configparser
import json
import os

import requests

import helpers.connection as db

config = configparser.ConfigParser()
file_path = 'ini/favourites.ini'
absolute_path = os.path.join(os.getcwd(), file_path)
config.read(absolute_path)


# function to return the locations user had saved as favourites
# from the database along with the place details
def retrieve_favourites(user):
if 'UserSettings' in config:
print("UserSettings section found.")
print(config['query']['retrieve_favourites'])

conn, cursor = db.connect_to_db()
cursor.execute(config['query']['retrieve_favourites'], (user,))
sql = """
SELECT
CONCAT(a.location, ' (',CAST(a.date AS VARCHAR),')') AS trip,
a.id AS index, a.location, a.date, a.placeid, b.name,
CAST(b.ratings AS FLOAT) AS ratings,
b.rating_count, b.search_link, b.photo_reference,
b.editorial_summary, b.type, c.sortorder
FROM placesadded a
LEFT JOIN places b
ON a.placeid = b.placeid
LEFT JOIN placesorder c
ON CONCAT(a.userid, a.location,
' (',CAST(a.date AS VARCHAR),')')
= c.id
WHERE a.userid = %s
ORDER BY a.date DESC, index;
"""
cursor.execute(sql, (user,))
sql_results = cursor.fetchall()
cursor.close()
conn.close()
Expand Down Expand Up @@ -95,8 +103,15 @@ def save_favourites_order(user, sortedList):
trip_id = sortedList[0]['tripid']
sorted_idx = [x['idx'] for x in sortedList]
conn, cursor = db.connect_to_db()
cursor.execute(config['query']['save_fav_order'],
(user + trip_id, sorted_idx, sorted_idx))
sql = """
INSERT INTO placesorder (id, sortorder)
VALUES (%(id)s, %(sortorder)s)
ON CONFLICT (id) DO UPDATE
SET sortorder = %(sortorder)s;
"""
cursor.execute(sql,
{"id": user + trip_id,
"sortorder": (sorted_idx)})
conn.commit()
cursor.close()
conn.close()
Expand Down

0 comments on commit 08dcd0d

Please sign in to comment.