deprem-yardim-backend icon indicating copy to clipboard operation
deprem-yardim-backend copied to clipboard

discard junk data by refactoring the address creation function

Open safebuffer opened this issue 1 year ago • 1 comments

Address record creation should go through a proxy function i.e create_new_address and the city value should be checked whether it's inside affected areas or not

def create_address(processed_address=None,full_address=None,tweet=None):
    city = processed_address.get("city")
    allowed_cities = ["Gaziantep", "Malatya", "Batman", "Bingöl", "Elazığ", "Kilis", "Diyarbakır", "Mardin", "Siirt", "Şırnak", "Van", "Muş", "Bitlis", "Hakkari", "Adana", "Osmaniye","Hatay'"]

    if city in allowed_cities or city == None:
        return Address.objects.create(
            tweet_id=tweet.id,
            address=full_address,
            city=processed_address.get("city"),
            distinct=processed_address.get("distinct"),
            neighbourhood=processed_address.get("neighbourhood"),
            street=processed_address.get("street"),
            no=processed_address.get("no"),
            name_surname=processed_address.get("name_surname"),
            tel=processed_address.get("tel"),
        )

inside the ask_to_zekai function



        address = create_address(processed_address,full_address,tweet)
        if not address:
            return

this will cut down the number of API requests sent to the ty_geolocation_url endpoint

safebuffer avatar Feb 07 '23 17:02 safebuffer