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
Exemple #2
0
    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
Exemple #3
0
    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 handle(self, *args, **options):
        f = xlrd.open_workbook(args[0])
        sh = f.sheet_by_index(0)
        kont = 1
        ercnt =1
        
        CDICT = {'legutiano':'legutio',
                 'ribera-alta':'erriberagoitia', 
        }

        uloc = {}

        for rownum in range(sh.nrows)[1:]:
            fields = sh.row_values(rownum)

            if len(fields)!=27:
                print 'Tenemos mas o menos de 27 campos'
                n = 1
                for field in fields:
                    print n, field
                    n = n+1
                break
            else:
                (titulo, denom, slug, ent_origen, cod_origen, rcat, 
                direc1, direc2, cp, pob1, pob, loc, desc, lat, lon, tel, fax, url, 
                foto_x, foto_x_tit, foto_x_alt, itinerarios, 
                acc_fis, acc_vis, acc_aud, acc_int, 
                acc_org ) = fields[:27]
                
            place = Place()
            place.name = titulo
            place.slug = slugify(slug.split('/')[2], instance=place)
            ent_origen = 'ejgv-tur-rest'   
            place.source = ent_origen
            place.source_id = cod_origen

            cat = slugify(rcat)            
            cat = self.RDICT.get(cat,cat)
            
            rel_cat = Category.objects.filter(slug=cat)
            if len(rel_cat)>0:
                cat_obj = Category.objects.get(slug=cat)
            else:
                parentcat = Category.objects.get(slug='restaurant')
                cat_obj = Category(slug=cat,name=cat,parent=parentcat)
                cat_obj.save()
            place.category = cat_obj
            place.address1 = direc1
            place.address2 = direc2
            if len(cp)<5:
                cp = "0%s" % cp
            place.postalcode = cp.strip()
            location_slug = slugify(pob)
            if CDICT.has_key(location_slug):
                location_slug = CDICT[location_slug]           
            location = Location.objects.filter(slug__startswith=location_slug)
            if location:
                loc_obj = location[0]
            else:
                print ercnt,'ERROREA TOKI EZEZAGUNA', titulo, cp, pob, kont
                uloc[pob]=uloc.get(pob,0)+1
                ercnt = ercnt+1
                break
            place.city = loc_obj
            place.locality = loc
            place.description = desc           
            if lat:
                place.lat = lat
            if lon:
                place.lon = lon
            place.tlf = tel[:30]
            place.fax = fax[:15]
            place.url = url
            place.email = ''
            
            try:
                print kont, titulo, place.slug, loc_obj.name, place.cp
            except:
                print place.slug
            print "##%s##" % tel, len(tel)           

            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()
        
            foto_x = foto_x.replace('http://turismo.euskadi.net/contenidos/a_alojamiento/ ','http://turismo.euskadi.net/x65-12375/es/contenidos/a_alojamiento/')
            print foto_x
            t_place = place #Place.objects.get(slug='bib-ikaztegieta')
            has_point = foto_x.split('/')[-1].find('.')
            if has_point>-1:
                image = loadUrlImage(foto_x, t_place, foto_x_tit, 'jpg', )            
            kont += 1

        print uloc
