-
Notifications
You must be signed in to change notification settings - Fork 0
/
del2atom
executable file
·62 lines (49 loc) · 1.92 KB
/
del2atom
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
#!/usr/bin/env python
# encoding: utf-8
"""Grab the latest delicious.com links and turn them into an Atom feed"""
import sys, re
import feedparser
import feed2atom
USER = 'bbolli'
FEED_FMT = 'http://feeds.delicious.com/v2/rss/%s' # ?count=50'
VIDEO_RE = re.compile(r'(?i)youtube\.com/watch\?')
class DeliciousToAtom(feed2atom.FeedToAtom):
def __init__(self):
self.db_file = '/var/local/del2atom.latest'
try:
self.latest = open(self.db_file).read()
except (IOError, OSError):
self.latest = '2000-01-01'
self.new_latest = self.latest
def __del__(self):
if self.new_latest > self.latest:
open(self.db_file, 'w').write(self.new_latest)
def filter(self, entry):
ts = feed2atom.isodate(entry.updated_parsed)
if ts > self.latest:
self.new_latest = max(self.new_latest, ts)
return True
def post_process(self, entry):
self.entry['category':] = {'scheme': 'http://drbeat.li', 'term': 'delicious-link'}
if entry.link.endswith('.jpg'):
self.entry['link':] = {'rel': 'enclosure', 'type': 'image/jpg', 'href': entry.link}
elif entry.link.endswith('.png'):
self.entry['link':] = {'rel': 'enclosure', 'type': 'image/png', 'href': entry.link}
elif entry.link.endswith('.mp3'):
self.entry['link':] = {'rel': 'enclosure', 'type': 'audio/mp3', 'href': entry.link}
elif VIDEO_RE.search(entry.link):
self.entry['link':] = {'rel': 'enclosure', 'type': 'video/x-flash', 'href': entry.link}
def run(self, user):
feed = feedparser.parse(FEED_FMT % user)
try:
print self.convert(feed).encode('utf-8')
except:
import pprint
pprint.pprint(feed)
print
raise
if __name__ == '__main__':
if len(sys.argv) == 2:
DeliciousToAtom().run(sys.argv[1])
else:
DeliciousToAtom().run(USER)