Exemple #1
0
def add_hospitals(data, locality_id):
    for index, item in data[["name", "city"]].iterrows():
        print(index)
        hospital = item.to_dict()

        def hospital_exists(name):
            obj = Hospital.objects.filter(name=name,
                                          locality_id=locality_id).first()

            if obj is None:
                return False

            return True

        if hospital_exists(hospital["name"]):
            continue

        args = {
            **hospital,
            "state": "Andhra Pradesh",
        }

        location_info = get_location_info(**args)
        hospital = {**hospital, **location_info}

        contact_info = get_contact_info(hospital["place_id"] if 'place_id' in
                                        hospital.keys() else {})
        hospital = {**hospital, **contact_info}

        hospital["district"] = "AP"
        hospital["locality_id"] = locality_id

        obj = Hospital(**hospital)
        obj.save()
Exemple #2
0
def add_bangalore_hospitals(data):
    for index, item in data[['name', 'category', 'phone', 'address', "hotel"]].iterrows():
        hospital = {
            "name": item.loc['name'],
            "category": item.loc['category'],
            "locality_id": 1
        }

        if not pd.isna(item.loc["phone"]):
            hospital["phone"] = item.loc["phone"]

        if not pd.isna(item.loc["address"]):
            hospital["address"] = item.loc["address"]

        def hospital_exists(name, place_id=None):
            obj = Hospital.objects.filter(
                name=name, city__icontains="Bengaluru").first()

            if obj is None:
                return False

            return True

        if hospital_exists(hospital['name']):
            continue

        if pd.isna(item.loc["address"]):
            location_info = get_location_info(
                item.loc['name'], "Bangalore", "Karnataka")
        else:
            location_info = get_location_info(
                address=item.loc['address'], name=item.loc["hotel"], city="Bangalore", state="Karnataka")

        hospital = {**hospital, **location_info}

        contact_info = get_contact_info(
            hospital['place_id']) if 'place_id' in hospital.keys() else {}
        hospital = {**contact_info, **hospital}

        obj = Hospital(**hospital)
        obj.save()

        print(index, hospital)
Exemple #3
0
def refetch_info():
    hospitals = Hospital.objects.all()
    for hospital in hospitals:
        location_info = get_location_info(
            hospital.name, "Bangalore", "Karnataka")
        if location_info != {}:
            hospital.location = location_info['location']
            hospital.address = location_info['address']
            hospital.place_id = location_info['place_id']
            hospital.state = location_info['state']
            hospital.country = location_info['country']
            hospital.district = location_info['district']
            hospital.city = location_info['city']

            contact_info = get_contact_info(hospital.place_id)
            hospital.phone = contact_info['phone']
            hospital.website = contact_info['website']

            hospital.save()
Exemple #4
0
def add_pune_hospitals(data, locality_id):
    for index, item in data[['name', 'category', 'phone',
                             'address']].iterrows():
        print(index)
        hospital = item.to_dict()

        def hospital_exists(name):
            obj = Hospital.objects.filter(name=name,
                                          locality_id=locality_id).first()

            if obj is None:
                return False

            return True

        if hospital_exists(hospital["name"]):
            continue

        args = {
            "name": hospital["name"],
            "city": "Pune",
            "state": "Maharashtra",
            "address":
            None if hospital["address"] == "NA" else hospital["address"]
        }

        location_info = get_location_info(**args)
        hospital = {**hospital, **location_info}

        contact_info = get_contact_info(
            hospital["place_id"]) if 'place_id' in hospital.keys() else {}
        hospital = {**hospital, **contact_info}

        if item.loc["phone"] != "NA":
            hospital["phone"] = item.loc["phone"]

        hospital["district"] = "Pune"
        hospital["locality_id"] = locality_id

        obj = Hospital(**hospital)
        obj.save()