Exemple #5
0
    def handle(self, *args, **options):
        saving = len(args)>1 and args[1] or 0
        line = len(args)>2 and int(args[2]) or 1
        filename = args[0]
        full_path = "%s/%s" % (IMPORT_FILES_FOLDER,filename)
        f = xlrd.open_workbook(full_path)
        sh = f.sheet_by_index(0)
        kont = 1
        ercnt =1

        CDICT = {'legutiano':'legutio',
                 'ribera-alta':'erriberagoitia',
        }

        uloc = {}

        new_rest = 0

        for rownum in range(sh.nrows)[line:]:
            fields = sh.row_values(rownum)
            if len(fields)!=26:
                print 'Tenemos mas o menos de 25 campos'
                n = 1
                for field in fields:
                    print n, field
                    n = n+1
                break
            else:
                (titulo, slug, ent_origen, cod_origen, rcat,
                direc1, direc2, cp, pob, loc, desc, lat, lon, tel, fax, url,
                foto_x, foto_x_tit, foto_x_alt, itinerarios,
                acc_fis, acc_vis, acc_aud, acc_int,
                acc_org, title_code ) = fields[:26]

            print '############################'
            print kont, titulo


            pattern = re.compile("\s+\d+")
            translation = False
            ent_origen = 'ejgv-tur-rest'
            places = Place.objects.filter(source_id=cod_origen, source=ent_origen)
            if len(places)<1:
                places = Place.objects.filter(source_id=str(int(cod_origen)), source=ent_origen)
            if len(places)>0:
                place = places[0]
            if '_eu' in filename and place:
                place.description_eu = strip_tags(desc)
                translation = True
            elif '_en' in filename and place:
                place.description_en = strip_tags(desc)
                translation = True
            elif '_eu' in filename or '_en' in filename:
                translation = True

            if translation:
                place.save()
                continue

            #GET USER!!!!
            author = User.objects.get(username=ent_origen)

            location_slug = slugify(pob)

            if CDICT.has_key(location_slug):
                location_slug = CDICT[location_slug]
            location = Location.objects.filter(slug__startswith=location_slug)
            if location:
                loc_obj = location[0]
            else:
                print ercnt,'WARNING: New place', titulo, cp, pob, kont
                uloc[pob]=uloc.get(pob,0)+1
                ercnt = ercnt+1
                break


            if len(places)>0:
                print 'EDIT:', slug, cod_origen
                place = places[0]
            else:
                print 'NEW:', slug, cod_origen
                place = Place()
                place.slug = slugify(slug.split('/')[2],instance=place)

                if rcat:
                    cat = slugify(rcat)
                    cat = self.RDICT.get(cat, cat)
                    rel_cat = Category.objects.filter(slug=cat)
                    if len(rel_cat)>0:
                        cat_obj = Category.objects.get(slug=cat)
                    else:
                        print 'WARNING: Missing cat:', cat
                        parentcat = Category.objects.get(slug='sleep')
                        cat_obj = Category(slug=cat, name=cat, name_es=cat, name_eu=cat, name_en=cat, parent=parentcat)
                        if saving:
                            cat_obj.save()
                else:
                    cat_obj = Category.objects.get(slug='sleep')

                place.category = cat_obj

                new_rest += 1

            if title_code:
                place.name = "%s %s" % (titulo, title_code)
            else:
                place.name = titulo
            place.description_es = strip_tags(desc)
            repl = pattern.search(direc1)
            if "," not in direc1 and "km" not in direc1 and repl:
                repl = repl.group()
                direc1 = direc1.replace(repl, ",%s" % repl).replace("  ", " ").replace(" ,", ",")
            place.address1 = direc1.replace(u" Nº", "")
            place.address2 = direc2
            if len(cp) < 5:
                cp = "0%s" % cp
            place.postalcode = cp.strip()
            try:
                place.city = loc_obj
            except:
                pass
            place.locality = pob != loc and loc or ""
            place.description = strip_tags(desc)
            place.source = ent_origen
            place.source_id = "%d" % int(cod_origen)
            if lat:
                place.lat = str(lat)
            if lon:
                place.lon = str(lon)

            #SET USER!!!!!
            place.author = author
            place.tlf = ''.join(tel[:30].split())
            place.fax = ''.join(fax[:15].split())
            place.url = url
            place.url_es = url
            place.url_eu = url
            place.url_en = url
            place.email = ''
            if saving:
                place.save()

            accesses = Access.objects.filter(place=place)
            if len(accesses)>0:
                access = accesses[0]
            else:
                access = Access()
                access.place = place
            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()]

            if saving:
                access.save()




            #print foto_x
            t_place = place
            has_point = foto_x.split('/')[-1].find('.')
            if has_point>-1:
                if saving:
                    image = loadUrlImage(foto_x, t_place, foto_x_tit, 'jpg', )
            kont += 1

        print "New restaurants: %d" % (new_rest)
        print uloc
