def POST(self):
    you = require_you()
    params = web.input(name='')

    unique = True
    name = params['name']
    if name and name != you.get('name',None):
      from helper import slugify
      slug = slugify(name)
      for row in dbview.users(db, startkey=slug, endkey=slug):
        if slug == row.key:
          unique = False
          break
    
      if unique:
        you['name'] = name
        you['slug'] = slug
    elif not name and 'name' in you:
      # blanking your name makes you anonymous, and makes your page inaccessible
      del you['name']
      del you['slug']

    db[you.id] = you

    if unique:
      web.redirect('/')
    else:
      return render('settings', errors="Sorry, that name's taken!", you=you)
示例#2
0
    def download(self, proxy=None, https=False):
        if self.download_url:
            if proxy:
                if https:
                    _proxy = urllib2.ProxyHandler({"https": proxy})

                else:
                    _proxy = urllib2.ProxyHandler({"http": proxy})

                opener = urllib2.build_opener(_proxy)
                response = opener.open(self.download_url)

            else:
                response = urllib2.urlopen(self.download_url)

            # get the file size
            meta_data = dict(response.info().items())
            # size in bytes
            f_size = int(
                meta_data.get("Content-Length")
                or meta_data.get("content-length"))

            # CHANGE [0] IF YOU WANT TO GET DIFFERENT QUALITY VIDEOS
            f_name = "{}.{}".format(
                helper.slugify(self.title),
                self.parse_video_type(self.stream_map["type"][0]))
            # 256kb == 0.25mb
            chunk_size = 256 * 1024
            download_progress = 0

            print("DOWNLOADING: {}".format(f_name))

            with open(f_name, "wb") as f:
                while True:
                    # load a buffer
                    b = response.read(chunk_size)
                    if len(b) == 0:
                        break

                    f.write(b)

                    download_progress += len(b)
                    print("\t{}mb / {}mb".format(
                        helper.byte_mb(download_progress),
                        helper.byte_mb(f_size)))
示例#3
0
文件: app.py 项目: smartuse/platform
 def dict(self):
     content = ''
     if self.description:
         try:
             content = Markup(
                 markdown.markdown(self.description,
                                   extensions=MARKDOWN_EXT))
         except Exception as e:
             print(e)
     return {
         'id': self.id,
         'title': self.title,
         'name': helper.slugify(self.title),
         'description': content,
         'mediatype': helper.media_mime(self.path),
         'format': helper.media_name(self.path),
         'path': self.path or '',
         'sources': [r.dict() for r in self.sources]
     }
示例#4
0
文件: app.py 项目: smartuse/platform
 def on_model_change(view, form, model, is_created):
     model.slug = helper.slugify(form.title.data)
示例#5
0
 def header(self, tr):
     """Extract the header from the table (used as keys for the data items)
     """
     return tuple([helper.slugify(td.text) for td in tr.findAll('td')] + ['url'])