Skip to content

Feature/parasha #260

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 88 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
25ad676
add parasha feature
elor555 Feb 11, 2021
eed8d7c
update
elor555 Feb 11, 2021
eaadce0
update
elor555 Feb 11, 2021
ecff42d
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 11, 2021
1b1faf2
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 11, 2021
5646a56
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 13, 2021
407d692
ines starting
elor555 Feb 13, 2021
3ea2768
dd space
elor555 Feb 13, 2021
c3aa08a
fix farts of flake8
elor555 Feb 13, 2021
819f2b2
edit
elor555 Feb 13, 2021
e5bfc87
edit
elor555 Feb 13, 2021
75805fc
edit5
elor555 Feb 13, 2021
91fff6f
edit6
elor555 Feb 13, 2021
161cb98
edit api
elor555 Feb 13, 2021
91b9fe3
edit by yam
elor555 Feb 14, 2021
cde7aa6
edit by yam2
elor555 Feb 14, 2021
0ab998e
edit flake8
elor555 Feb 14, 2021
e53c37d
edit flake8
elor555 Feb 14, 2021
2f7b60a
edit flake8
elor555 Feb 14, 2021
433539f
edit flake8
elor555 Feb 14, 2021
58988ba
edit pytest
elor555 Feb 14, 2021
871a6d0
edit
elor555 Feb 15, 2021
5cb60fe
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 15, 2021
eca6849
edit flake8
elor555 Feb 15, 2021
032e204
edit flake8
elor555 Feb 15, 2021
6ae3d97
edit after pull
elor555 Feb 16, 2021
05bf66f
edit after flake8
elor555 Feb 16, 2021
9999ac1
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 16, 2021
497a365
edit after pytest
elor555 Feb 16, 2021
18ed51d
edit after pytest
elor555 Feb 16, 2021
8d7a6c1
edit after pytest
elor555 Feb 16, 2021
b072699
edit after pytest
elor555 Feb 16, 2021
60386ce
edit after pytest
elor555 Feb 16, 2021
2044f70
edit after pytest
elor555 Feb 16, 2021
992841a
edit after pytest
elor555 Feb 16, 2021
f588ded
edit after pytest
elor555 Feb 16, 2021
76472c1
edit after pytest
elor555 Feb 16, 2021
1a2ba69
edit after pytest
elor555 Feb 16, 2021
c4c7227
edit after pytest
elor555 Feb 16, 2021
3042a61
check
elor555 Feb 16, 2021
8fbee77
edit after comments
elor555 Feb 16, 2021
2c16624
edit after flake8
elor555 Feb 16, 2021
e08ee63
edit after pytest
elor555 Feb 16, 2021
900d4c5
edit after pytest
elor555 Feb 16, 2021
d734bc1
edit after pytest
elor555 Feb 16, 2021
bee1cbc
edit after pytest
elor555 Feb 16, 2021
f5b8368
edit after pytest
elor555 Feb 16, 2021
48b3c62
edit after flake8
elor555 Feb 17, 2021
1b5d932
edit after flake8
elor555 Feb 17, 2021
495539b
edit after pull
elor555 Feb 17, 2021
bd77d76
edit after pull
elor555 Feb 18, 2021
e1d6e74
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 18, 2021
9754ba2
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 18, 2021
b132c7a
edit after pull
elor555 Feb 19, 2021
c4093e1
edit after pull
elor555 Feb 19, 2021
ba8d840
edit after pull
elor555 Feb 19, 2021
35722bc
edit after pull
elor555 Feb 19, 2021
c6c01fb
edit after pull
elor555 Feb 19, 2021
535844e
edit after pull
elor555 Feb 19, 2021
9d0277e
edit
elor555 Feb 20, 2021
d116f25
edit
elor555 Feb 21, 2021
1d50cb1
edit
elor555 Feb 21, 2021
4c16f61
edit
elor555 Feb 21, 2021
15d0e04
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 21, 2021
17340f8
edit
elor555 Feb 21, 2021
4ee3beb
edit
elor555 Feb 21, 2021
66dc75e
edit
elor555 Feb 21, 2021
21b8033
edit
elor555 Feb 21, 2021
66b4457
edit
elor555 Feb 21, 2021
fdc0219
edit
elor555 Feb 21, 2021
0fd6e7e
edit
elor555 Feb 22, 2021
f011437
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 23, 2021
60ce6ce
edit
elor555 Feb 23, 2021
d9b1745
edit
elor555 Feb 23, 2021
ee9faf7
edit
elor555 Feb 23, 2021
59c61e6
edit
elor555 Feb 23, 2021
a3099f4
edit
elor555 Feb 23, 2021
108e152
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
elor555 Feb 24, 2021
4729f27
Details Message
elor555 Feb 24, 2021
5d27e04
Details Message
elor555 Feb 24, 2021
9f14957
Merge remote-tracking branch 'upstream/develop' into feature/parasha
elor555 Feb 25, 2021
122574f
fix: style improvements
elor555 Feb 25, 2021
1421c19
fix: style improvements
elor555 Feb 25, 2021
52df059
fix: improvments
elor555 Feb 26, 2021
8714224
Details Message
elor555 Feb 26, 2021
09aceb1
fix: improvments
elor555 Feb 26, 2021
baf06ac
Merge remote-tracking branch 'upstream/develop' into feature/parasha
elor555 Mar 1, 2021
6d430ed
fix: styling
elor555 Mar 1, 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
43 changes: 37 additions & 6 deletions app/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ class Category(Base):

