Skip to content

Feature/HebrewView #280

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 71 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
33723a7
add hebrew dates to calendar-nre feature
elor555 Feb 14, 2021
0d296f3
add test to hebrew dates
elor555 Feb 14, 2021
970534d
edit flake8
elor555 Feb 14, 2021
f0bc588
edit flake8
elor555 Feb 14, 2021
7282e00
fix after pull
elor555 Feb 15, 2021
861587a
edit flake8
elor555 Feb 15, 2021
8426167
edit
elor555 Feb 15, 2021
6b28e84
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 15, 2021
fbdd7f5
edit
elor555 Feb 15, 2021
442a640
edit
elor555 Feb 15, 2021
e4720c8
check
elor555 Feb 16, 2021
fcefcbe
check
elor555 Feb 16, 2021
9e6742e
edit
elor555 Feb 17, 2021
c63471a
edit
elor555 Feb 17, 2021
97a1d8c
edit after flake8
elor555 Feb 17, 2021
201b1d8
edit after flake8
elor555 Feb 17, 2021
739729e
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 17, 2021
d79b1c3
edit after flake8
elor555 Feb 17, 2021
f488161
edit after flake8
elor555 Feb 17, 2021
3d2c150
edit after flake8
elor555 Feb 17, 2021
d873fd6
edit after flake8
elor555 Feb 17, 2021
7593c11
edit after pull
elor555 Feb 19, 2021
3dd122b
edit after pull
elor555 Feb 19, 2021
b06b7be
edit after pull
elor555 Feb 19, 2021
4dd3ac5
edit
elor555 Feb 20, 2021
6c2d65c
edit
elor555 Feb 20, 2021
f6b8607
edit
elor555 Feb 20, 2021
3c70a58
edit
elor555 Feb 20, 2021
6a34a33
edit
elor555 Feb 20, 2021
822ac9d
edit
elor555 Feb 20, 2021
0ae1726
edit
elor555 Feb 20, 2021
9e9ee25
edit
elor555 Feb 20, 2021
0a8b157
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 21, 2021
ac73386
edit
elor555 Feb 21, 2021
426da0a
edit
elor555 Feb 21, 2021
63c437a
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 21, 2021
4ae0595
edit
elor555 Feb 21, 2021
f2323d6
edit
elor555 Feb 22, 2021
9fd7cbc
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 23, 2021
1c52fbd
edit
elor555 Feb 23, 2021
0abd915
edit
elor555 Feb 23, 2021
ad7ea1a
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 23, 2021
78278bc
edit
elor555 Feb 23, 2021
e8c1776
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 23, 2021
d2573b1
edit
elor555 Feb 23, 2021
d6b58f0
edit
elor555 Feb 23, 2021
7af9582
edit
elor555 Feb 23, 2021
a3b0b95
edit
elor555 Feb 23, 2021
be3ce04
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 24, 2021
408de5d
edit
elor555 Feb 24, 2021
848368f
edit
elor555 Feb 24, 2021
3e96b8b
edit
elor555 Feb 24, 2021
34ebe6e
edit
elor555 Feb 24, 2021
4fa9da5
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 24, 2021
a64fcd9
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 25, 2021
3b1a6be
Details Message
elor555 Feb 25, 2021
ed58474
Details Message
elor555 Feb 25, 2021
22f0bcc
fix: flake8
elor555 Feb 25, 2021
1a1eb3d
fix: flake8
elor555 Feb 25, 2021
7d6ec9b
fix: bug fix
elor555 Feb 25, 2021
18a0195
fix: bug fix
elor555 Feb 25, 2021
c022096
fix: bug fix
elor555 Feb 25, 2021
44f9d61
fix: fix translation files
elor555 Feb 25, 2021
76726e1
Merge remote-tracking branch 'upstream/develop' into feature/hebrewview
elor555 Feb 27, 2021
a2449d2
fix: bugfix
elor555 Mar 1, 2021
c7d3b7d
fix: bugfix
elor555 Mar 1, 2021
11fc0d6
fix: bugfix
elor555 Mar 1, 2021
377e82d
fix: bugfix
elor555 Mar 1, 2021
9b0c629
fix: styling
elor555 Mar 1, 2021
0a9a4fb
fix: bugfix
elor555 Mar 2, 2021
c48a270
fix: bugfix
elor555 Mar 2, 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
29 changes: 29 additions & 0 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,33 @@ def __repr__(self):
)


