Created
March 17, 2011 19:11
-
-
Save jorilallo/874931 to your computer and use it in GitHub Desktop.
Use export file as source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from BeautifulSoup import BeautifulSoup | |
from datetime import datetime | |
def import_bookmarks(data): | |
''' | |
Get bookmarks from Delicious' export file format | |
''' | |
soup = BeautifulSoup(data) | |
deli_bookmarks = soup.findAll('dt') | |
bookmarks = [] | |
for bookmark in deli_bookmarks: | |
name = bookmark.a.string | |
url = bookmark.a['href'] | |
private = True if bookmark.a['private'] else False | |
time = datetime.fromtimestamp(int(bookmark.a['add_date'])) | |
tags = bookmark.a['tags'].split(',') | |
bookmarks.append({ | |
'name': name, | |
'url': url, | |
'private': private, | |
'time': time, | |
'tags': tags, | |
}) | |
return bookmarks | |
# Test import | |
data = open('data.html', 'r').read() | |
print import_bookmarks(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment