コード例 #1
0
def fetch_centre_slots(rdv_site_web, start_date, fetch_map: dict = None):
    if fetch_map is None:
        # Map platform to implementation.
        # May be overridden for unit testing purposes.
        fetch_map = {
            'Doctolib': {
                'urls':
                ['https://partners.doctolib.fr', 'https://www.doctolib.fr'],
                'scraper_ptr': doctolib_fetch_slots
            },
            'Keldoc': {
                'urls':
                ['https://vaccination-covid.keldoc.com', 'https://keldoc.com'],
                'scraper_ptr':
                keldoc_fetch_slots
            },
            'Maiia': {
                'urls': ['https://www.maiia.com'],
                'scraper_ptr': maiia_fetch_slots
            },
            'Mapharma': {
                'urls': [
                    'https://mapharma.net/',
                ],
                'scraper_ptr': mapharma_fetch_slots
            },
            'Ordoclic': {
                'urls': [
                    'https://app.ordoclic.fr/',
                ],
                'scraper_ptr': ordoclic_fetch_slots
            }
        }

    rdv_site_web = fix_scrap_urls(rdv_site_web)
    request = ScraperRequest(rdv_site_web, start_date)

    # Determine platform based on visit URL
    platform = None
    for scraper_name in fetch_map:
        scraper = fetch_map[scraper_name]
        scrap = sum([
            1 if rdv_site_web.startswith(url) else 0
            for url in scraper.get('urls', [])
        ])
        if scrap == 0:
            continue
        platform = scraper_name

    if not platform:
        return ScraperResult(request, 'Autre', None)
    # Dispatch to appropriate implementation.
    fetch_impl = fetch_map[platform]['scraper_ptr']
    result = ScraperResult(request, platform, None)
    result.next_availability = fetch_impl(request)
    return result
コード例 #2
0
def fetch_centre_slots(rdv_site_web, start_date, fetch_map: dict = None):
    if fetch_map is None:
        # Map platform to implementation.
        # May be overridden for unit testing purposes.
        fetch_map = get_default_fetch_map()

    rdv_site_web = fix_scrap_urls(rdv_site_web)
    request = ScraperRequest(rdv_site_web, start_date)
    platform = get_center_platform(rdv_site_web, fetch_map=fetch_map)

    if not platform:
        return ScraperResult(request, "Autre", None)
    # Dispatch to appropriate implementation.
    fetch_impl = fetch_map[platform]["scraper_ptr"]
    result = ScraperResult(request, platform, None)
    result.next_availability = fetch_impl(request)
    return result
コード例 #3
0
def test_scraper_request():
    request = ScraperRequest("https://doctolib.fr/center/center-test", "2021-04-14")

    request.update_internal_id("d739")
    request.update_practitioner_type(GENERAL_PRACTITIONER)
    request.update_appointment_count(42)
    request.add_vaccine_type(get_vaccine_name("Injection pfizer 1ère dose"))

    assert request is not None
    assert request.internal_id == "d739"
    assert request.appointment_count == 42
    assert request.vaccine_type == [Vaccine.PFIZER]

    result = ScraperResult(request, "Doctolib", "2021-04-14T14:00:00.0000")
    assert result.default() == {
        "next_availability": "2021-04-14T14:00:00.0000",
        "platform": "Doctolib",
        "request": request,
    }
コード例 #4
0
def fetch_centre_slots(
    rdv_site_web,
    center_platform,
    start_date,
    creneau_q,
    center_info,
    fetch_map: dict = None,
    input_data: dict = None,
    atlas_gid=None,
) -> ScraperResult:
    practitioner_type = None
    internal_id = None
    if fetch_map is None:
        # Map platform to implementation.
        # May be overridden for unit testing purposes.
        fetch_map = get_default_fetch_map()
    if center_info.type:
        practitioner_type = center_info.type
    if center_info.internal_id:
        internal_id = center_info.internal_id
    rdv_site_web = fix_scrap_urls(rdv_site_web)
    request = ScraperRequest(
        rdv_site_web,
        start_date,
        center_info,
        internal_id=internal_id,
        practitioner_type=practitioner_type,
        atlas_gid=atlas_gid,
    )
    platform = get_center_platform(rdv_site_web,
                                   center_platform,
                                   fetch_map=fetch_map)

    if not platform:
        return ScraperResult(request, "Autre", None)
    if input_data:
        request.input_data = input_data
    # Dispatch to appropriate implementation.
    fetch_impl = fetch_map[platform]["scraper_ptr"]
    result = ScraperResult(request, platform, None)
    result.next_availability = fetch_impl(request, creneau_q)
    return result
