-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathhebrew_date_view.py
More file actions
34 lines (27 loc) · 986 Bytes
/
hebrew_date_view.py
File metadata and controls
34 lines (27 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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