Project

General

Profile

« Previous | Next » 

Revision 4c6410dc

Added by dsorber almost 12 years ago

Finished up the bookmarks importer and made the whole thing a package that I'm calling bmklib. I'm also preparing to start working on the web interface by copying the existing .wsgi file I created to use as a template.

View differences:

software/bookmark_library/lib/bookmark.py
import datetime
import re
from urllib.error import HTTPError, URLError
from urllib.request import urlopen
import dateutil.parser
......
values.append(_format_date(getattr(self, key)))
else:
values.append(getattr(self, key))
db = self._db_conn.cursor()
if values and sets:
# Add the record id as the last value
values.append(self.id)
# Build full SQL statement then execute it
sql = SQL_UPDATE_BOOKMARK.format(','.join(sets))
db = self._db_conn.cursor()
db.execute(sql, values)
# Reset dirty flags
......
self._dirty[key] = False
# Inner function FTW
def update_tags_lists(delete_sql, insert_sql, tags):
def update_tag_lists(delete_sql, insert_sql, tags):
db.execute(delete_sql, (self.id,))
tag_updates = []
for tag in tags:
......
def _get_content(self):
""" Read the page and get its raw page HTML content. """
if self.url:
response = urlopen(self.url)
if response.getcode() == HTTP_OKAY:
self._content = response.read().decode('utf-8')
try:
response = urlopen(self.url)
if response.getcode() == HTTP_OKAY:
content = response.read()
try:
self._content = content.decode('utf-8')
except UnicodeDecodeError:
self._content = content.decode('ISO-8859-1')
except (HTTPError, URLError):
return ''
def suggest_title(self):
""" Return the contents of the page's <title> tag as a title suggestion
......
try:
title = re.search('<title>(.+)</title>', self._content).group(1)
except IndexError:
except (IndexError, AttributeError, TypeError):
title = None
return title
def is_reachable(self):
""" Check if the page is reachable. """
if self.url:
response = urlopen(self.url)
if response.getcode() == HTTP_OKAY:
self.last_reachable = datetime.datetime.now()
return True
try:
response = urlopen(self.url)
if response.getcode() == HTTP_OKAY:
self.last_reachable = datetime.datetime.now()
return True
except (HTTPError, URLError):
return False
return False
def visit(self):

Also available in: Unified diff