Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/fix sqlite holidays and excess data #68

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion python/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python version of Lift Pass Pricing Kata

As with the other language versions, this exercise requires a database. There is a description in the [top level README](../README.md) of how to set up MySQL. If you don't have that, this version should fall back on sqlite3, and create a local database file 'lift_pass.db' in the directory where you run the application. Unfortunately the code doesn't actually work properly with sqlite3, so you'll have to adjust the SQL statements in prices.py.
As with the other language versions, this exercise requires a database. There is a description in the [top level README](../README.md) of how to set up MySQL. If you don't have that, this version should fall back on sqlite3, and create a local database file 'lift_pass.db' in the directory where you run the application.

For this python version you will also need to install the dependencies. I recommend you install them in a virtual environment like this:

Expand Down
11 changes: 11 additions & 0 deletions python/src/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def create_lift_pass_db_connection(connection_options):
def try_to_connect_with_sqlite3(connection_options):
import sqlite3
connection = sqlite3.connect("lift_pass.db")
try:
connection.execute(
'SELECT * FROM holidays '
'WHERE holiday = 2019-03-04'
)
except sqlite3.OperationalError:
pass
else:
return connection

create_statements = [
"""CREATE TABLE IF NOT EXISTS base_price (
pass_id INTEGER PRIMARY KEY AUTOINCREMENT,
Expand All @@ -38,6 +48,7 @@ def try_to_connect_with_sqlite3(connection_options):
]
for statement in create_statements:
connection.execute(statement)
connection.commit()

return connection

Expand Down
2 changes: 2 additions & 0 deletions python/src/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def prices():
holiday = row[0]
if "date" in request.args:
d = datetime.fromisoformat(request.args["date"])
if not isinstance(holiday, datetime):
holiday = datetime.fromisoformat(holiday)
if d.year == holiday.year and d.month == holiday.month and holiday.day == d.day:
is_holiday = True
if not is_holiday and "date" in request.args and datetime.fromisoformat(request.args["date"]).weekday() == 0:
Expand Down