def handle(self, *args, **options): f = open(args[0],'r') parent = Location.objects.get(slug='gipuzkoa') #fix this, location's parent must be described in data file kont = 1 for pl in f.readlines()[1:]: print kont, len(pl.split('\t')), pl.split('\t')[0], pl.split('\t')[-2] (titulo, slug, ent_origen, cod_origen, cat, direc, cp, pob, desc, tel, fax, url, foto, lat, lon, foto_x, foto_x_tit, foto_x_alt, itinerarios, acc_fis, acc_vis, acc_aud, acc_int, acc_org, imagen_titulo, imagen_alt, tipo_biblio, ano_inicio, institucion, tipo_institucion, codigo_portal, horarios, tipo_acceso, tipo_centro, tematica, servicios, snbe, snbe_url, bilgunea, bilgunea_url, bilgunea_fecha, acces_itinerario, acces_url_ficha ) = pl.split('\t')[:43] cat_obj = Category.objects.get(slug=cat) location_slug =slugify(pob) location = Location.objects.filter(slug__startswith=location_slug) if location: loc_obj = location[0] else: loc_obj = Location() loc_obj.name = pob.decode('utf-8') loc_obj.parent = parent loc_obj.save() place = Place() place.name = titulo.decode('utf-8') place.category = cat_obj place.description = desc.decode('utf-8') place.address1 = direc place.postalcode = cp place.city = loc_obj place.source = ent_origen place.source_id = cod_origen if lat: place.lat = lat if lon: place.lon = lon place.tlf = tel place.fax = fax place.url = url place.url_es = url place.url_eu = url place.url_en = url place.save() access = Access() access.aphysic = self.ADICT[acc_fis.lower().strip()] access.avisual = self.ADICT[acc_vis.lower().strip()] access.aaudio = self.ADICT[acc_aud.lower().strip()] access.aintelec = self.ADICT[acc_int.lower().strip()] access.aorganic = self.ADICT[acc_org.lower().strip()] access.description = acces_itinerario access.fileurl = acces_url_ficha access.place = place access.save() kont += 1
def handle(self, *args, **options): f = open(args[0],'r') parent = Location.objects.get(slug='gipuzkoa') #fix this, location's parent must be described in data file kont = 1 for pl in f.readlines(): print kont titulo, slug, ent_origen, cod_origen, cat, direc, cp, pob, desc, tel, fax, url, foto, lat, lon, foto_x, foto_x_tit, itinerarios, foto_x_alt, acc_fis, acc_vis, acc_aud, acc_int, acc_org = pl.split('\t')[0:24] cat_obj = Category.objects.get(slug=cat) location_slug =slugify(pob) location = Location.objects.filter(slug__startswith=location_slug) if location: loc_obj = location[0] else: loc_obj = Location() loc_obj.name = pob.decode('utf-8') loc_obj.parent = parent loc_obj.save() place = Place() place.name = titulo.decode('utf-8') place.category = cat_obj place.description = desc.decode('utf-8') place.address1 = direc place.postalcode = cp place.city = loc_obj place.source = ent_origen place.source_id = cod_origen if lat: place.lat = lat if lon: place.lon = lon place.tlf = tel place.fax = fax place.url = url place.save() access = Access() access.aphysic = self.ADICT[acc_fis.lower().strip()] access.avisual = self.ADICT[acc_vis.lower().strip()] access.aaudio = self.ADICT[acc_aud.lower().strip()] access.aintelec = self.ADICT[acc_int.lower().strip()] access.aorganic = self.ADICT[acc_org.lower().strip()] access.place = place access.save() kont += 1
def get_cities(): loc_file = codecs.open("src/arartekomaps/arartekomaps/locations/herriak.csv", "r", "utf-8") locs = {} for line in loc_file.readlines(): a, b = line.strip().split(",") prov, city = a.strip(), b.strip() if locs.has_key(prov): locs[prov].append(city) else: locs[prov] = [city] euskadi = Location(name=u"Euskadi") euskadi.save() for prob in locs.keys(): myprob = Location(name=prob, parent=euskadi) myprob.save() print prob for city in locs[prob]: mycity = Location(name=city, parent=myprob) mycity.save() print city
def handle(self, *args, **options): f = open(args[0], 'r') parent = Location.objects.get(slug='gipuzkoa') #fix this, location's parent must be described in data file kont = 1 for pl in f.readlines(): print kont titulo, slug, ent_origen, cod_origen, cat, direc, cp, pob, desc, tel, fax, url, foto, lat, lon, foto_x, foto_x_tit, itinerarios, foto_x_alt, acc_fis, acc_vis, acc_aud, acc_int, acc_org = pl.split( '\t')[0:24] cat_obj = Category.objects.get(slug=cat) location_slug = slugify(pob) location = Location.objects.filter(slug__startswith=location_slug) if location: loc_obj = location[0] else: loc_obj = Location() loc_obj.name = pob.decode('utf-8') loc_obj.parent = parent loc_obj.save() place = Place() place.name = titulo.decode('utf-8') place.category = cat_obj place.description = desc.decode('utf-8') place.address1 = direc place.postalcode = cp place.city = loc_obj place.source = ent_origen place.source_id = cod_origen if lat: place.lat = lat if lon: place.lon = lon place.tlf = tel place.fax = fax place.url = url place.save() access = Access() access.aphysic = self.ADICT[acc_fis.lower().strip()] access.avisual = self.ADICT[acc_vis.lower().strip()] access.aaudio = self.ADICT[acc_aud.lower().strip()] access.aintelec = self.ADICT[acc_int.lower().strip()] access.aorganic = self.ADICT[acc_org.lower().strip()] access.place = place access.save() kont += 1
def get_cities(): loc_file = codecs.open( 'src/arartekomaps/arartekomaps/locations/herriak.csv', 'r', 'utf-8') locs = {} for line in loc_file.readlines(): a, b = line.strip().split(',') prov, city = a.strip(), b.strip() if locs.has_key(prov): locs[prov].append(city) else: locs[prov] = [city] euskadi = Location(name=u"Euskadi") euskadi.save() for prob in locs.keys(): myprob = Location(name=prob, parent=euskadi) myprob.save() print prob for city in locs[prob]: mycity = Location(name=city, parent=myprob) mycity.save() print city