Coverage for bookie.lib.importer : 97%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Importers for bookmarks"""
"""The actual factory object we use for handling imports"""
"""work on getting an importer instance"""
# we need to get our list of hashes to make sure we check for dupes BmarkMgr.hash_list(username=username)])
"""Overriding new we return a subclass based on the file content"""
def can_handle(file_io): """This is meant to be implemented in subclasses"""
"""Meant to be implemented in subclasses"""
"""Save the bookmark to the db
:param url: bookmark url :param desc: one line description :param ext: extended description/notes :param tags: The string of tags to store with this bmark :param mark: Instance of Bmark that we're storing to db
""" # we should make sure that this url isn't already bookmarked before # adding it...if the hash matches, you must skip! url, self.username, desc, ext, tags, dt=dt, inserted_by=IMPORTED)
# add this hash to the list so that we can skip dupes in the same # import set else:
"""Process a delicious html file"""
def _is_delicious_format(soup, can_handle, delicious_doctype): """A check for if this import files is a delicious format compat file
Very fragile currently, it makes sure the first line is the doctype. Any blank lines before it will cause it to fail
""" soup.contents[0] == delicious_doctype and not soup.find('h3')):
def can_handle(file_io): """Check if this file is a google bookmarks format file
In order to check the file we have to read it and check it's content type.
Google Bookmarks and Delicious both have the same content type, but they use different formats. We use the fact that Google Bookmarks uses <h3> tags and Delicious does not in order to differentiate these two formats. """
can_handle, delicious_doctype)
# make sure we reset the file_io object so that we can use it again
"""Given a file, process it"""
# if we have a dd as next sibling, get it's content else:
# Remove microseconds from the timestamp
link['href'], link.text, extended, " ".join(link.get('tags', '').split(',')), dt=add_date)
transaction.commit()
# Commit any that are left since the last commit performed.
# For each bookmark in this set that we saved, sign up to # fetch its content.
# Start a new transaction for the next grouping.
"""Process a delicious xml export file"""
def _is_delicious_format(parsed, can_handle): """A check for if this import files is a delicious xml format compat
The root xml element will be 'posts' if this is the case.
"""
def can_handle(file_io): """Check if this file is a google bookmarks format file
In order to check the file we have to read it and check it's content type.
Google Bookmarks and Delicious both have the same content type, but they use different formats. We use the fact that Google Bookmarks uses <h3> tags and Delicious does not in order to differentiate these two formats. """
# IF etree can't parse it, it's not our file. can_handle)
# make sure we reset the file_io object so that we can use it again
"""Given a file, process it"""
continue
post.get('href'), post.get('description'), post.get('extended'), post.get('tag'), dt=add_date) except InvalidBookmark, exc: bmark = None
# Commit any that are left since the last commit performed.
# For each bookmark in this set that we saved, sign up to # fetch its content.
# Start a new transaction for the next grouping.
"""Process a Google Bookmark export html file"""
def _is_google_format(soup, gbookmark_doctype, can_handle): """Verify that this import file is in the google export format
Google only puts one tag at a time and needs to be looped through to get them all. See the sample files in the test_importer directory
""" soup.contents[0] == gbookmark_doctype and soup.find('h3')):
def can_handle(file_io): """Check if this file is a google bookmarks format file
In order to check the file we have to read it and check it's content type
Google Bookmarks and Delicious both have the same content type, but they use different formats. We use the fact that Google Bookmarks uses <h3> tags and Delicious does not in order to differentiate these two formats. """ gbookmark_doctype, can_handle)
# make sure we reset the file_io object so that we can use it again
"""Process an html google bookmarks export and import them into bookie The export format is a tag as a heading, with urls that have that tag under that heading. If a url has N tags, it will appear N times, once under each heading. """ raise Exception("File is not a google bookmarks file")
# we don't want to just import all the available urls, since each url # occurs once per tag. loop through and aggregate the tags for each url
else:
# get extended description link.parent.nextSibling and link.parent.nextSibling.name == 'dd') else:
# date the site was bookmarked
'description': link.text, 'tags': tags, 'extended': extended, 'date_added': datetime.fromtimestamp( timestamp_added), }
# save the bookmarks url, metadata['description'], metadata['extended'], " ".join(metadata['tags']), dt=metadata['date_added']) # Start a new transaction for the next grouping.
# Commit any that are left since the last commit performed.
# For each bookmark in this set that we saved, sign up to # fetch its content. |