Ejemplo n.º 1
0
def editImmigrant(imm, firstName, lastName, gender, date, country, continent,
                  ethnicity, spokenLang, processLocation, destCity, destState):
    imm = getImmigrant(imm)
    imm.immfirstname = firstName
    imm.immlastname = lastName
    imm.immgender = gender
    imm.immdate = date

    cont = Continent.objects.get(cname=continent)

    try:
        # Attempts to find that country
        c = Country.objects.get(cname=country)
    except Country.DoesNotExist:
        # If that country is not found, creates it
        c = Country(cname=country, ccontinent=cont)
        c.save()

    try:
        # Attempts to find that ethnicity
        e = Ethnicity.objects.get(ename=ethnicity)
    except Ethnicity.DoesNotExist:
        # If that combination is not found, creates it
        e = Ethnicity(ename=ethnicity)
        e.save()

    try:
        # Attempts to find that ethnicity
        sl = Languages.objects.get(lname=spokenLang)
    except Languages.DoesNotExist:
        # If that combination is not found, creates it
        sl = Languages(lname=spokenLang)
        sl.save()

    try:
        # Attempts to find that specific ethnic background combination
        eb = Ethnicbackground.objects.get(country=country,
                                          ethnicity=ethnicity,
                                          spokenlang=spokenLang)
    except Ethnicbackground.DoesNotExist:
        # If that combination is not found, creates it
        eb = Ethnicbackground(country=c, ethnicity=e, spokenlang=sl)
        eb.save()

    imm.immeb = eb
    imm.immprocloc = Processlocation.objects.get(plname=processLocation)

    state = State.objects.get(sname=destState)

    try:
        # Tries to find the city (that matches the state)
        city = City.objects.get(cname=destCity, cstate=state)
    except City.DoesNotExist:
        # If that city doesn't exist, creates it
        city = City(cname=destCity, cstate=state)
        city.save()

    imm.immdestcity = city

    imm.save()
Ejemplo n.º 2
0
    def handle_city(self, data_set):
        print("-------handle_city-------")

        item = City()
        item.name = data_set["name"]
        country_name = data_set["country_name"]
        country = Country.objects.filter(name=country_name).last()
        item.country = country
        item.save()
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        file_path = '/home/aslan/Documents/parcing/worldcitiespop.txt'

        with open(file_path, 'r') as file:
            for line in file:
                line = line.split(",")
                city = City(ascii_city_name=line[1], city_name=line[2], region=line[3],
                            population=int(line[4]) if line[4] != '' else 0,
                            latitude=float(line[5]), longitude=float(line[6]))
                country_code, created = CountryCode.objects.get_or_create(code=line[0])
                city.country_code = country_code
                print(city.ascii_city_name)
                city.save()
                self.stdout = 'Банные занесены'
Ejemplo n.º 4
0
def cities():
    base, prog = get_data()

    print '\n'
    print 'Import/Update City'

    for row in base:
        try:
            city = City.objects(name_eu = row[2])[0]
        except:
            city = City(name_eu = row[2])

        city.name_ru = row[2]
        city.country = Country.objects(name_eu = row[3])[0]
        city.slug = '%s' % (str(row[2]).replace(' ','_'))
        city.save()

        prog.increment_amount()
        print prog, '\r',
        sys.stdout.flush()
Ejemplo n.º 5
0
    def parse_city(self, response):
        print("\n\n---------url-------", response.url)
        price = response.xpath(
            "//table[@class='data_wide_table']//tr[2]/td[2]/text()"
        ).extract_first()
        currency_sign = price.split("\xa0")[1]
        currency_code = response.xpath(
            "//select[@id='displayCurrency']/option[@selected='selected']/text()"
        ).extract_first()

        country = Country.objects.get(id=response.meta["country_id"])
        country.currency_sign = currency_sign
        country.currency_code = currency_code
        country.save()

        city_list = response.xpath(
            '//*[@id="city"]//option/text()').extract()[1:]
        for city in city_list:
            city = City(country=country, name=city)
            city.save()
Ejemplo n.º 6
0
 def create(self, validated_data):
     city = City(**validated_data)
     city.save()
     return city