예제 #1
0
    def handle(self, *args, **options):

        # CREATE CITY

        all_countries = location_models.Country.objects.all()
        for i in all_countries:
            if i.countryPhotoURL == None or i.countryThumbnailURL == None:
                try:
                    gp = locationThumbnail.get_photos(
                        term=i.countryName).get_urls()
                    countryPhotoURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                    countryThumbnailURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                except:
                    countryPhotoURL = None
                    countryThumbnailURL = None

                i.country_photo = countryPhotoURL,
                i.country_thumbnail = countryThumbnailURL
                i.save()
                print(i.country_name)

        all_cities = location_models.City.objects.all()
        for i in all_cities:
            if i.cityPhotoURL == None or i.cityThumbnailURL == None:
                try:
                    gp = locationThumbnail.get_photos(
                        term=i.cityName).get_urls()
                    cityPhotoURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                    cityThumbnailURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                except:
                    cityPhotoURL = None
                    cityThumbnailURL = None

                i.city_photo = cityPhotoURL,
                i.city_thumbnail = cityThumbnailURL
                i.save()
                print(i.city_name)

        self.stdout.write(self.style.SUCCESS(f"Everything seeded"))
예제 #2
0
def createCity(cityId):
    def get_locations_nearby_coords(latitude, longitude, max_distance=3000):
        gcd_formula = "6371 * acos(cos(radians(%s)) * \
        cos(radians(latitude)) \
        * cos(radians(longitude) - radians(%s)) + \
        sin(radians(%s)) * sin(radians(latitude)))"

        distance_raw_sql = RawSQL(gcd_formula, (latitude, longitude, latitude))
        qs = location_models.City.objects.all().annotate(
            distance=distance_raw_sql).order_by('distance')
        if max_distance is not None:
            qs = qs.filter(distance__lt=max_distance)
            for i in qs:
                pass
            return qs

    cityLatitude, cityLongitude, cityName, countryCode = reversePlace.reverse_place(
        cityId)
    nearCities = get_locations_nearby_coords(cityLatitude, cityLongitude,
                                             3000)[:20]
    if cityLatitude and cityLongitude and cityName and countryCode:
        try:
            country = location_models.Country.objects.get(
                country_code=countryCode)
        except location_models.Country.DoesNotExist:

            with open('pinner/locations/countryData.json',
                      mode='rt',
                      encoding='utf-8') as file:
                countryData = json.load(file)
                currentCountry = countryData[countryCode]
                countryName = currentCountry['name']
                countryNameNative = currentCountry['native']
                countryCapital = currentCountry['capital']
                countryCurrency = currentCountry['currency']
                countryPhone = currentCountry['phone']
                countryEmoji = currentCountry['emoji']
                continentCode = currentCountry['continent']
                latitude = currentCountry['latitude']
                longitude = currentCountry['longitude']

                try:
                    continent = location_models.Continent.objects.get(
                        continent_code=continentCode)
                except:
                    with open('pinner/locations/continentData.json',
                              mode='rt',
                              encoding='utf-8') as file:
                        continentData = json.load(file)
                        continentName = continentData[continentCode]

                        try:
                            gp = locationThumbnail.get_photos(
                                term=continentName).get_urls()
                            continentPhotoURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                            continentThumbnailURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                        except:
                            continentPhotoURL = None
                            continentThumbnailURL = None

                        continent = location_models.Continent.objects.create(
                            continent_name=continentName,
                            continent_photo=continentPhotoURL,
                            continent_thumbnail=continentThumbnailURL,
                            continent_code=continentCode)
            try:
                gp = locationThumbnail.get_photos(term=countryName).get_urls()
                countryPhotoURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                countryThumbnailURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
            except:
                countryPhotoURL = None
                countryThumbnailURL = None
            country = location_models.Country.objects.create(
                country_code=countryCode,
                country_name=countryName,
                country_name_native=countryNameNative,
                country_capital=countryCapital,
                country_currency=countryCurrency,
                country_phone=countryPhone,
                country_emoji=countryEmoji,
                country_photo=countryPhotoURL,
                country_thumbnail=countryThumbnailURL,
                continent=continent,
                latitude=latitude,
                longitude=longitude)

        try:
            gp = locationThumbnail.get_photos(term=cityName).get_urls()
            cityPhotoURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
            cityThumbnailURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
        except:
            cityPhotoURL = None
            cityThumbnailURL = None
        city = location_models.City.objects.create(
            city_id=cityId,
            city_name=cityName,
            country=country,
            city_photo=cityPhotoURL,
            city_thumbnail=cityThumbnailURL,
            latitude=cityLatitude,
            longitude=cityLongitude)
        print(city.city_name)
        for i in nearCities:
            city.near_city.add(i)
            city.save()
