Skip to content

Commit 07a024f

Browse files
committed
[#813] added .atom to import/export extensions
1 parent c0aed33 commit 07a024f

5 files changed

Lines changed: 70 additions & 21 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ To get started right away, jump to the [Quickstart](#quickstart) section. `buku`
6868
- Powerful search options (regex, substring...)
6969
- Continuous search with on the fly mode switch
7070
- Portable, merge-able database to sync between systems
71-
- Import/export bookmarks from/to HTML, XBEL, Markdown, RSS or Orgfile
71+
- Import/export bookmarks from/to HTML, XBEL, Markdown, RSS/Atom or Orgfile
7272
- Smart tag management using redirection (>>, >, <<)
7373
- Multi-threaded full DB refresh
7474
- Manual encryption support
@@ -232,11 +232,11 @@ POWER TOYS:
232232
format: [title](url) <!-- TAGS -->
233233
export Orgfile, if file ends with '.org'
234234
format: *[[url][title]] :tags:
235-
export rss feed if file ends with '.rss'
235+
export rss feed if file ends with '.rss'/'.atom'
236236
export buku DB, if file ends with '.db'
237237
combines with search results, if opted
238238
-i, --import file import bookmarks from file
239-
supports .html .xbel .json .md .org .rss .db
239+
supports .html .xbel .json .md .org .rss .atom .db
240240
-p, --print [...] show record details by indices, ranges
241241
print all bookmarks, if no arguments
242242
-n shows the last n results (like tail)

buku

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,8 @@ class BukuDb:
26322632
exported to an org file.
26332633
If destination file name ends with '.xbel' bookmarks are
26342634
exported to a XBEL file.
2635+
If destination file name ends with '.rss'/'.atom' bookmarks are
2636+
exported to an RSS file.
26352637
Otherwise, bookmarks are exported to a Firefox bookmarks.html
26362638
formatted file.
26372639
@@ -2712,7 +2714,7 @@ class BukuDb:
27122714
res = convert_bookmark_set(resultset, 'xbel', old)
27132715
count += res['count']
27142716
outfp.write(res['data'])
2715-
elif filepath.endswith('.rss'):
2717+
elif filepath.endswith('.rss') or filepath.endswith('.atom'):
27162718
res = convert_bookmark_set(resultset, 'rss', old)
27172719
count += res['count']
27182720
outfp.write(res['data'])
@@ -2992,7 +2994,8 @@ class BukuDb:
29922994
29932995
Supports Firefox, Google Chrome, and IE exported HTML bookmarks.
29942996
Supports XBEL standard bookmarks.
2995-
Supports Markdown files with extension '.md, .org'.
2997+
Supports RSS files with extension '.rss', '.atom'.
2998+
Supports Markdown files with extension '.md', '.org'.
29962999
Supports importing bookmarks from another buku database file.
29973000
29983001
Parameters
@@ -3026,7 +3029,7 @@ class BukuDb:
30263029
items = import_md(filepath=filepath, newtag=newtag)
30273030
elif filepath.endswith('org'):
30283031
items = import_org(filepath=filepath, newtag=newtag)
3029-
elif filepath.endswith('rss'):
3032+
elif filepath.endswith('rss') or filepath.endswith('atom'):
30303033
items = import_rss(filepath=filepath, newtag=newtag)
30313034
elif filepath.endswith('json'):
30323035
if not tacit:
@@ -5993,11 +5996,11 @@ POSITIONAL ARGUMENTS:
59935996
format: [title](url) <!-- TAGS -->
59945997
export Orgfile, if file ends with '.org'
59955998
format: *[[url][title]] :tags:
5996-
export rss feed if file ends with '.rss'
5999+
export rss feed if file ends with '.rss'/'.atom'
59976000
export buku DB, if file ends with '.db'
59986001
combines with search results, if opted
59996002
-i, --import file import bookmarks from file
6000-
supports .html .xbel .json .md .org .rss .db
6003+
supports .html .xbel .json .md .org .rss .atom .db
60016004
-p, --print [...] show record details by indices, ranges
60026005
print all bookmarks, if no arguments
60036006
-n shows the last n results (like tail)

buku.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ is a command-line utility to store, tag, search and organize bookmarks.
1818
* Powerful search options (regex, substring...)
1919
* Continuous search with on the fly mode switch
2020
* Portable, merge-able database to sync between systems
21-
* Import/export bookmarks from/to HTML, XBEL, Markdown, RSS or Orgfile
21+
* Import/export bookmarks from/to HTML, XBEL, Markdown, RSS/Atom or Orgfile
2222
* Smart tag management using redirection (>>, >, <<)
2323
* Multithreaded full DB refresh
2424
* Manual encryption support
@@ -241,7 +241,7 @@ has extension '.org' Orgfile format: * [[url][title]], 1 entry per line.
241241
.br
242242
RSS is used if
243243
.I file
244-
has extension '.rss' RSS format: <entry> per bookmark with <title>, <link>, <category>, <content> elements
244+
has extension '.rss'/'.atom' RSS format: <entry> per bookmark with <title>, <link>, <category>, <content> elements
245245
.br
246246
A buku database is generated if
247247
.I file
@@ -250,7 +250,7 @@ has extension '.db'.
250250
.BI \-i " " \--import " file"
251251
Import bookmarks from Firefox bookmarks formatted HTML.
252252
.I file
253-
is considered Firefox-exported JSON if it has '.json' extension, XBEL if it is '.xbel', Markdown (compliant with --export format) if it is '.md', Orgfile if the extension is '.org', RSS if the extension is '.rss' or another buku database if the extension is '.db'.
253+
is considered Firefox-exported JSON if it has '.json' extension, XBEL if it is '.xbel', Markdown (compliant with --export format) if it is '.md', Orgfile if the extension is '.org', RSS if the extension is '.rss'/'.atom' or another buku database if the extension is '.db'.
254254
.TP
255255
.BI \-p " " \--print " [...]"
256256
Show details (DB index, URL, title, tags and comment) of bookmark record by DB index. If no arguments, all records with actual index from DB are shown. Accepts hyphenated ranges and space-separated indices. A negative value (introduced for convenience) behaves like the tail utility, e.g., -n shows the details of the last n bookmarks.

tests/test_buku.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,17 +609,15 @@ def test_import_md(tmpdir, url, title, tags, newtag, exp_tags):
609609
assert res == ([] if not url else # `<>` and `[title]()` are not valid
610610
[(url, title or '', exp_tags, None, 0, True, False)])
611611

612-
@pytest.mark.parametrize(
613-
"newtag, exp_res",
614-
[
615-
(None, ("http://example.com", "text1", ",", None, 0, True, False)),
616-
("tag1", ("http://example.com", "text1", ",tag1,", None, 0, True, False)),
617-
],
618-
)
619-
def test_import_rss(tmpdir, newtag, exp_res):
612+
@pytest.mark.parametrize('newtag, exp_res', [
613+
(None, ('http://example.com', 'text1', ',', None, 0, True, False)),
614+
('tag1', ('http://example.com', 'text1', ',tag1,', None, 0, True, False)),
615+
])
616+
@pytest.mark.parametrize('extension', ['.rss', '.atom'])
617+
def test_import_rss(tmpdir, extension, newtag, exp_res):
620618
from buku import import_rss
621619

622-
p = tmpdir.mkdir("importrss").join("test.rss")
620+
p = tmpdir.mkdir('importrss').join('test' + extension)
623621
p.write(
624622
'<feed xmlns="http://www.w3.org/2005/Atom">\n'
625623
' <title>Bookmarks</title>\n'

tests/test_bukuDb.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ def custom_fetch(url, http_head=False):
10381038
' <title>Welcome to Python.org</title>',
10391039
' <desc>The official home...</desc>',
10401040
' </bookmark>',
1041-
'</xbel>',]),
1041+
'</xbel>']),
10421042
('html', ['<!DOCTYPE NETSCAPE-Bookmark-file-1>', '',
10431043
'<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">',
10441044
'<TITLE>Bookmarks</TITLE>', '<H1>Bookmarks</H1>', '',
@@ -1055,6 +1055,54 @@ def custom_fetch(url, http_head=False):
10551055
' <DD>The official home...',
10561056
' </DL><p>',
10571057
'</DL><p>']),
1058+
('rss', ['<feed xmlns="http://www.w3.org/2005/Atom">',
1059+
' <title>Bookmarks</title>',
1060+
' <generator uri="https://github.com/jarun/buku">buku</generator>',
1061+
' <entry>',
1062+
' <title>Fetched Title (DELETED)</title>',
1063+
' <link href="http://custom.url" rel="alternate" type="text/html"/>',
1064+
' <id>1</id>', # deleted entry, pre-deletion ID
1065+
' <content type="html"> <![CDATA[ <p>Fetched description.</p> ]]> </content>',
1066+
' </entry>',
1067+
' <entry>',
1068+
' <title>Wikipedia (OLD URL = http://wikipedia.net)</title>',
1069+
' <link href="https://www.wikipedia.org" rel="alternate" type="text/html"/>',
1070+
' <id>1</id>', # updated entry, current ID
1071+
' <category term="http:301"/>',
1072+
' <content type="html"> <![CDATA[ <p>Wikipedia is a free...</p> ]]> </content>',
1073+
' </entry>',
1074+
' <entry>',
1075+
' <title>Welcome to Python.org</title>',
1076+
' <link href="https://python.org/notfound" rel="alternate" type="text/html"/>',
1077+
' <id>2</id>',
1078+
' <category term="http:404"/>',
1079+
' <content type="html"> <![CDATA[ <p>The official home...</p> ]]> </content>',
1080+
' </entry>',
1081+
'</feed>']),
1082+
('atom', ['<feed xmlns="http://www.w3.org/2005/Atom">',
1083+
' <title>Bookmarks</title>',
1084+
' <generator uri="https://github.com/jarun/buku">buku</generator>',
1085+
' <entry>',
1086+
' <title>Fetched Title (DELETED)</title>',
1087+
' <link href="http://custom.url" rel="alternate" type="text/html"/>',
1088+
' <id>1</id>', # deleted entry, pre-deletion ID
1089+
' <content type="html"> <![CDATA[ <p>Fetched description.</p> ]]> </content>',
1090+
' </entry>',
1091+
' <entry>',
1092+
' <title>Wikipedia (OLD URL = http://wikipedia.net)</title>',
1093+
' <link href="https://www.wikipedia.org" rel="alternate" type="text/html"/>',
1094+
' <id>1</id>', # updated entry, current ID
1095+
' <category term="http:301"/>',
1096+
' <content type="html"> <![CDATA[ <p>Wikipedia is a free...</p> ]]> </content>',
1097+
' </entry>',
1098+
' <entry>',
1099+
' <title>Welcome to Python.org</title>',
1100+
' <link href="https://python.org/notfound" rel="alternate" type="text/html"/>',
1101+
' <id>2</id>',
1102+
' <category term="http:404"/>',
1103+
' <content type="html"> <![CDATA[ <p>The official home...</p> ]]> </content>',
1104+
' </entry>',
1105+
'</feed>']),
10581106
])
10591107
def test_export_on(bukuDb, ext, expected):
10601108
'''Testing exportdb() behaviour after update_rec() with export_on'''

0 commit comments

Comments
 (0)