Skip to content

Commit

Permalink
Deleted newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitri committed Nov 22, 2024
1 parent 331ab58 commit 1e6fbe4
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions services/sources/publisher_backlist_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from mappings.UofM import UofMMapping
from .source_service import SourceService


logger = create_log(__name__)

BASE_URL = "https://api.airtable.com/v0/appBoLf4lMofecGPU/Publisher%20Backlists%20%26%20Collections%20%F0%9F%93%96?view=All%20Lists"
Expand All @@ -25,18 +24,16 @@ def get_records(
offset: Optional[int]=None,
limit: Optional[int]=None
) -> list[UofMMapping]:

array_json_records = self.get_records_json(full_import, start_timestamp, offset, limit)


for json_dict in array_json_records:
for records_value in json_dict['records']:
try:
record_metadata_dict = records_value
record = UofMMapping(record_metadata_dict)
record.applyMapping()
except Exception as e:
logger.exception(f'Failed to process Publisher Backlist record due to {e}')
except Exception:
logger.exception(f'Failed to process Publisher Backlist record')
return array_json_records

def get_records_json(self,
Expand All @@ -45,34 +42,27 @@ def get_records_json(self,
offset: Optional[int]=None,
limit: Optional[int]=None
) -> list[dict]:

if offset == None:
limit = 100

headers = {"Authorization": f"Bearer {self.airtable_auth_token}"}

if not full_import:
if start_timestamp:

filter_by_formula = self.build_filter_by_formula_parameter(start_timestamp)

array_json_records = self.get_records_array(headers, limit, filter_by_formula)
array_json_records = self.get_records_array(limit, filter_by_formula)

return array_json_records

else:

filter_by_formula = self.build_filter_by_formula_parameter(start_timestamp)

array_json_records = self.get_records_array(headers, limit, filter_by_formula)

return array_json_records

else:
array_json_records = self.get_records_array(limit, filter_by_formula)

array_json_records = self.get_records_array(headers, limit, filter_by_formula=None)
return array_json_records

array_json_records = self.get_records_array(limit, filter_by_formula=None)

return array_json_records
return array_json_records

def build_filter_by_formula_parameter(self, start_timestamp: datetime=None) -> str:
if not start_timestamp:
Expand All @@ -86,13 +76,12 @@ def build_filter_by_formula_parameter(self, start_timestamp: datetime=None) -> s

return filter_by_formula

def get_records_array(self,
headers: Dict[str, str],
def get_records_array(self,
limit: Optional[int]=None,
filter_by_formula: str=None,
) -> list[dict]:

url = f'{BASE_URL}&pageSize={limit}'
headers = {"Authorization": f"Bearer {self.airtable_auth_token}"}

if filter_by_formula:
url += f'&filterByFormula{filter_by_formula}'
Expand Down

0 comments on commit 1e6fbe4

Please sign in to comment.