Exemple #6
0
    def handle(self, *args, **options):
        saving = 1
        filename = args[0]
        full_path = "%s/%s" % (IMPORT_FILES_FOLDER,filename)
        f = xlrd.open_workbook(full_path)
        sh = f.sheet_by_index(0)

        kont = 1
        now = datetime.now()
        print 'NOW!:'
        print now


        for rownum in range(sh.nrows)[2:]:
            fields = sh.row_values(rownum)

            if len(fields)!=19:
                print 'Tenemos mas o menos de 19 campos'
                n = 1
                for field in fields:
                    print n, field
                    n = n+1
                break
            else:
                (name, catname, address1, postalcode,
                city_name, province, lat,
                 lon, tlf,
                 acc_fis, acc_vis, acc_aud, acc_int, acc_org,
                 acc_desc, xw, xx, xy, xz) = fields[:19]

            """slug
                name
                category.slug
                description
                address1
                address2
                postalcode
                city.name
                locality
                source
                source_id
                lat
                lon
                tlf
                fax
                url
                email
                access.aphysic
                access.avisual
                access.aaudio
                access.aintelec
                access.aorganic
                access.description
                access.fileurl
            """

            location_slug = slugify(city_name)
            try:
                location = Location.objects.get(slug=location_slug)
                loc_obj = location
            except:
                location = Location.objects.filter(slug__startswith=location_slug)
                if location:
                    loc_obj = location[0]
                else:
                    print 'ERROREA', location_slug
                    break
            print location, city_name, location_slug

            # Line added to force slug creation for the first import
            slug = "abcdefghijklmnopqrs"
            source_id = "%04d" % rownum
            source = 'elkartu'


            cat = self.CATDICT[catname]
            cat_obj = Category.objects.get(slug=cat)


            places = Place.objects.filter(slug=slug)

            if len(places)>0:
                place = places[0]
                print 'EDIT:', place.slug, place.source, place.source_id
            else:
                place = Place()
                place.slug = slugify(name, instance=place)
                print 'NEW:', place.slug, source_id
            place.name = name.encode('utf-8')
            place.category = cat_obj
            place.description_es = ''
            place.description_eu = ''
            place.description_en = ''
            place.address1 = address1
            place.address2 = ''
            cp = str(int(postalcode))
            if len(cp)<5:
                cp = "0%s" % cp
            place.postalcode = cp.strip()
            place.city = loc_obj
            place.locality = ''
            place.source = source
            place.source_id = source_id
            latstr = str(lat)[:-2]
            if type(lon)==type(0.3):
                lonstr =str(lon)[:-2]
            else:
                lonstr = lon
            place.lat = "%s.%s" % (latstr[:2],latstr[2:])
            place.lon = "%s.%s" % (lonstr[:2],lonstr[2:])
            print place.lat
            print place.lon
            place.tlf = tlf
            place.fax = ''
            place.url = ''
            place.email = ''
            place.modified_date = now

            if saving:
                place.save()

            # ACCESS
            try:
                access = place.access.all()[0]
            except:
                access = Access()
                access.place = place

            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 = acc_desc

            if saving:
                access.save()

            kont += 1
