-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeeder.py
76 lines (69 loc) · 2.94 KB
/
feeder.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
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
import feedparser
from random import choice
from pickle import dump, load
from time import time, localtime, asctime
class GoogleNews(object):
TEMPLATE = 'http://news.google.com/news?pz=1&cf=all&ned=%(territory)s&hl=%(language)s&topic=%(topic)s&output=rss'
FEED = {
'ko' : {
'ned' : 'kr',
'topics' : {
'w' : u'국제',
'b' : u'경제',
'y' : u'사회',
'l' : u'문화/생활',
'p' : u'정치',
't' : u'정보과학',
'e' : u'연예',
's' : u'스포츠',
'po' : u'인기뉴스',
},
'lang' : u'한국어'
},
'us' : {
'ned' : 'en',
'topics' : {
'w' : u'WORLD',
'm' : u'HEALTH',
'b' : u'BUSINESS',
'e' : u'ENTERTAIN',
'tc' : u'TECHNOLOGY',
'snc' : u'SCIENCE',
's' : u'SPORTS',
'ir' : u'SPOTLIGHT',
},
'lang' : u'English'
},
'zh-CN' : {
'ned' : 'cn',
'topics' : {
'b' : u'财经',
'y' : u'社会',
'w' : u'国际/港台',
't' : u'科技',
'e' : u'娱乐',
's' : u'体育',
'po' : u'热门报道',
},
'lang' : u'中文'
}
}
def __init__(self, locale):
self.locale = locale
def checkPickledFeed(self):
return False
def getRSS(self, topic):
if not self.checkPickledFeed():
return feedparser.parse(self.TEMPLATE % {'topic' : topic,
'territory' : self.FEED[self.locale]['ned'],
'language' : self.locale,
}).entries
def getAllTopics(self):
return self.FEED[self.locale]['topics']
@classmethod
def getAllLocales(self):
return self.FEED.keys()
@classmethod
def getLangFromLocale(cls, locale):
return cls.FEED[locale]['lang']