Skip to content

Feature/shabbatime #333

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

Open
wants to merge 44 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6952f62
new featue-shabbat time
elor555 Feb 23, 2021
c745b37
edit
elor555 Feb 23, 2021
58d8fba
edit
elor555 Feb 24, 2021
4d2e3d3
edit
elor555 Feb 24, 2021
f4451ca
edit
elor555 Feb 24, 2021
03f8200
edit
elor555 Feb 24, 2021
09f3447
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 24, 2021
ad29c3b
edit
elor555 Feb 24, 2021
e82ad81
edit
elor555 Feb 24, 2021
5805579
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 24, 2021
e2612a9
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 24, 2021
55e82fa
Details Message
elor555 Feb 25, 2021
c422398
Details Message
elor555 Feb 25, 2021
a027151
Details Message
elor555 Feb 25, 2021
d07f516
Details Message
elor555 Feb 25, 2021
e49b624
Merge remote-tracking branch 'upstream/develop' into feature/shabbatime
elor555 Feb 25, 2021
d1da1f3
fix: flake8
elor555 Feb 25, 2021
00450c3
fix: many code improvements
elor555 Feb 25, 2021
1d21cd2
fix: many code improvements
elor555 Feb 25, 2021
10e5b04
fix: style improvements
elor555 Feb 25, 2021
5ef54f1
Merge remote-tracking branch 'upstream/develop' into feature/shabbatime
elor555 Feb 26, 2021
48cae11
fix: improvments
elor555 Feb 26, 2021
2e8be84
fix: improvments
elor555 Feb 26, 2021
7a4c32c
fix: improvments
elor555 Feb 26, 2021
e519138
fix: BUGFIX
elor555 Feb 26, 2021
6c580dd
fix: BUGFIX
elor555 Feb 26, 2021
ea4e41b
fix: STYLE
elor555 Feb 26, 2021
b0bb745
fix: bugfix
elor555 Feb 27, 2021
8fea1f5
fix: bugfix
elor555 Feb 27, 2021
bc9f14f
Merge remote-tracking branch 'upstream/develop' into feature/shabbatime
elor555 Mar 1, 2021
50c42d2
fix: improvment
elor555 Mar 1, 2021
1c743c3
fix: bugfix
elor555 Mar 2, 2021
935a9de
fix: bugfix
elor555 Mar 2, 2021
4c6a434
fix: bugfix
elor555 Mar 2, 2021
c8cf12f
fix: bugfix
elor555 Mar 3, 2021
bf56e9b
fix : adding information
elor555 Mar 3, 2021
f89ea45
fix : bugfix
elor555 Mar 3, 2021
ba2f35c
fix : bugfix
elor555 Mar 3, 2021
421e70b
fix : bugfix
elor555 Mar 10, 2021
8d3e106
fix : bugfix
elor555 Mar 10, 2021
9e22801
fix : bugfix
elor555 Mar 10, 2021
7313c85
fix : bugfix
elor555 Mar 10, 2021
855a871
fix : bugfix
elor555 Mar 11, 2021
b7c8067
fix : bugfix
elor555 Mar 11, 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
9 changes: 9 additions & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ class InternationalDays(Base):
international_day = Column(String, nullable=False)


class Location(Base):
__tablename__ = "locations"

id = Column(Integer, primary_key=True, index=True)
country = Column(String, nullable=False)
city = Column(String, nullable=False)
zip_number = Column(String, nullable=False)


# insert language data

# Credit to adrihanu https://stackoverflow.com/users/9127249/adrihanu
Expand Down
24 changes: 18 additions & 6 deletions app/internal/json_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
from loguru import logger
from sqlalchemy.orm import Session

from app.database.models import Base, InternationalDays, Joke, Quote, Zodiac
from app.internal import daily_quotes, international_days, jokes, zodiac
from app.config import RESOURCES_DIR
from app.database.models import (
Base, InternationalDays, Joke, Quote, Location, Zodiac
)
from app.internal import (
daily_quotes, international_days, jokes, locations, zodiac
)


def load_to_database(session: Session) -> None:
Expand All @@ -23,28 +28,35 @@ def load_to_database(session: Session) -> None:
"""
_insert_into_database(
session,
'app/resources/zodiac.json',
RESOURCES_DIR / "zodiac.json",
Zodiac,
zodiac.get_zodiac,
)

_insert_into_database(
session,
'app/resources/quotes.json',
RESOURCES_DIR / "quotes.json",
Quote,
daily_quotes.get_quote,
)

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

_insert_into_database(
session,
'app/resources/jokes.json',
RESOURCES_DIR / "locations.json",
Location,
locations.create_location_object,
)

_insert_into_database(
session,
RESOURCES_DIR / "jokes.json",
Joke,
jokes.get_joke,
)
Expand Down
54 changes: 54 additions & 0 deletions app/internal/locations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import requests
from typing import Dict

from sqlalchemy.orm import Session

from app.database.models import Location


def create_location_object(location_: Dict[str, str]) -> Location:
"""Returns a Zodiac object from the dictionary data.

Args:
location_: A dictionary location related information.

Returns:
A new Location object.
"""
return Location(
country=location_['country'],
city=location_['city'],
zip_number=location_['zip_number'],
)


def return_zip_to_location(session: Session) -> str:
"""Returns the zip number of the user IP location that match location object.

Args:
session: The database connection.

Returns:
A zip number for the user location.
"""
ip_and_location = requests.get('http://ipinfo.io/json').json()
for location in session.query(Location).all():
if location.city == ip_and_location['city'] and \
location.country == ip_and_location['country']:
return location.zip_number


def get_user_location(session: Session) -> str:
"""Returns the user location.

Args:
session: The database connection.

Returns:
A user location string.
"""
my_location = return_zip_to_location(session)
location_details = requests.get(
f"https://www.hebcal.com/shabbat?cfg=json&geonameid={my_location}"
)
return location_details.json()
41 changes: 41 additions & 0 deletions app/internal/shabbat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from typing import Dict
from datetime import datetime


def shabbat_time_by_user_location(shabbat_time: Dict[str, str]) -> Dict:
"""Returns the shabbat time of the user location..

Args:
Shabbat details.

Returns:
Shabbat start end ending time.
"""
shabbat_limit = {
'start_hour': shabbat_time['items'][5]['title'].split(': ')[1],
'start_date': datetime.strptime(
shabbat_time['items'][5]['date'].split('T')[0], "%Y-%m-%d"
).date(),
'end_hour': shabbat_time['items'][7]['title'].split(': ')[1],
'end_date': datetime.strptime(
shabbat_time['items'][7]['date'].split('T')[0], "%Y-%m-%d"
).date()}
return shabbat_limit


def get_shabbat_if_date_friday(
shabbat_time: Dict[str, str],
date: datetime) -> Dict:
"""Returns shabbat start end ending time if specific date
is Saturday, else None.

Args:
Shabbat details and date.

Returns:
Shabbat start end ending time if specific date
is Saturday, else None
"""
shabbat_obj = shabbat_time_by_user_location(shabbat_time)
if date == shabbat_obj['start_date']:
return shabbat_obj
Loading