├── .gitignore
├── README.md
└── bm2evernote.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[co]
2 |
3 | # Packages
4 | *.egg
5 | *.egg-info
6 | dist
7 | build
8 | eggs
9 | parts
10 | bin
11 | var
12 | sdist
13 | develop-eggs
14 | .installed.cfg
15 |
16 | # Installer logs
17 | pip-log.txt
18 |
19 | # Unit test / coverage reports
20 | .coverage
21 | .tox
22 |
23 | #Translations
24 | *.mo
25 |
26 | #Mr Developer
27 | .mr.developer.cfg
28 |
29 | venv
30 | *.enex
31 | *.html
32 |
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | bookmarks2evernote
2 | ==================
3 |
4 | A simple command line tool to transform bookmarks exported from Google Chrome and Google Bookmarks into Evernote as _individual_ notes using EN's enex format.
5 | If the html file you are using as input uses H3 as folder name, this are translated into Evernote tags.
6 | For this to work correctly, you may have to ensure when exporting Google Chrome Bookmarks that all the folders are located at the end of your bookmark's list.
7 |
8 | It also indentifies duplicated bookmarks in the same HTML file. Google Bookmarks export feature duplicates all bookmarks with more than one tag.
9 |
10 | Requisites:
11 | -----------
12 |
13 | * Python
14 | * [Beautiful Soup](http://www.crummy.com/software/BeautifulSoup/). An excellent python library for html parsing and navigation. Follow their instructions for installation.
15 |
16 | Usage:
17 | ------
18 | It takes a single parameter, the name of the input html file.
19 |
20 | E.g. `python bm2evernote.py YOUR_BOOKMARKS_EXPORT_FILE.html`
21 |
22 | The output file will have the same name as the input but with an enex extension.
23 |
--------------------------------------------------------------------------------
/bm2evernote.py:
--------------------------------------------------------------------------------
1 | from bs4 import BeautifulSoup
2 | import codecs
3 | import argparse
4 | import time
5 |
6 | class Bookmark():
7 | """docstring for Bookmark"""
8 | def __init__(self, title, url, tag, date):
9 | self.title = title
10 | self.url = url
11 | self.tag = '' + tag + ''
12 | self.date = time.strftime("%Y%m%dT%H%M%SZ", time.gmtime(float(date)))
13 | self.content = '''%(title)s''' % {'title': self.title, 'url': self.url}
14 |
15 | def printAsEnex(self):
16 | output = """%(title)s%(content)s]]>%(date)s%(date)s%(tag)s%(url)s""" % {'title': self.title, 'content': self.content, 'tag': self.tag, 'url': self.url, 'date': self.date,}
17 | return output.replace('&', '&')
18 |
19 | def __str__(self):
20 | return unicode(self.title + " " + self.url + " " + self.tag)
21 |
22 | def unique(bookmarks):
23 | found = {}
24 | res = []
25 |
26 | for bookmark in bookmarks:
27 | if bookmark.url not in found:
28 | found[bookmark.url] = bookmark
29 | else:
30 | found[bookmark.url].tag += bookmark.tag
31 |
32 | for key in found:
33 | res.append(found[key])
34 |
35 | return res
36 |
37 | def main():
38 |
39 |
40 | try:
41 | parser = argparse.ArgumentParser()
42 | parser.add_argument("html_file", help="the file that contains the bookmarks in html format")
43 | args = parser.parse_args()
44 | soup = BeautifulSoup(codecs.open(args.html_file, encoding='utf-8'))
45 |
46 | html_tags = soup.findAll(['h3', 'a'])
47 |
48 | en_tag = ''
49 |
50 | bookmarks = []
51 |
52 | for tag in html_tags:
53 | if tag.name == 'h3':
54 | en_tag = tag.string
55 | if tag.name == 'a':
56 | new_bm = Bookmark(tag.string, tag['href'], en_tag, tag['add_date'])
57 | bookmarks.append(new_bm)
58 |
59 | print "Total Bookmarks: " + str(len(bookmarks))
60 |
61 | bookmarks = unique(bookmarks)
62 |
63 | print "Unique Bookmarks: " + str(len(bookmarks))
64 |
65 | output_file = args.html_file.split('.')[0] + ".enex"
66 | out = codecs.open(output_file, 'w', encoding='utf-8')
67 |
68 | out.write("""""")
69 | for n in bookmarks:
70 | out.write(n.printAsEnex())
71 |
72 | out.write("")
73 | out.close()
74 |
75 | print "Success! Output file name: " + output_file
76 | except Exception as e:
77 | print "Error!"
78 | print type(e)
79 | print e.args
80 |
81 |
82 | if __name__ == '__main__':
83 | main()
84 |
--------------------------------------------------------------------------------