Skip to content

Feature/international days #210

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
231bbc6
added functions to add data to the db, added fronted and added the th…
liaarbel Jan 27, 2021
74e36f3
added get data from database function
liaarbel Jan 27, 2021
3a40b06
finished international days functionality and start with testing
liaarbel Jan 29, 2021
a4f7a80
move .idea to gitignore
liaarbel Jan 29, 2021
fae7d17
merged
liaarbel Jan 29, 2021
ac23d01
merged
liaarbel Jan 29, 2021
af49910
added tests and templates not connected to the full project
liaarbel Feb 5, 2021
5c6695b
merged
liaarbel Feb 5, 2021
a511898
create client side to international days feature
liaarbel Feb 5, 2021
9857b9b
changed fronted message
liaarbel Feb 5, 2021
db8e55b
deleted css styles
liaarbel Feb 5, 2021
7dd4ec4
reformat code
liaarbel Feb 5, 2021
1054fe4
reformatted code
liaarbel Feb 5, 2021
e3d4b74
reformatted code
liaarbel Feb 5, 2021
2e9a0c1
formatted json, changed name of a function, and delete unused file
liaarbel Feb 6, 2021
9055936
changed function name in tests
liaarbel Feb 6, 2021
4952b96
change load data by 'json_data_loader', little changes in the fronted…
liaarbel Feb 7, 2021
5a52693
merged
liaarbel Feb 7, 2021
6996280
reformatted code
liaarbel Feb 7, 2021
e32f592
changed typing
liaarbel Feb 7, 2021
e2c6d8a
changed from Optional to Union
liaarbel Feb 7, 2021
593e1c2
install requirements
liaarbel Feb 7, 2021
09c2a17
reformatted json
liaarbel Feb 7, 2021
21ec125
typing changes
liaarbel Feb 7, 2021
227117d
changed typing convert
liaarbel Feb 8, 2021
39914e5
changed typing convert
liaarbel Feb 8, 2021
136b353
changed month get
liaarbel Feb 8, 2021
80d1f52
changed test input
liaarbel Feb 8, 2021
f31eefa
merged
liaarbel Feb 14, 2021
24b54ef
deleted styles
liaarbel Feb 14, 2021
ac7db28
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
liaarbel Feb 15, 2021
2892180
added tests for every international day, reformatted and change funct…
liaarbel Feb 15, 2021
95a1c73
reformatted
liaarbel Feb 15, 2021
84d2742
reformatted2
liaarbel Feb 15, 2021
1ae4836
fixed test
liaarbel Feb 15, 2021
ebbbe18
fixed test
liaarbel Feb 15, 2021
4408939
reformatted files
liaarbel Feb 16, 2021
b7bc835
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
liaarbel Feb 16, 2021
0e10d53
merged
liaarbel Feb 16, 2021
a504708
merged
liaarbel Feb 23, 2021
a897d93
fixed tests, changed functions name and ordered files.
liaarbel Feb 23, 2021
1610068
deleted unused function
liaarbel Feb 23, 2021
355468a
changed order of days in json, test in every day exist international …
liaarbel Feb 23, 2021
fb60031
fixed and reordered import
liaarbel Feb 23, 2021
d69c3a5
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
liaarbel Feb 23, 2021
0ea7a0b
fixed and reordered import
liaarbel Feb 23, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dev.db
test.db
.idea
config.py

# Byte-compiled / optimized / DLL files
Expand Down
9 changes: 9 additions & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,15 @@ class Joke(Base):
text = Column(String, nullable=False)


class InternationalDays(Base):
__tablename__ = "international_days"

id = Column(Integer, primary_key=True, index=True)
day = Column(Integer, nullable=False)
month = Column(Integer, nullable=False)
international_day = Column(String, nullable=False)


# insert language data

# Credit to adrihanu https://stackoverflow.com/users/9127249/adrihanu
Expand Down
40 changes: 40 additions & 0 deletions app/internal/international_days.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from datetime import datetime
from typing import Optional, Dict, Union

from sqlalchemy.orm import Session
from sqlalchemy.sql.expression import func

from app.database.models import InternationalDays


def get_international_day(
international_day: Dict[str, Union[str, int]]
) -> InternationalDays:
"""Returns an international day object from the dictionary data.

Args:
international_day: A dictionary international day
related information.

Returns:
A new international day object.
"""
return InternationalDays(
day=international_day["day"],
month=international_day["month"],
international_day=international_day["international_day"],
)


def get_international_day_per_day(
session: Session, date: datetime
) -> Optional[InternationalDays]:
day_num = date.day
month = date.month
international_day = (session.query(InternationalDays)
.filter(InternationalDays.day == day_num)
.filter(InternationalDays.month == month)
.order_by(func.random())
.first()
)
return international_day
11 changes: 9 additions & 2 deletions app/internal/json_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from loguru import logger
from sqlalchemy.orm import Session

from app.database.models import Base, Joke, Quote, Zodiac
from app.internal import daily_quotes, jokes, zodiac
from app.database.models import Base, InternationalDays, Joke, Quote, Zodiac
from app.internal import daily_quotes, international_days, jokes, zodiac


def load_to_database(session: Session) -> None:
Expand Down Expand Up @@ -35,6 +35,13 @@ def load_to_database(session: Session) -> None:
daily_quotes.get_quote,
)

_insert_into_database(
session,
'app/resources/international_days.json',
InternationalDays,
international_days.get_international_day,
)

_insert_into_database(
session,
'app/resources/jokes.json',
Expand Down
Loading