Exemplo n.º 1
0
def get_slots(
    center_id: str,
    consultation_reason_name: str,
    start_date: str,
    end_date: str,
    limit=MAIIA_LIMIT,
    client: httpx.Client = DEFAULT_CLIENT,
) -> Optional[list]:
    url = f"{MAIIA_URL}/api/pat-public/availabilities?centerId={center_id}&consultationReasonName={consultation_reason_name}&from={start_date}&to={end_date}"
    availabilities = get_paged(url, limit=limit, client=client)["items"]
    if not availabilities:
        next_slot_date = get_next_slot_date(center_id,
                                            consultation_reason_name,
                                            start_date,
                                            client=client)
        if not next_slot_date:
            return None
        next_date = datetime.strptime(next_slot_date, "%Y-%m-%dT%H:%M:%S.%fZ")
        if next_date - isoparse(start_date) > timedelta(days=MAIIA_DAY_LIMIT):
            return None
        start_date = next_date.isoformat()
        url = f"{MAIIA_URL}/api/pat-public/availabilities?centerId={center_id}&consultationReasonName={consultation_reason_name}&from={start_date}&to={end_date}"
        availabilities = get_paged(url, limit=limit, client=client)["items"]
    if availabilities:
        return availabilities
    return None
Exemplo n.º 2
0
 def get_slots(
     self,
     center_id: str,
     consultation_reason_name: str,
     start_date: str,
     end_date: str,
     limit=MAIIA_LIMIT,
     client: httpx.Client = DEFAULT_CLIENT,
     request: ScraperRequest = None,
 ) -> Optional[list]:
     url = PLATFORM_API.get("slots").format(
         center_id=center_id,
         consultation_reason_name=consultation_reason_name,
         start_date=start_date,
         end_date=end_date,
     )
     availabilities = get_paged(url,
                                limit=limit,
                                client=client,
                                request=request,
                                request_type="slots")["items"]
     if not availabilities:
         next_slot_date = self.get_next_slot_date(center_id,
                                                  consultation_reason_name,
                                                  start_date,
                                                  client=client,
                                                  request=request)
         if not next_slot_date:
             return None
         next_date = dt.datetime.strptime(next_slot_date,
                                          "%Y-%m-%dT%H:%M:%S.%fZ")
         if next_date - isoparse(start_date) > dt.timedelta(
                 days=NUMBER_OF_SCRAPED_DAYS):
             return None
         start_date = next_date.isoformat()
         url = PLATFORM_API.get("slots").format(
             center_id=center_id,
             consultation_reason_name=consultation_reason_name,
             start_date=start_date,
             end_date=end_date,
         )
         availabilities = get_paged(url,
                                    limit=limit,
                                    client=client,
                                    request=request,
                                    request_type="slots")["items"]
     if availabilities:
         return availabilities
     return None
Exemplo n.º 3
0
def get_slots(center_id: str, consultation_reason_name: str, start_date: str, end_date: str, limit=MAIIA_LIMIT, client: httpx.Client = DEFAULT_CLIENT) -> Optional[list]:
    url = f'{MAIIA_URL}/api/pat-public/availabilities?centerId={center_id}&consultationReasonName={consultation_reason_name}&from={start_date}&to={end_date}'
    availabilities = get_paged(url, limit=limit, client=client)['items']
    if not availabilities:
        next_slot_date = get_next_slot_date(
            center_id, consultation_reason_name, start_date, client=client)
        if not next_slot_date:
            return None
        next_date = datetime.strptime(next_slot_date, '%Y-%m-%dT%H:%M:%S.%fZ')
        start_date = datetime.strftime(next_date, '%Y-%m-%dT%H:%M:%S.%f%zZ')
        end_date = (next_date + timedelta(days=MAIIA_DAY_LIMIT)
                    ).strftime('%Y-%m-%dT%H:%M:%S.%f%zZ')
        url = f'{MAIIA_URL}/api/pat-public/availabilities?centerId={center_id}&consultationReasonName={consultation_reason_name}&from={start_date}&to={end_date}'
        availabilities = get_paged(url, limit=limit, client=client)['items']
    if availabilities:
        return availabilities
    return None
Exemplo n.º 4
0
def get_reasons(center_id: str,
                limit=MAIIA_LIMIT,
                client: httpx.Client = DEFAULT_CLIENT) -> list:
    url = f"{MAIIA_URL}/api/pat-public/consultation-reason-hcd?rootCenterId={center_id}"
    result = get_paged(url, limit=limit, client=client)
    if not result["total"]:
        return []
    return result.get("items", [])
Exemplo n.º 5
0
def get_reasons(center_id: str,
                limit=MAIIA_LIMIT,
                client: httpx.Client = DEFAULT_CLIENT,
                request: ScraperRequest = None) -> list:
    url = MAIIA_API.get("motives").format(center_id=center_id)
    result = get_paged(url,
                       limit=limit,
                       client=client,
                       request=request,
                       request_type="motives")
    if not result["total"]:
        return []
    return result.get("items", [])