forked from kihashi/mtg-irc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.py
More file actions
96 lines (70 loc) · 2.41 KB
/
article.py
File metadata and controls
96 lines (70 loc) · 2.41 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'''
This module allows a bot to give out the 5 most recent articles from a site.
Author: John Cleaver
License: BSD 3 Clause.
'''
import feedparser
rss = {
'scg': 'http://www.starcitygames.com/rss/rssfeed.xml',
'tcg': 'http://www.tcgplayer.com/RSS/rssfeed.xml',
'mtg': 'http://www.wizards.com/Magic/Magazine/rss.aspx',
'gm': 'http://www.gatheringmagic.com/feed/',
'cf': 'http://www.channelfireball.com/feed/rss/'
}
def get_rss(site):
rss_data = feedparser.parse(rss[site])
return rss_data
def get_articles(site):
rss_data = get_rss(site)
length = min(rss_data.entries, 5)
return rss_data.entries[:length]
def article(phenny, input):
switch = {
'scg' : get_scg_articles,
'tcg' : get_scg_articles,
'mtg' : get_mtg_articles,
'gm' : get_gm_articles,
'cf' : get_cf_articles
}
if not input.group(2):
phenny.reply('Perhaps you meant to specify a site?')
else:
if input.group(2).lower() not in rss:
phenny.reply('That is not a site that I know of.')
else:
articles = switch[input.group(2)]()
for article in articles:
phenny.reply(article)
article.commands = ['article']
article.priority = 'medium'
article.example = '.article scg'
def get_scg_articles():
raw_articles = get_articles('scg')
article_list = []
for article in raw_articles:
article_list.append(article['title'] + " | " + article['link'])
return article_list
def get_tcg_articles():
raw_articles = get_articles('tcg')
article_list = []
for article in raw_articles:
article_list.append(article['title'] + " | " + article['link'])
return article_list
def get_mtg_articles():
raw_articles = get_articles('mtg')
article_list = []
for article in raw_articles:
article_list.append(article['title'] + " | " + article['author'] + " | " + article['link'])
return article_list
def get_gm_articles():
raw_articles = get_articles('gm')
article_list = []
for article in raw_articles:
article_list.append(article['title'] + " | " + article['author'] + " | " + article['link'])
return article_list
def get_cf_articles():
raw_articles = get_articles('cf')
article_list = []
for article in raw_articles:
article_list.append(article['title'] + " | " + article['author'] + " | " + article['link'])
return article_list