class HebrewView(Base):
"""Each year the Json file will need to be re-updated
according to this API in this way:
def relevent_details(hebrew_date):
hebrew_dates_dict = {
'date_gregorian': hebrew_date['date'],
'date_hebrew': hebrew_date['hebrew']}
return hebrew_dates_dict


def get_all_hebrew_dates():
request = requests.get(
'https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&
min=on&mod=on&nx=on&year=now&month=x&ss=on&mf=on&
c=on&geo=geoname&geonameid=293397&m=50&s=on&d=on&D=on')
items = request.json()['items']
return[
relevent_details(hebrew_date) for hebrew_date in items
if 'hebdate' in hebrew_date['category]]
"""
__tablename__ = "hebrewView"

id = Column(Integer, primary_key=True, index=True)
date = Column(DateTime, nullable=False)
hebrew_date = Column(String, nullable=False)


class Joke(Base):
__tablename__ = "jokes"

Expand All @@ -396,6 +423,8 @@ class Joke(Base):

# Credit to adrihanu https://stackoverflow.com/users/9127249/adrihanu
# https://stackoverflow.com/questions/17461251


def insert_data(target, session: Session, **kw):
session.execute(
target.insert(),
Expand Down
34 changes: 34 additions & 0 deletions app/internal/hebrew_date_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from datetime import datetime
from typing import Dict, Optional

from app.database.models import HebrewView
from sqlalchemy.orm import Session


def create_hebrew_dates_object(
hebrew_dates_fields: Dict[str, Optional[str]])\
-> HebrewView:
"""This function create a hebrew date object
from given fields dictionary.
It is used for adding the data from the json into the db"""
return HebrewView(
date=datetime.strptime(
hebrew_dates_fields['date_gregorian'],
'%Y-%m-%d').date(),
hebrew_date=hebrew_dates_fields['date_hebrew']
)


def get_hebrew_date_object(session: Session, date: datetime) -> HebrewView:
"""Returns the HebrewView object for the specific day.

Args:
session: The database connection.
date: The requested date.

Returns:
A HebrewView object.
"""
for hebrew in session.query(HebrewView).all():
if hebrew.date == date:
return hebrew
20 changes: 16 additions & 4 deletions app/internal/json_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
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, HebrewView, Joke, Quote, Zodiac
from app.internal import daily_quotes, hebrew_date_view, jokes, zodiac


def load_to_database(session: Session) -> None:
"""Loads data from JSON data files into the database.

On startup, data from the JSON files should be added to the database and
not be accessed from a network call for each request as it is costly.

The quotes JSON file content is copied from the free API:
'https://type.fit/api/quotes'.
The parashot and hebrew_view JSON files content is copied
from the free API:
'https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&min=on&
mod=on&nx=on&year=now&month=x&ss=on&mf=on&c=on&geo=geoname
&geonameid=293397&m=50&s=on&d=on&D=on'.

Args:
session: The database connection.
Expand All @@ -35,6 +40,13 @@ def load_to_database(session: Session) -> None:
daily_quotes.get_quote,
)

_insert_into_database(
session,
'app/resources/hebrew_view.json',
HebrewView,
hebrew_date_view.create_hebrew_dates_object,
)

_insert_into_database(
session,
'app/resources/jokes.json',
Expand Down Expand Up @@ -97,7 +109,7 @@ def _get_data_from_json(path: str) -> List[Dict[str, Any]]:
A list of dictionary objects.
"""
try:
with open(path, 'r') as json_file:
with open(path, 'r', encoding='utf-8-sig') as json_file:
json_content = json.load(json_file)
except (IOError, ValueError):
file_name = os.path.basename(path)
Expand Down
9 changes: 5 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def create_tables(engine, psql_environment):
set_ui_language()

from app.routers import ( # noqa: E402
about_us, agenda, calendar, categories, celebrity, credits,
currency, dayview, email, event, export, four_o_four, friendview,
google_connect, invitation, joke, login, logout, profile,
register, search, telegram, user, weekview, weight, whatsapp,
about_us, agenda, calendar, categories, celebrity,
credits, currency, dayview, email, event, export,
four_o_four, friendview, google_connect, invitation,
joke, login, logout, profile, register, search, telegram,
user, weekview, weight, whatsapp,
)

json_data_loader.load_to_database(next(get_db()))
Expand Down
Loading