Ejemplo n.º 1
0
def fetch(csv_file):
    with codecs.open(csv_file, 'r', encoding='utf-8') as csvf:
        for line in csvf:
            if not wpexists(line[:line.find(',')]):
                line = unicodedata.normalize('NFKD', unicode(line, 'latin1'))
                wp, name, tags = get_data(line)
                w = Wallpaper()
                w.file = wp
                w.title = name
                w.save()
                w.tags = tags
                w.save()
Ejemplo n.º 2
0
def handle_upload(request):
    """
    Función que se encarga de manipular el wallpaper una vez en el servidor.
    """
    post = request.POST.copy()
    try:
        wallpaper = Wallpaper()
        wallpaper.author = post.get('author')
        wallpaper.title = post.get('title')
        wallpaper.uploader = request.user
        wallpaper.save()
        wallpaper.tags = post.get('tags')
    except Exception, e:
        print e
        return None
Ejemplo n.º 3
0
        print e
        return None
    try:
        filename = file.name[file.name.rindex('/') + 1:-4]
        ext = file.name[-4:]
    except Exception, e:
        print e
        filename = file.name
    destpath = join(settings.ORPHANS_DIR, slugify(filename) + ext)
    if not exists(destpath):
        try:
            dest = open(destpath, 'w')
        except Exception, e:
            print e
            return None
        dest.write(file.read())
        dest.close()
        print 'Copiando contenido a destino...', destpath
    file.close()
    if Wallpaper.objects.filter(file=destpath).count():
        print 'El wallpaper ya existía, no se hace nada.'
    else:
        wallpaper = Wallpaper()
        wallpaper.file = destpath
        wallpaper.save()
        # wallpaper, created = Wallpaper.objects.get_or_create(file=destpath)

if __name__ == "__main__":
    for arg in argv[1:]:
        crawl_orphans(arg)