-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.py
More file actions
36 lines (32 loc) · 1.16 KB
/
atom.py
File metadata and controls
36 lines (32 loc) · 1.16 KB
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
import requests
from lxml import etree
import time
import dateutil.parser
import rsstastic
class AtomReader() :
def __init__(self,config) :
self.url = config
def get_items(self) :
namespace = "{http://www.w3.org/2005/Atom}"
response = requests.get(self.url)
tree = etree.fromstring(response.content)
root = tree
items = {}
for item in root.findall(namespace+'entry') :
atomid = item.find(namespace+'id').text
summary = item.find(namespace+'summary')
if summary == None :
title = item.find(namespace+'title').text
link = item.find(namespace+'link').get('href')
summary = '<a href="{}">{}</a>'.format(link,title)
else :
summary = summary.text
updated = int(dateutil.parser.parse(item.find(namespace+'updated').text).timestamp())
items[atomid] = (updated,summary)
return items
def retrieve(self,key,item) :
return item[1]
rsstastic.readermap['atom'] = AtomReader
if __name__ == "__main__" :
x = AtomReader("http://xkcd.com/atom.xml")
print(x.get_items())