コード例 #5
0
def test_scraper_request():
    request = ScraperRequest("https://doctolib.fr/center/center-test",
                             "2021-04-14")

    request.update_internal_id("d739")
    request.update_practitioner_type(GENERAL_PRACTITIONER)
    request.update_appointment_count(42)
    request.add_vaccine_type(get_vaccine_name("Injection pfizer 1ère dose"))

    assert request is not None
    assert request.internal_id == "d739"
    assert request.appointment_count == 42
    assert request.vaccine_type == ['Pfizer-BioNTech']

    result = ScraperResult(request, 'Doctolib', '2021-04-14T14:00:00.0000')
    assert result.default() == {
        'next_availability': '2021-04-14T14:00:00.0000',
        'platform': 'Doctolib',
        'request': request
    }
コード例 #6
0
def test_center_info_fill():
    center = CenterInfo("Paris", "Centre 1", "https://.../centre")
    newloc = CenterLocation(1.122, 2.391, "Ok", "Cp")
    request = ScraperRequest(center.url, "2021-05-04")
    result = ScraperResult(request, "Doctolib", "2021-05-06")
    center.fill_localization(newloc)
    request.update_appointment_count(42)
    request.add_vaccine_type(Vaccine.PFIZER)
    request.add_vaccine_type(Vaccine.ASTRAZENECA)
    request.add_vaccine_type(Vaccine.MODERNA)
    request.update_internal_id("doctolibcentre1")
    request.update_practitioner_type(DRUG_STORE)
    request.set_appointments_only_by_phone(False)
    center.fill_result(result)

    assert center.location == newloc
    assert center.prochain_rdv == "2021-05-06"
    assert center.plateforme == "Doctolib"
    assert center.type == "drugstore"
    assert center.appointment_count == 42
    assert center.internal_id == "doctolibcentre1"
    assert center.vaccine_type == ["Pfizer-BioNTech", "AstraZeneca", "Moderna"]
    assert not center.appointment_by_phone_only
    assert center.default() == {
        "departement": "Paris",
        "nom": "Centre 1",
        "url": "https://.../centre",
        "location": {
            "longitude": 1.122,
            "latitude": 2.391,
            "city": "Ok",
            "cp": "Cp"
        },
        "metadata": None,
        "prochain_rdv": "2021-05-06",
        "plateforme": "Doctolib",
        "type": "drugstore",
        "appointment_count": 42,
        "internal_id": "doctolibcentre1",
        "vaccine_type": ["Pfizer-BioNTech", "AstraZeneca", "Moderna"],
        "appointment_by_phone_only": False,
        "erreur": None,
        "last_scan_with_availabilities": None,
        "appointment_schedules": None,
        "request_counts": None,
    }
コード例 #7
0
def test_center_info_fill():
    center = CenterInfo("Paris", "Centre 1", "https://.../centre")
    newloc = CenterLocation(1.122, 2.391, "Ok")
    request = ScraperRequest(center.url, "2021-05-04")
    result = ScraperResult(request, "Doctolib", "2021-05-06")
    center.fill_localization(newloc)
    request.update_appointment_count(42)
    request.add_vaccine_type(Vaccine.PFIZER)
    request.add_vaccine_type(Vaccine.ASTRAZENECA)
    request.add_vaccine_type(Vaccine.MODERNA)
    request.update_internal_id("doctolibcentre1")
    request.update_practitioner_type(DRUG_STORE)
    request.set_appointments_only_by_phone(False)
    center.fill_result(result)

    assert center.location == newloc
    assert center.prochain_rdv == "2021-05-06"
    assert center.plateforme == "Doctolib"
    assert center.type == "drugstore"
    assert center.appointment_count == 42
    assert center.internal_id == "doctolibcentre1"
    assert center.vaccine_type == ["Pfizer-BioNTech", "AstraZeneca", "Moderna"]
    assert not center.appointment_by_phone_only
    assert center.default() == {
        'departement': 'Paris',
        'nom': 'Centre 1',
        'url': 'https://.../centre',
        'location': {
            'longitude': 1.122,
            'latitude': 2.391,
            'city': 'Ok'
        },
        'metadata': None,
        'prochain_rdv': '2021-05-06',
        'plateforme': 'Doctolib',
        'type': 'drugstore',
        'appointment_count': 42,
        'internal_id': 'doctolibcentre1',
        'vaccine_type': ['Pfizer-BioNTech', 'AstraZeneca', 'Moderna'],
        'appointment_by_phone_only': False,
        'erreur': None,
        'last_scan_with_availabilities': None,
        'appointment_schedules': None
    }