Exemple #7
0
    def handle(self, *args, **options):
        saving = 1
        filename = args[0]
        full_path = "%s/%s" % (IMPORT_FILES_FOLDER, filename)
        f = xlrd.open_workbook(full_path)
        sh = f.sheet_by_index(0)

        kont = 1
        now = datetime.now()
        print 'NOW!:'
        print now

        cat = 'train'
        cat_obj = Category.objects.get(slug=cat)

        for rownum in range(sh.nrows)[1:]:
            fields = sh.row_values(rownum)

            if len(fields) != 24:
                print 'Tenemos mas o menos de 24 campos'
                n = 1
                for field in fields:
                    print n, field
                    n = n + 1
                break
            else:
                (slug, name, cat_slug, description, address1, address2,
                 postalcode, city_name, locality, source, source_id, lat, lon,
                 tlf, fax, url, email, acc_fis, acc_vis, acc_aud, acc_int,
                 acc_org, acc_desc, acc_fileurl) = fields[:24]
            """slug
                name
                category.slug
                description
                address1
                address2
                postalcode
                city.name
                locality
                source
                source_id
                lat
                lon
                tlf
                fax
                url
                email
                access.aphysic
                access.avisual
                access.aaudio
                access.aintelec
                access.aorganic
                access.description
                access.fileurl
            """

            location_slug = slugify(city_name)
            location = Location.objects.filter(slug__startswith=location_slug)
            if location:
                loc_obj = location[0]
            else:
                print 'ERROREA', location_slug
                break

            places = Place.objects.filter(slug=slug)

            if len(places) > 0:
                place = places[0]
                print 'EDIT:', place.slug, place.source, place.source_id
            else:
                place = Place()
                place.slug = slugify(slug, instance=place)
                print 'NEW:', slug, source_id

            place.name = name
            place.category = cat_obj
            place.description_es = description
            place.description_eu = description
            place.description_en = description
            place.address1 = address1
            place.address2 = address2
            cp = str(int(postalcode))
            if len(cp) < 5:
                cp = "0%s" % cp
            place.postalcode = cp.strip()
            place.city = loc_obj
            place.locality = locality
            place.source = source
            place.source_id = source_id
            place.lat = str(lat)
            place.lon = str(lon)
            place.tlf = tlf
            place.fax = fax
            place.url = url
            place.email = email
            place.modified_date = now

            if saving:
                place.save()

            # ACCESS
            try:
                access = place.access.all()[0]
            except:
                access = Access()
                access.place = place

            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 = acc_desc

            if saving:
                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()[2:]:
            (titulo, slug, ent_origen, cod_origen, cat, 
            direc1, direc2, cp, pob, desc, tel, fax, url, 
            email, foto, lat, lon, foto_x, foto_x_tit, foto_x_alt, 
            acc_fis, acc_vis, acc_aud, acc_int, acc_org, tipo_biblio, 
            ano_inicio, institution, institution_type, open_times, 
            access_type, center_type, tem_general, tem_infantil, 
            tem_religioso, ser_consulta, ser_reprografia, ser_hemeroteca, 
            ser_wifi, ser_selectiva, ser_bol_novedades, ser_prestamo, 
            ser_prestamo_inter, ser_prestamo_domic, ser_infor_bibliografica, 
            ser_internet_usuarios, ser_acceso_bbdd) = pl.split('\t')[0:47]

            cat = 'biblioteka'
            cat_obj = Category.objects.get(slug=cat)                     
            cod_origen = "bib%04d" % (kont)
            
            
            location_slug = slugify(pob)           
            location = Location.objects.filter(slug__startswith=location_slug)
            if location:
                loc_obj = location[0]
            else:
                print 'ERROREA', location_slug
                break
                     
            place = Place()
            place.slug = slugify("%s_%s" % ('bib',pob), instance=place)
            
            print kont, titulo, place.slug, loc_obj.name, institution, self.IDICT[institution_type]
            place.name = titulo.decode('utf-8')
            place.category = cat_obj
            place.description = desc.decode('utf-8')
            place.address1 = direc1
            place.address2 = direc2
            if len(cp)<5:
                cp = "0%s" % cp
            place.postalcode = cp
            place.city = loc_obj
            place.description = desc
            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.email = email
            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()
             
            biblio = Biblio()
            biblio.btype = self.BDICT[tipo_biblio.strip()]
            ano_conv = ano_inicio.strip().replace('.','')
            try:
                biblio.start_year = int(ano_conv)
            except:
                biblio.start_year = 0
            biblio.institution = institution_type
            biblio.institution_type = self.IDICT[institution_type.strip()]
            biblio.open_times = open_times
            biblio.access_type = self.ACDICT[access_type.strip()]
            biblio.center_type = self.CDICT[center_type.strip()]
            biblio.place = place
            biblio.save()
            
            bibtopics = {'general':tem_general, 'infantil':tem_infantil, 'religioso':tem_religioso}             
            for k,v in bibtopics.items():
                if v:
                    bibtopic = Bibtopic.objects.filter(name=k)
                    if bibtopic:
                        bibtopic_obj = bibtopic[0]
                    else:
                        print 'ERROR: no bibtopic called %s' % k
                        bibtopic_obj = Bibtopic()
                        bibtopic_obj.name = k
                        bibtopic_obj.save()
                    biblio.topics.add(bibtopic_obj)
                                                        
            bibservices = {'consulta':ser_consulta, 'reprografia':ser_reprografia, 
                           'hemeroteca':ser_hemeroteca, 'wifi':ser_wifi, 'selectiva':ser_selectiva, 
                           'bol_novedades':ser_bol_novedades, 'prestamo':ser_prestamo, 
                           'prestamo_inter':ser_prestamo_inter, 'prestamo_domic':ser_prestamo_domic, 
                           'infor_bibliografica':ser_infor_bibliografica, 'internet_usuarios':ser_internet_usuarios, 
                           'acceso_bbdd':ser_acceso_bbdd
                           }                        
            for k,v in bibservices.items():
                if v:
                    bibservice = Bibservice.objects.filter(name=k)
                    if bibservice:
                        bibservice_obj = bibservice[0]
                    else:
                        print 'ERROR: no bibservice called %s' % k
                        bibservice_obj = Bibservice()
                        bibservice_obj.name = k
                        bibservice_obj.save()
                    biblio.services.add(bibservice_obj)                                  


            biblio.save()
            kont += 1
    def handle(self, *args, **options):
        saving = 1
        filename = args[0]
        full_path = "%s/%s" % (IMPORT_FILES_FOLDER,filename)
        f = xlrd.open_workbook(full_path)
        sh = f.sheet_by_index(0)

        kont = 1
        now = datetime.now()
        print 'NOW!:'
        print now

        cat = 'train'
        cat_obj = Category.objects.get(slug=cat)

        for rownum in range(sh.nrows)[1:]:
            fields = sh.row_values(rownum)

            if len(fields)!=24:
                print 'Tenemos mas o menos de 24 campos'
                n = 1
                for field in fields:
                    print n, field
                    n = n+1
                break
            else:
                (slug, name, cat_slug, description, address1, address2,
                 postalcode, city_name, locality, source, source_id, lat,
                 lon, tlf, fax, url, email,
                 acc_fis, acc_vis, acc_aud, acc_int, acc_org,
                 acc_desc, acc_fileurl) = fields[:24]
            
            """slug
                name
                category.slug
                description
                address1
                address2
                postalcode
                city.name
                locality
                source
                source_id
                lat
                lon
                tlf
                fax
                url
                email
                access.aphysic
                access.avisual
                access.aaudio
                access.aintelec
                access.aorganic
                access.description
                access.fileurl
            """

            location_slug = slugify(city_name)
            location = Location.objects.filter(slug__startswith=location_slug)
            if location:
                loc_obj = location[0]
            else:
                print 'ERROREA', location_slug
                break
            
            places = Place.objects.filter(slug=slug)

            if len(places)>0:
                place = places[0]
                print 'EDIT:', place.slug, place.source, place.source_id
            else:
                place = Place()
                place.slug = slugify(slug, instance=place)
                print 'NEW:', slug, source_id

            place.name = name
            place.category = cat_obj
            place.description_es = description
            place.description_eu = description
            place.description_en = description
            place.address1 = address1
            place.address2 = address2
            cp = str(int(postalcode))
            if len(cp)<5:
                cp = "0%s" % cp
            place.postalcode = cp.strip()
            place.city = loc_obj
            place.locality = locality
            place.source = source
            place.source_id = source_id
            place.lat = str(lat)
            place.lon = str(lon)
            place.tlf = tlf
            place.fax = fax
            place.url = url
            place.email = email
            place.modified_date = now

            if saving:
                place.save()           

            # ACCESS
            try:
                access = place.access.all()[0]
            except:
                access = Access()
                access.place = place

            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 = acc_desc
            
            if saving:
                access.save()

            kont += 1