@staticmethod
def create(
db_session: Session,
session: Session,
name: str,
color: str,
user_id: int,
) -> Category:
try:
category = Category(name=name, color=color, user_id=user_id)
db_session.add(category)
db_session.flush()
db_session.commit()
db_session.refresh(category)
session.add(category)
session.flush()
session.commit()
session.refresh(category)
except (SQLAlchemyError, IntegrityError) as e:
logger.error(f"Failed to create category: {e}")
raise e
Expand Down Expand Up @@ -382,8 +382,39 @@ def __repr__(self):
)


# insert language data
class Parasha(Base):
"""
Each year the Json file will need to be re-updated
according to this API in this way:

def relevent_details(parasha):
parashot_dict = {
'name': parasha['title'],
'hebrew': parasha['hebrew'],
'link': parasha['link'],
'date': parasha['date']}
return parashot_dict


def get_all_parashot():
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']
[relevent_details(p) for parasha in items
if 'Parashat' in parasha['title]]
"""
__tablename__ = "parashot"

id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
hebrew_name = Column(String, nullable=False)
link = Column(String, nullable=False)
date = Column(DateTime, nullable=False)


# insert language data
# Credit to adrihanu https://stackoverflow.com/users/9127249/adrihanu
# https://stackoverflow.com/questions/17461251
def insert_data(target, session: Session, **kw):
Expand Down
31 changes: 17 additions & 14 deletions app/internal/json_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
from loguru import logger
from sqlalchemy.orm import Session

from app.database.models import Base, Quote, Zodiac
from app.internal import daily_quotes, zodiac
from app.database.models import Base, Quote, Zodiac, Parasha
from app.internal import daily_quotes, zodiac, weekly_parasha


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.

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 +38,13 @@ def load_to_database(session: Session) -> None:
daily_quotes.get_quote,
)

_insert_into_database(
session,
'app/resources/parashot.json',
Parasha,
weekly_parasha.create_parasha_object,
)


def _insert_into_database(
session: Session,
Expand All @@ -43,13 +53,11 @@ def _insert_into_database(
model_creator: Callable
) -> bool:
"""Inserts the extracted JSON data into the database.

Args:
session: The database connection.
path: The file path.
table: A model entity table.
model_creator: A model creation function.

Returns:
True if the save was successful, otherwise returns False.
"""
Expand All @@ -66,11 +74,9 @@ def _insert_into_database(

def _is_table_empty(session: Session, table: Base) -> bool:
"""Returns True if the table is empty.

Args:
session: The database connection.
table: A model entity table.

Returns:
True if the table is empty, otherwise returns False.
"""
Expand All @@ -79,13 +85,10 @@ def _is_table_empty(session: Session, table: Base) -> bool:

def _get_data_from_json(path: str) -> List[Dict[str, Any]]:
"""Returns a list of dictionary objects.

Reads the data from a specific JSON file and converts the data into
a list of dictionary items.

Args:
path: The file path.

Returns:
A list of dictionary objects.
"""
Expand Down
23 changes: 23 additions & 0 deletions app/internal/weekly_parasha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import datetime
from typing import Dict, Optional, List

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


def create_parasha_object(parashot_fields: Dict[str, Optional[str]])\
-> Parasha:
"""This function create a parasha object from given fields dictionary.
It is used for adding the data from the json into the db"""
return Parasha(
name=parashot_fields['name'],
hebrew_name=parashot_fields['hebrew'],
link=parashot_fields['link'],
date=datetime.strptime(parashot_fields['date'], '%Y-%m-%d').date()
)


def get_all_parahot_list(session: Session) \
-> List[Dict[str, Optional[str]]]:
"""This function return all parashot object in list"""
return session.query(Parasha).all()
10 changes: 6 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ 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, login, logout, profile,
register, search, telegram, user, weekview, whatsapp,
about_us, agenda, calendar, categories, celebrity,
credits, currency, dayview, email, event, export,
four_o_four, friendview, google_connect, invitation,
login, logout, profile, register, search, telegram,
user, weekview, whatsapp,
)


json_data_loader.load_to_database(next(get_db()))


Expand Down
Loading