예제 #3
0
    def mutate(self, info, **kwargs):

        first_name = kwargs.get('first_name')
        last_name = kwargs.get('last_name')
        email = kwargs.get('email')
        gender = kwargs.get('gender')
        cityId = kwargs.get('cityId')
        countryCode = kwargs.get('countryCode')
        appleId = kwargs.get('appleId')

        try:
            user = models.User.objects.get(
                appleId=appleId
            )
            token = get_token(user)
            return types.AppleConnectResponse(ok=True, token=token)

        except models.User.DoesNotExist:

            def get_locations_nearby_coords(latitude, longitude, max_distance=3000):
                gcd_formula = "6371 * acos(cos(radians(%s)) * \
                cos(radians(latitude)) \
                * cos(radians(longitude) - radians(%s)) + \
                sin(radians(%s)) * sin(radians(latitude)))"
                distance_raw_sql = RawSQL(
                    gcd_formula,
                    (latitude, longitude, latitude)
                )
                qs = location_models.City.objects.all().annotate(distance=distance_raw_sql).order_by('distance')
                if max_distance is not None:
                    qs = qs.filter(Q(distance__lt=max_distance))
                    for i in qs:
                        pass
                return qs

            try:
                city = location_models.City.objects.get(city_id=cityId)
            except location_models.City.DoesNotExist:
                cityLatitude, cityLongitude, cityName, countryCode = reversePlace.reverse_place(cityId)
                nearCities = get_locations_nearby_coords(cityLatitude, cityLongitude, 3000)[:20]

                try:
                    country = location_models.Country.objects.get(country_code=countryCode)
                except location_models.Country.DoesNotExist:

                    with open('pinner/locations/countryData.json', mode='rt', encoding='utf-8') as file:
                        countryData = json.load(file)
                        currentCountry = countryData[countryCode]
                        countryName = currentCountry['name']
                        countryNameNative = currentCountry['native']
                        countryCapital = currentCountry['capital']
                        countryCurrency = currentCountry['currency']
                        countryPhone = currentCountry['phone']
                        countryEmoji = currentCountry['emoji']
                        continentCode = currentCountry['continent']
                        latitude = currentCountry['latitude']
                        longitude = currentCountry['longitude']

                        try:
                            continent = location_models.Continent.objects.get(continent_code=continentCode)
                        except:
                            with open('pinner/locations/continentData.json', mode='rt', encoding='utf-8') as file:
                                continentData = json.load(file)
                                continentName = continentData[continentCode]

                                try:
                                    gp = locationThumbnail.get_photos(term=continentName).get_urls()
                                    continentPhotoURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                                    continentThumbnailURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                                except:
                                    continentPhotoURL = None
                                    continentThumbnailURL = None

                                continent = location_models.Continent.objects.create(
                                    continent_name=continentName,
                                    continent_photo=continentPhotoURL,
                                    continent_thumbnail=continentThumbnailURL,
                                    continent_code=continentCode
                                )
                    try:
                        gp = locationThumbnail.get_photos(term=countryName).get_urls()
                        countryPhotoURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                        countryThumbnailURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                    except:
                        countryPhotoURL = None
                        countryThumbnailURL = None

                    country = location_models.Country.objects.create(
                        country_code=countryCode,
                        country_name=countryName,
                        country_name_native=countryNameNative,
                        country_capital=countryCapital,
                        country_currency=countryCurrency,
                        country_phone=countryPhone,
                        country_emoji=countryEmoji,
                        country_photo=countryPhotoURL,
                        country_thumbnail=countryThumbnailURL,
                        continent=continent,
                        latitude=latitude,
                        longitude=longitude
                    )

                try:
                    gp = locationThumbnail.get_photos(term=cityName).get_urls()
                    cityPhotoURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                    cityThumbnailURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                except:
                    cityPhotoURL = None
                    cityThumbnailURL = None

                city = location_models.City.objects.create(
                    city_id=cityId,
                    city_name=cityName,
                    country=country,
                    city_photo=cityPhotoURL,
                    city_thumbnail=cityThumbnailURL,
                    latitude=cityLatitude,
                    longitude=cityLongitude
                )
                for i in nearCities:
                    city.near_city.add(i)
                    city.save()

            with open('pinner/users/adjectives.json', mode='rt', encoding='utf-8') as adjectives:
                with open('pinner/users/nouns.json', mode='rt', encoding='utf-8') as nouns:
                    adjectives = json.load(adjectives)
                    nouns = json.load(nouns)

                    if email:
                        local, at, domain = email.rpartition('@')
                        username = random.choice(adjectives) + local.capitalize()
                        is_verified_email_address = True
                    else:
                        username = random.choice(adjectives) + random.choice(nouns).capitalize()
                        is_verified_email_address = False

                    newUser = models.User.objects.create_user(username)
                    if first_name:
                        newUser.first_name = first_name
                    if last_name:
                        newUser.last_name = last_name
                    newUser.save()
                    newUser.appleId = appleId
                    newUser.email_address = email
                    newUser.is_verified_email_address = is_verified_email_address
                    newUser.gender = gender
                    newUser.current_city = city
                    newUser.current_country = city.country
                    newUser.current_continent = city.country.continent
                    newUser.save()

                    moveNotification = notification_models.MoveNotification.objects.create(
                        actor=newUser,
                        city=city,
                        country=city.country,
                        continent=city.country.continent,
                    )

                    token = get_token(newUser)
                    return types.AppleConnectResponse(ok=True, token=token)
