-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedfdw.py
More file actions
55 lines (47 loc) · 1.83 KB
/
feedfdw.py
File metadata and controls
55 lines (47 loc) · 1.83 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from . import ForeignDataWrapper
from datetime import datetime, timedelta
from logging import ERROR, WARNING
from multicorn.utils import log_to_postgres
import json
import feedparser
class FeedFdw(ForeignDataWrapper):
def __init__(self, options, columns):
super(FeedFdw, self).__init__(options, columns)
self.url = options.get('url', None)
if self.url is None:
log_to_postgres("You musT set an url when creating the table.", ERROR)
def execute(self, quals, columns):
try:
entries = []
d = feedparser.parse(self.url)
for e in d.entries:
entry = []
"""
prob should switch these to named entries?
entry.append(["id", e.id])
entry.append(["link", e.link])
entry.append(["title", e.title])
entry.append(["published", e.published])
entry.append(["updated", e.updated])
entry.append(["summary", e.summary])
entry.append(["content", e.content])
"""
entry.append(e.id)
entry.append(e.link)
entry.append(e.title)
entry.append(e.published)
entry.append(e.updated)
entry.append(e.summary)
if e.content:
entry.append(e.content[0].value)
else:
entry.append('')
# if e.description:
# entry.append(e.description[0].value)
# else:
# entry.append(e.description[0].value)
#
entries.append(entry)
return entries
except IOError:
log_to_postgres("Cannot retrieve '%s'" % self.url, WARNING)