示例#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()
示例#2
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 = 'Банные занесены'
示例#3
0
文件: views.py 项目: mki/brTech
def cities(request, slug=''):
    try:
        city = City.objects(country=Country.objects(slug=slug)[0])
    except:
        raise Http404

    return render_to_response('city.html', {'City': city, 'slug': slug},
        context_instance=RequestContext(request))
示例#4
0
文件: views.py 项目: mki/brTech
def airports(request, slug=''):
    try:
        city=City.objects(slug=slug)[0]
        airport = Airport.objects(city=city)
    except:
        raise Http404

    return render_to_response('airport.html', {'Airport': airport, 'slug': slug, 'city': city},
        context_instance=RequestContext(request))
示例#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()
示例#6
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()
示例#7
0
文件: importdata.py 项目: mki/brTech
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()
示例#8
0
文件: importdata.py 项目: mki/brTech
def airs():
    base, prog = get_data()

    print '\n'
    print 'Import/Update Airport'

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

        city.name_ru = row[1]
        city.location = (float(row[6]),float(row[7]))
        city.altitude = row[8]
        city.timezone = float(row[9])
        city.dst = row[10]
        city.city = City.objects(name_eu = row[2])[0]
        city.slug = '%s' % (str(row[1]).replace(' ','_'))
        city.save()

        prog.increment_amount()
        print prog, '\r',
        sys.stdout.flush()
示例#9
0
from main.db_migration_data.schedules_config import schedules

# saving old record before migration
cached_records = []
try:
    cached_records = [
        record.json(withDates=False) for record in Sensor_record.query.all()
    ]
except Exception as ex:
    print(ex)

db.drop_all()
db.create_all()

for city in cities:
    db_city = City(**city)
    db.session.add(db_city)

for region in regions:
    db_region = Region(**region)
    db.session.add(db_region)

for house in houses:
    db_house = House(**house)
    db.session.add(db_house)

for flat in flats:
    db_flat = Flat(**flat)
    db.session.add(db_flat)

for resident in residents:
示例#10
0
 def create(self, validated_data):
     city = City(**validated_data)
     city.save()
     return city