Exemple #10
0
    def handle(self, *args, **options):
        saving = len(args)>1 and args[1] or 0
        filename = args[0]
        line = len(args)>2 and int(args[2]) or 1
        full_path = "%s/%s" % (IMPORT_FILES_FOLDER,filename)
        f = xlrd.open_workbook(full_path)
        sh = f.sheet_by_index(0)
        kont = 1
        ercnt =1

        CDICT = {'legutiano':'legutio',
                 'ribera-alta':'erriberagoitia',
        }

        uloc = {}

        for rownum in range(sh.nrows)[line:]:
            fields = sh.row_values(rownum)

            if len(fields)!=25:
                print 'Tenemos mas o menos de 24 campos'
                n = 1
                for field in fields:
                    print n, field
                    n = n+1
                break
            else:
                (titulo, slug, ent_origen, cod_origen,
                direc1, direc2, cp, pob, loc, desc, lat, lon, tel, fax, url,
                foto_x, foto_x_tit, foto_x_alt, itinerarios,
                acc_fis, acc_vis, acc_aud, acc_int,
                acc_org, title_code ) = fields[:26]



            translation = False
            ent_origen = 'ejgv-tur-infos'
            places = Place.objects.filter(source_id=cod_origen, source=ent_origen)
            if len(places)<1:
                places = Place.objects.filter(source_id=str(int(cod_origen)), source=ent_origen)
            if len(places)>0:
                place = places[0]
            if '_eu' in filename and place:
                place.description_eu = strip_tags(desc)
                translation = True
            elif '_en' in filename and place:
                place.description_en = strip_tags(desc)
                translation = True
            elif '_eu' in filename or '_en' in filename:
                translation = True

            if translation:
                place.save()
                continue



            if 'oficinas' in filename:
                cat_obj = Category.objects.get(slug='tourist-office')
            elif 'centros' in filename:
                cat_obj = Category.objects.get(slug='interpretation-centre')
            else:
                cat_obj = Category.objects.get(slug='tourism')

            #GET USER
            author = User.objects.get(username=ent_origen)

            location_slug = slugify(pob)

            if CDICT.has_key(location_slug):
                location_slug = CDICT[location_slug]
            location = Location.objects.filter(slug__startswith=location_slug)
            if location:
                loc_obj = location[0]
            else:
                print ercnt,'WARNING: New place', titulo, cp, pob, kont
                uloc[pob]=uloc.get(pob,0)+1
                ercnt = ercnt+1
                break

            if len(places)>0:
                place = places[0]
                print 'EDIT:', place.slug, cod_origen
            else:
                place = Place()
                print slug
                place.slug = slugify(slug.split('/')[2],instance=place)
                print 'NEW:', slug, cod_origen


            if title_code:
                place.name = "%s %s" % (titulo, title_code)
            else:
                place.name = titulo
            place.category = cat_obj
            place.description_es = strip_tags(desc)
            place.address1 = direc1
            place.address2 = direc2
            if len(cp)<5:
                cp = "0%s" % cp
            place.postalcode = cp.strip()
            try:
                place.city = loc_obj
            except:
                pass
            place.locality = pob != loc and loc or ""
            place.description = strip_tags(desc)

            #SET USER
            place.author = author
            place.source = ent_origen
            place.source_id = "%d" % int(cod_origen)
            if lat:
                place.lat = str(lat)
            if lon:
                place.lon = str(lon)
            place.tlf = ''.join(tel[:30].split())
            place.fax = ''.join(fax[:15].split())
            place.url = url
            place.url_es = url
            place.url_eu = url
            place.url_en = url
            place.email = ''
            if saving:
                place.save()

            accesses = Access.objects.filter(place=place)
            if len(accesses)>0:
                access = accesses[0]
            else:
                access = Access()
                access.place = place
            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()]

            if saving:
                access.save()

            #print foto_x
            t_place = place
            has_point = foto_x.split('/')[-1].find('.')
            if has_point>-1:
                if saving:
                    image = loadUrlImage(foto_x, t_place, foto_x_tit, 'jpg', )
            kont += 1

        print uloc