add elad files
This commit is contained in:
31
utils.py
Normal file
31
utils.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import json
|
||||
import yaml
|
||||
import re
|
||||
|
||||
from constants import SERIES_NAME_YEAR_PATTERN
|
||||
|
||||
|
||||
def get_credentials():
|
||||
with open('credentials.yaml') as file:
|
||||
sdarot_credentials = yaml.full_load(file)
|
||||
return sdarot_credentials.get('username'), sdarot_credentials.get('password')
|
||||
|
||||
|
||||
def save_cookies(cookies):
|
||||
with open('cookie.json') as cookie_file:
|
||||
json.dump(cookies, cookie_file)
|
||||
|
||||
|
||||
def save_series_dictionary(series_json):
|
||||
with open('series.json', 'w') as file:
|
||||
json.dump(series_json, file)
|
||||
|
||||
|
||||
def get_matched_series_ids(series_dictionary, series_name):
|
||||
year = ''
|
||||
match = re.match(SERIES_NAME_YEAR_PATTERN, series_name)
|
||||
if match:
|
||||
series_name = match.group(1)
|
||||
year = match.group(2)
|
||||
return list(filter(lambda obj: (series_name in obj['eng'].lower() or series_name in obj['heb']) and year in obj['year'], series_dictionary))
|
||||
|
||||
Reference in New Issue
Block a user