예제 #4
0
    def mutate(self, info, **kwargs):

        phoneNumber = kwargs.get('phoneNumber')
        countryPhoneNumber = kwargs.get('countryPhoneNumber')
        countryPhoneCode = kwargs.get('countryPhoneCode')
        key = kwargs.get('key')
        cityId = kwargs.get('cityId')

        if phoneNumber.startswith('0'):
            phoneNumber = phoneNumber.replace('0', '')
            return phoneNumber

        payload = countryPhoneNumber + phoneNumber

        try:
            verification = models.Verification.objects.get(key=key,
                                                           target="phone",
                                                           payload=payload,
                                                           is_verified=False,
                                                           is_edit=False)

            try:
                exstingUser = users_models.User.objects.get(
                    phone_number=phoneNumber)
                exstingUser.is_verified_phone_number = True
                exstingUser.save()
                verification.is_verified = True
                verification.user = exstingUser
                verification.save()
                token = get_token(exstingUser)
                return types.CompletePhoneVerificationResponse(ok=True,
                                                               token=token)

            except users_models.User.DoesNotExist:

                def get_locations_nearby_coords(latitude,
                                                longitude,
                                                max_distance=3000):
                    gcd_formula = "6371 * acos(cos(radians(%s)) * \
                    cos(radians(latitude)) \
                    * cos(radians(longitude) - radians(%s)) + \
                    sin(radians(%s)) * sin(radians(latitude)))"

                    distance_raw_sql = RawSQL(gcd_formula,
                                              (latitude, longitude, latitude))
                    qs = location_models.City.objects.all().annotate(
                        distance=distance_raw_sql).order_by('distance')
                    if max_distance is not None:
                        qs = qs.filter(distance__lt=max_distance)
                        for i in qs:
                            pass
                        return qs

                try:
                    city = location_models.City.objects.get(city_id=cityId)
                except location_models.City.DoesNotExist:
                    cityLatitude, cityLongitude, cityName, countryCode = reversePlace.reverse_place(
                        cityId)
                    nearCities = get_locations_nearby_coords(
                        cityLatitude, cityLongitude, 3000)[:20]

                    try:
                        country = location_models.Country.objects.get(
                            country_code=countryCode)
                    except location_models.Country.DoesNotExist:

                        with open('pinner/locations/countryData.json',
                                  mode='rt',
                                  encoding='utf-8') as file:
                            countryData = json.load(file)
                            currentCountry = countryData[countryCode]
                            countryName = currentCountry['name']
                            countryNameNative = currentCountry['native']
                            countryCapital = currentCountry['capital']
                            countryCurrency = currentCountry['currency']
                            countryPhone = currentCountry['phone']
                            countryEmoji = currentCountry['emoji']
                            continentCode = currentCountry['continent']
                            latitude = currentCountry['latitude']
                            longitude = currentCountry['longitude']

                            try:
                                continent = location_models.Continent.objects.get(
                                    continent_code=continentCode)
                            except:
                                with open(
                                        'pinner/locations/continentData.json',
                                        mode='rt',
                                        encoding='utf-8') as file:
                                    continentData = json.load(file)
                                    continentName = continentData[
                                        continentCode]

                                    try:
                                        gp = locationThumbnail.get_photos(
                                            term=continentName).get_urls()
                                        continentPhotoURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                                        continentThumbnailURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                                    except:
                                        continentPhotoURL = None
                                        continentThumbnailURL = None

                                    continent = location_models.Continent.objects.create(
                                        continent_name=continentName,
                                        continent_photo=continentPhotoURL,
                                        continent_thumbnail=
                                        continentThumbnailURL,
                                        continent_code=continentCode)

                        try:
                            gp = locationThumbnail.get_photos(
                                term=countryName).get_urls()
                            countryPhotoURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                            countryThumbnailURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                        except:
                            countryPhotoURL = None
                            countryThumbnailURL = None
                        country = location_models.Country.objects.create(
                            country_code=countryCode,
                            country_name=countryName,
                            country_name_native=countryNameNative,
                            country_capital=countryCapital,
                            country_currency=countryCurrency,
                            country_phone=countryPhone,
                            country_emoji=countryEmoji,
                            country_photo=countryPhotoURL,
                            country_thumbnail=countryThumbnailURL,
                            continent=continent,
                            latitude=latitude,
                            longitude=longitude)

                    try:
                        gp = locationThumbnail.get_photos(
                            term=cityName).get_urls()
                        cityPhotoURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                        cityThumbnailURL = gp + "?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                    except:
                        cityPhotoURL = None
                        cityThumbnailURL = None
                    city = location_models.City.objects.create(
                        city_id=cityId,
                        city_name=cityName,
                        country=country,
                        city_photo=cityPhotoURL,
                        city_thumbnail=cityThumbnailURL,
                        latitude=cityLatitude,
                        longitude=cityLongitude)
                    for i in nearCities:
                        city.near_city.add(i)
                        city.save()

                with open('pinner/users/adjectives.json',
                          mode='rt',
                          encoding='utf-8') as adjectives:
                    with open('pinner/users/nouns.json',
                              mode='rt',
                              encoding='utf-8') as nouns:
                        adjectives = json.load(adjectives)
                        nouns = json.load(nouns)
                        username = random.choice(adjectives) + random.choice(
                            nouns).capitalize()
                        newUser = users_models.User.objects.create_user(
                            username=username)
                        token = get_token(newUser)
                        city = location_models.City.objects.get(city_id=cityId)
                        newUser.country_phone_number = countryPhoneNumber
                        newUser.country_phone_code = countryPhoneCode
                        newUser.phone_number = phoneNumber
                        newUser.current_city = city
                        newUser.current_country = city.country
                        newUser.current_continent = city.country.continent
                        moveNotification = notification_models.MoveNotification.objects.create(
                            actor=newUser,
                            city=city,
                            country=city.country,
                            continent=city.country.continent,
                        )
                        newUser.is_verified_phone_number = True
                        newUser.save()
                        verification.is_verified = True
                        verification.user = newUser
                        verification.save()
                        return types.CompletePhoneVerificationResponse(
                            ok=True, token=token)

        except models.Verification.DoesNotExist:
            return types.CompletePhoneVerificationResponse(ok=False,
                                                           token=None)
            raise Exception('Verification key not valid')
