-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail2rss.py
54 lines (47 loc) · 1.27 KB
/
mail2rss.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
#!/usr/bin/env python
import email, sys, re, PyRSS2Gen, feedparser, datetime
ME="[email protected]"
FEEDTITLE="shared items"
FEEDFILE="/var/www/rss/share.rss"
FEEDSELF="http://somewhere.com/rss/share.rss"
FEEDDESC="stuff on the web I thought was cool"
FEEDITEMCT=20
URLMATCH='URL:.*?<a href="(.*?)">.*?</a>'
m = email.message_from_string(sys.stdin.read())
#m.get('From') == ME or exit
newtitle = re.sub(r'FW[D][:]', '', m.get('Subject'), re.I)
newdate=datetime.datetime.utcnow()
newdate = m.get('Date')
newurl = ""
allurls = re.findall(URLMATCH, m.get_payload(decode=True))
newurl = allurls[0]
if newurl and newtitle:
allitems = [
PyRSS2Gen.RSSItem(
title = newtitle,
link = newurl,
guid = PyRSS2Gen.Guid(newurl),
pubDate = newdate
)
]
feedin=feedparser.parse(FEEDFILE)
ct = 1
for entry in feedin.entries:
allitems.append (
PyRSS2Gen.RSSItem(
title = entry.title,
link = entry.link,
guid = PyRSS2Gen.Guid(entry.link),
pubDate = entry.updated
))
ct += 1
if ct >= FEEDITEMCT:
break
feedout = PyRSS2Gen.RSS2(
title = FEEDTITLE,
link = FEEDSELF,
description = FEEDDESC,
lastBuildDate = datetime.datetime.utcnow(),
items = allitems
)
feedout.write_xml(open(FEEDFILE, "w"))