def _get_contacts(site: dict): ret = [] if site["Appointment Phone"] != "": ret.extend(_parse_phone_numbers(site["Appointment Phone"])) url = site["Web Address"] # Some URLs have multiple schemes. valid_url = re.match(r"(https?:\/\/)*(.+)", url) if ( url == "http://" or url == "https://" or url == "none" or url == "" or url.startswith("Please email") ): return ret elif valid_url is not None: if valid_url.group(1) is None: url = valid_url.group(2) else: url = f"{valid_url.group(1)}{valid_url.group(2)}" url = normalize_url(url) ret.append(schema.Contact(website=url)) else: logger.warning(f"Unknown, invalid URL: {url}") return ret
def normalize(site: dict) -> schema.NormalizedLocation: """Converts the parsed `site` into a normalized site location.""" name = site.get("name") address = schema.Address( street1=site.get("street1"), street2=site.get("street2"), city=site.get("city"), state=site.get("state"), zip=normalize_zip(site.get("zip")), ) source = schema.Source( source=_SOURCE_NAME, id=_generate_id(name, address), fetched_from_uri=normalize_url(site.get("fetched_from_uri")), published_at=_normalize_date_string(site.get("published_at")), data=site, ) county = site.get("county") opening_times = _normalize_opening_times(site.get("opening_times")) normalized_site = schema.NormalizedLocation( name=name, id=_make_site_id(source), source=source, address=address, active=True, # this source updates weekly opening_dates=opening_times[0] if opening_times else None, opening_hours=opening_times[1] if opening_times else None, notes=[county] if county else None, ) return normalized_site
def _normalize_websites(maybe_websites: str) -> List[str]: websites = [] for website in maybe_websites.lower().split(" "): if not re.match(r"https?://", website): if website[0:4] == "www." or re.match(r"\.(com|net|org|gov)", website[:-4]): website = "http://" + website if re.match(r"https?://", website): websites.append(normalize_url(website)) return websites
def _get_contacts(site: dict) -> Optional[List[schema.Contact]]: contacts = [] phones = normalize_phone(site["attributes"]["phone"]) contacts.extend(phones) website = normalize_url(site["attributes"]["website"]) if website is not None: contacts.append( schema.Contact(website=website, contact_type=schema.ContactType.GENERAL)) if len(contacts) > 0: return contacts return None
def _get_contacts(site: dict) -> List[schema.Contact]: ret = [] for raw_phone in site["phoneNumber"]: general_phone = _normalize_phone(raw_phone) if general_phone is not None and "?" not in general_phone: ret.append(schema.Contact(phone=general_phone, contact_type="general")) for website in site["website"]: ret.append(schema.Contact(website=website, contact_type="general")) scheduling_info_raw = site["schedulingInfo"] website_matches = re.search('href="(http.*)"', scheduling_info_raw) if website_matches: website = website_matches.group(1).split(" ")[0] website = website.replace('"', "") # remove quote marks from urls website = normalize_url(website) else: website = None phone_matches = re.search( "tel:([-() \\d]*)", scheduling_info_raw.replace("\u2013", "-") ) # .replace() replaces en dash with ASCII '-', for better regex if phone_matches: raw_phone = phone_matches.group(1) else: phone_matches = re.search( "(\\d\\d\\d-\\d\\d\\d-\\d\\d\\d\\d)", scheduling_info_raw.replace("\u2013", "-"), ) # .replace() replaces en dash with ASCII '-', for better regex if phone_matches: raw_phone = phone_matches.group(1) elif "1-800-Walgreens" in scheduling_info_raw: raw_phone = "(800) 925-4733" else: raw_phone = "" booking_phone = _normalize_phone(raw_phone) if booking_phone is not None and "?" not in booking_phone: ret.append(schema.Contact(contact_type="booking", phone=booking_phone)) if website is not None: ret.append(schema.Contact(contact_type="booking", website=website)) ret.append(schema.Contact(contact_type="booking", other=scheduling_info_raw)) return ret
def _get_contacts(site: dict) -> Optional[List[schema.Contact]]: contacts = [] if site["attributes"]["USER_Scheduling_by_Phone"]: for phone in normalize_phone( site["attributes"]["USER_Scheduling_by_Phone"]): contacts.append(phone) if site["attributes"]["USER_Link_to_Sign_Up"]: url = site["attributes"]["USER_Link_to_Sign_Up"].strip() if url is not None and url != "\x08" and url != "-": url = normalize_url(url) contacts.append(schema.Contact(website=url)) if len(contacts) > 0: return contacts return None
def _get_contacts(site: dict) -> Optional[List[schema.Contact]]: contacts = [] if site["attributes"]["USER_Scheduling_by_Phone"]: sourcePhone = re.sub( "[^0-9]", "", site["attributes"]["USER_Scheduling_by_Phone"] ) if len(sourcePhone) == 10: phone = f"({sourcePhone[0:3]}) {sourcePhone[3:6]}-{sourcePhone[6:]}" contacts.append(schema.Contact(phone=phone)) if site["attributes"]["USER_Link_to_Sign_Up"]: url = site["attributes"]["USER_Link_to_Sign_Up"].strip() if url is not None and url != "\x08" and url != "-": url = normalize_url(url) contacts.append(schema.Contact(website=url)) if len(contacts) > 0: return contacts return None
def _get_contacts(site: dict) -> Optional[List[schema.Contact]]: contacts = [] if "phone" in site["contact"] and re.match(r"^\(\d{3}\) \d{3}-\d{4}$", site["contact"]["phone"]): contacts.append( schema.Contact(contact_type="general", phone=site["contact"]["phone"])) if "website" in site["contact"]: uri = site["contact"]["website"] if uri[0:7] == "mailto:": contacts.append( schema.Contact(contact_type="general", email=uri[7:])) else: contacts.append( schema.Contact(contact_type="general", website=normalize_url(uri))) if len(contacts) > 0: return contacts return None
logger = getLogger(__file__) def _get_id(site: dict) -> str: return site["attributes"]["globalid"] def _get_contacts(site: dict) -> Optional[List[schema.Contact]]: ret = [] if phone := site["attributes"]["phone"]: ret.extend(normalize_phone(phone)) if email := site["attributes"]["publicEmail"]: ret.append(schema.Contact(email=email)) if website := site["attributes"]["publicWebsite"]: ret.append(schema.Contact(website=normalize_url(website))) return ret def _get_availability(site: dict) -> Optional[schema.Availability]: if site["attributes"]["flu_walkins"] == "no_please_make_an_appointment": return schema.Availability(drop_in=False) return None def _get_inventory(site: dict) -> Optional[List[schema.Vaccine]]: vaccine_names = [ ("pfizer", schema.VaccineType.PFIZER_BIONTECH), ("moderna", schema.VaccineType.MODERNA), ("jjj", schema.VaccineType.JOHNSON_JOHNSON_JANSSEN), ]
def _make_website_contact(url: Optional[Text]) -> Optional[schema.Contact]: """Returns a `schema.Contact` object for the given booking URL, if any.""" normalized_url = normalize_url(url) if normalized_url: return schema.Contact(contact_type="booking", website=normalized_url) return None
# it must be an invalid URL return None url = re.sub(r"^(https?)\/:([^\/:].*)", r"\g<1>://\g<2>", url) url = re.sub(r"^(https?:\/)([^\/].*)", r"\g<1>/\g<2>", url) return url def _get_contacts(site: dict) -> Optional[List[schema.Contact]]: contacts = [] if phone := site["attributes"]["Phone"]: contacts.append(schema.Contact(phone=phone)) if url := normalize_url(_cleanup_url(site["attributes"]["URL"])): contacts.append(schema.Contact(website=url)) if contacts: return contacts return None def _get_notes(site: dict) -> Optional[List[str]]: notes = [] if hours_info := site["attributes"]["AdditionalHoursInfo"]: notes.append(hours_info) if requirements := site["attributes"]["TestingRequirements"]: