-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-export-from-liferea.py
68 lines (51 loc) · 2.02 KB
/
01-export-from-liferea.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
import sqlite3
import json
def dictionary_from_query(cur, query):
cur.execute(query)
items = []
for data in cur.fetchall():
columns = [x[0] for x in cur.description]
output = {}
for entry in zip(columns, data):
output[entry[0]] = entry[1]
items.append(output)
return items
try:
with sqlite3.connect("liferea.db") as con:
cur = con.cursor()
items = dictionary_from_query(cur, "select * from items")
subscription = dictionary_from_query(cur, "select * from subscription")
metadata = dictionary_from_query(cur, "select * from metadata")
newsbeuter_items = []
for item in items:
newsbeuter_item = {}
feedurl = [x['source'] for x in subscription if x['node_id'] == item['node_id']]
if len(feedurl) == 0:
feedurl = ""
else:
feedurl = feedurl[0]
author = [x['value'] for x in metadata if x['item_id'] == item['item_id'] and x['key'] == "author"]
if len(author) == 0:
author = ""
else:
author = author[0]
newsbeuter_item['feedurl'] = feedurl
newsbeuter_item['unread'] = not item['read']
newsbeuter_item['pubDate'] = item['date']
newsbeuter_item['author'] = author
newsbeuter_item['url'] = item['source']
newsbeuter_item['title'] = item['title']
newsbeuter_item['content'] = item['description']
newsbeuter_item['guid'] = item['source_id']
newsbeuter_item['enqueued'] = 0
newsbeuter_item['enclosure_type'] = ""
newsbeuter_item['enclosure_url'] = ""
newsbeuter_item['flags'] = ""
newsbeuter_item['base'] = ""
newsbeuter_item['deleted'] = 0
newsbeuter_items.append(newsbeuter_item)
print json.dumps(newsbeuter_items, indent=2)
except sqlite3.Error, e:
print "Error %s" % (e.args[0])
sys.exit(1)