예제 #5
0
    def mutate(self, info, **kwargs):

        user = info.context.user

        if user.is_authenticated:

            bio = kwargs.get('bio', user.bio)
            gender = kwargs.get('gender', user.gender)
            firstName = kwargs.get('firstName', user.first_name)
            lastName = kwargs.get('lastName', user.last_name)
            username = kwargs.get('username', user.username)
            nationalityCode = kwargs.get('nationalityCode', user.nationality)
            residenceCode = kwargs.get('residenceCode', user.residence)

            # if username:
            #     raise Exception("Only English username is allowed "

            try:
                nationality = location_models.Country.objects.get(country_code=nationalityCode)
            except location_models.Country.DoesNotExist:
                with open('pinner/locations/countryData.json', mode='rt', encoding='utf-8') as file:
                    countryData = json.load(file)
                    currentCountry = countryData[nationalityCode]
                    countryName = currentCountry['name']
                    countryNameNative = currentCountry['native']
                    countryCapital = currentCountry['capital']
                    countryCurrency = currentCountry['currency']
                    countryPhone = currentCountry['phone']
                    countryEmoji = currentCountry['emoji']
                    continentCode = currentCountry['continent']
                    latitude = currentCountry['latitude']
                    longitude = currentCountry['longitude']

                    try:
                        continent = location_models.Continent.objects.get(continent_code=continentCode)
                    except:
                        with open('pinner/locations/continentData.json', mode='rt', encoding='utf-8') as file:
                            continentData = json.load(file)
                            continentName = continentData[continentCode]

                            try:
                                gp = locationThumbnail.get_photos(term=continentName).get_urls()
                                continentPhotoURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                                continentThumbnailURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                            except:
                                continentPhotoURL = None
                                continentThumbnailURL = None

                            # DOWNLOAD IMAGE
                            # continentPhotoURL = gp.get_urls()
                            # # for i in range(gp.num):
                            # #     gp.download(i)

                            continent = location_models.Continent.objects.create(
                                continent_name=continentName,
                                continent_photo=continentPhotoURL,
                                continent_thumbnail=continentThumbnailURL,
                                continent_code=continentCode
                            )

                try:
                    gp = locationThumbnail.get_photos(term=countryName).get_urls()
                    countryPhotoURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                    countryThumbnailURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                except:
                    countryPhotoURL = None
                    countryThumbnailURL = None

                # DOWNLOAD IMAGE
                # for i in range(gp.num):
                #     gp.download(i)

                nationality = location_models.Country.objects.create(
                    country_code=nationalityCode,
                    country_name=countryName,
                    country_name_native=countryNameNative,
                    country_capital=countryCapital,
                    country_currency=countryCurrency,
                    country_phone=countryPhone,
                    country_emoji=countryEmoji,
                    country_photo=countryPhotoURL,
                    country_thumbnail=countryThumbnailURL,
                    continent=continent,
                    latitude=latitude,
                    longitude=longitude
                )

            try:
                residence = location_models.Country.objects.get(country_code=residenceCode)
            except location_models.Country.DoesNotExist:
                with open('pinner/locations/countryData.json', mode='rt', encoding='utf-8') as file:
                    countryData = json.load(file)
                    currentCountry = countryData[residenceCode]
                    countryName = currentCountry['name']
                    countryNameNative = currentCountry['native']
                    countryCapital = currentCountry['capital']
                    countryCurrency = currentCountry['currency']
                    countryPhone = currentCountry['phone']
                    countryEmoji = currentCountry['emoji']
                    continentCode = currentCountry['continent']
                    latitude = currentCountry['latitude']
                    longitude = currentCountry['longitude']

                    try:
                        continent = location_models.Continent.objects.get(continent_code=continentCode)
                    except:
                        with open('pinner/locations/continentData.json', mode='rt', encoding='utf-8') as file:
                            continentData = json.load(file)
                            continentName = continentData[continentCode]

                            try:
                                gp = locationThumbnail.get_photos(term=continentName).get_urls()
                                continentPhotoURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                                continentThumbnailURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                            except:
                                continentPhotoURL = None
                                continentThumbnailURL = None

                            # DOWNLOAD IMAGE
                            # continentPhotoURL = gp.get_urls()
                            # # for i in range(gp.num):
                            # #     gp.download(i)

                            continent = location_models.Continent.objects.create(
                                continent_name=continentName,
                                continent_photo=continentPhotoURL,
                                continent_thumbnail=continentThumbnailURL,
                                continent_code=continentCode
                            )

                try:
                    gp = locationThumbnail.get_photos(term=countryName).get_urls()
                    countryPhotoURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=450&w=450&fit=crop"
                    countryThumbnailURL = gp+"?ixlib=rb-0.3.5&q=100&fm=jpg&crop=entropy&cs=faces&h=80&w=80&fit=crop"
                except:
                    countryPhotoURL = None
                    countryThumbnailURL = None

                # DOWNLOAD IMAGE
                # for i in range(gp.num):
                #     gp.download(i)

                residence = location_models.Country.objects.create(
                    country_code=residenceCode,
                    country_name=countryName,
                    country_name_native=countryNameNative,
                    country_capital=countryCapital,
                    country_currency=countryCurrency,
                    country_phone=countryPhone,
                    country_emoji=countryEmoji,
                    country_photo=countryPhotoURL,
                    country_thumbnail=countryThumbnailURL,
                    continent=continent,
                    latitude=latitude,
                    longitude=longitude
                )

            try:
                user.bio = bio
                user.gender = gender
                user.nationality = nationality
                user.residence = residence
                user.save()

                user.first_name = firstName
                user.last_name = lastName
                if user.username != username:
                    try:
                        existing_user = models.User.objects.get(username=username)
                        raise Exception("Username is already taken")
                    except models.User.DoesNotExist:
                        user.username = username
                user.save()
                token = get_token(user)
                return types.EditProfileResponse(ok=True, user=user, token=token)

            except IntegrityError as e:
                print(e)
                error = "Can't save"
                return types.EditProfileResponse(ok=False, user=None, token=None)

        else:
            error = 'You need to log in'
            return types.EditProfileResponse(ok=False, user=None, token=None)