Example #1
0
    def POST(self):
        try:
            post_file = web.input(file={})
        except:
            return "File too large!"
        cgi.maxlen = settings.MAX_IMPORTED_FILE
        if 'file' in post_file:                              # if there is an attached file -> good!
            if post_file['file'].filename.endswith('.html'): # luckily chrome && firefox use same structure for storing bookmarks
                file_contents = post_file['file'].value
                
                soup = BeautifulSoup(file_contents)
                bookmarks = soup.findAll('a')

                # access to attribute: each['ATTRIBUTE']
                for each in bookmarks:
                    # WARNING!: some special characters should be removed or you'll be hitten by:
                    #   UnicodeEncodeError: 'charmap' codec can't encode character u'\xab' in position 51: character maps to <undefined>
                    # or something similiar.
                    title = re.sub("['\$\"<>]",'', each.string)
                    url = each['href']
                    db.insert_favorite( {'url': url, 'title': title, 'description' : 'empty', 'tags': 'imported', 'date': datetime.datetime.now(), 'page_path': None, 'images': ['/static/missing.ico']} )
                return web.seeother("/")
                
            else:
                return web.seeother("/error")   # bad file format
        else:
            return web.seeother("/error")       # no file attached!
Example #2
0
    def POST(self):
        post_sent = web.input() # returns Storage obj  --> <Storage {'url': u'myurl', 'title': u'mytitle' ...}>
        post_sent['date'] = datetime.datetime.now()
        
        # handle 'Get' && 'Save page' checkboxes:
        flag_get_title = post_sent.has_key('get_title')
        flag_save_page = post_sent.has_key('save_page')
        
        # default
        post_sent['page_path'] = None
        post_sent['images'] = ["/static/missing.ico"] # default icon
        if flag_get_title or flag_save_page:
            post_sent = utils.get_page(post_sent, flag_save_page, flag_get_title)
        db.insert_favorite(post_sent)

        raise web.seeother('/') # go home
Example #3
0
    def POST(self):
        post_sent = web.input(
        )  # returns Storage obj  --> <Storage {'url': u'myurl', 'title': u'mytitle' ...}>
        post_sent['date'] = datetime.datetime.now()

        # handle 'Get' && 'Save page' checkboxes:
        flag_get_title = post_sent.has_key('get_title')
        flag_save_page = post_sent.has_key('save_page')

        # default
        post_sent['page_path'] = None
        post_sent['images'] = ["/static/missing.ico"]  # default icon
        if flag_get_title or flag_save_page:
            post_sent = utils.get_page(post_sent, flag_save_page,
                                       flag_get_title)
        db.insert_favorite(post_sent)

        raise web.seeother('/')  # go home
Example #4
0
    def POST(self):
        try:
            post_file = web.input(file={})
        except:
            return "File too large!"
        cgi.maxlen = settings.MAX_IMPORTED_FILE
        if 'file' in post_file:  # if there is an attached file -> good!
            if post_file['file'].filename.endswith(
                    '.html'
            ):  # luckily chrome && firefox use same structure for storing bookmarks
                file_contents = post_file['file'].value

                soup = BeautifulSoup(file_contents)
                bookmarks = soup.findAll('a')

                # access to attribute: each['ATTRIBUTE']
                for each in bookmarks:
                    # WARNING!: some special characters should be removed or you'll be hitten by:
                    #   UnicodeEncodeError: 'charmap' codec can't encode character u'\xab' in position 51: character maps to <undefined>
                    # or something similiar.
                    title = re.sub("['\$\"<>]", '', each.string)
                    url = each['href']
                    db.insert_favorite({
                        'url': url,
                        'title': title,
                        'description': 'empty',
                        'tags': 'imported',
                        'date': datetime.datetime.now(),
                        'page_path': None,
                        'images': ['/static/missing.ico']
                    })
                return web.seeother("/")

            else:
                return web.seeother("/error")  # bad file format
        else:
            return web.seeother("/error")  # no file attached!