-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMailingList.py
140 lines (114 loc) · 4.33 KB
/
MailingList.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- Mode: python; coding: utf-8 -*-
#
# Cherokee Web Site
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
import os
import CTK
import time
import urllib
import feedparser
ML_RSS_URL = "http://groups.google.com/group/cherokee-http/feed/atom_v1_0_msgs.xml?num=50"
CACHE_EXPIRATION = 30 * 60 #30mins
#
# Internals
#
def get_mailing_list_subjects():
# Fetch
d = feedparser.parse (ML_RSS_URL)
# Parse
subjects = {}
subject_list = []
month_link = ''
month_page = ''
for entry in d['entries']:
date = entry['updated'][:10]
author = entry['author']
nick = author.split(' ')[0]
link = 'http://lists.octality.com/pipermail/cherokee/%s/thread.html' % (time.strftime("%Y-%B", time.strptime(date, "%Y-%m-%d")))
if month_link != link:
month_link = link
month_page = urllib.urlopen(month_link).read()
# Clean title
title = entry['title']
if title.lower().startswith("re: "):
title = title[4:]
if title.lower().startswith("[cherokee] "):
title = title[11:]
if len(title) > 45:
title = title[:45] + " .."
# Clean author
n = author.find ('(')
if n != -1:
author = author[:n-1]
if not subjects.has_key(title):
subjects[title] = {'hits':1}
subject_list.append(title)
else:
subjects[title]['hits'] += 1
if not subjects[title].has_key('date'):
subjects[title]['date'] = time.strftime("%b %d", time.strptime(date, "%Y-%m-%d"))
if not subjects[title].has_key('authors'):
subjects[title]['authors'] = []
if not nick in subjects[title]['authors']:
subjects[title]['authors'] += [nick]
if not subjects[title].has_key('link'):
try:
thread_link = get_thread_link (month_page, title[:45])
link = link.split('thread.html')[0] + thread_link
except:
pass
subjects[title]['link'] = link
return (subjects, subject_list)
#
# Widget
#
class Latest_Mailing_List_Widget (CTK.Box):
def __init__ (self, limit=6):
CTK.Box.__init__ (self, {'id': 'mailing-list'})
self += CTK.Box({'class': 'bar3-title'}, CTK.RawHTML('<a href="http://lists.octality.com/listinfo/cherokee" target="_blank">Mailing List</a>'))
ret = get_mailing_list_subjects()
subjects, subject_list = ret
for s in subject_list[:limit]:
subject = subjects[s]
authors = '(%s)' %(', '.join(subject['authors']))
content_box = CTK.Box({'class': 'mail'})
date_box = CTK.Box({'class': 'date'})
date_box += CTK.RawHTML(subject['date'])
content_box += date_box
box = CTK.Box({'class': 'mail-txt'})
box += CTK.LinkWindow (subject['link'], CTK.RawHTML(s))
box += CTK.RawHTML ('<br/>by %s, %s messages'%(authors, subject['hits']))
content_box += box
self += content_box
self += CTK.Box({'class': 'bar3-bottom-link'}, CTK.RawHTML('<a href="http://lists.octality.com/listinfo/cherokee" target="_blank">Subscribe to Cherokee Mailing List »</a>'))
#
# Factory and cache
#
latest_widget = None
latest_widget_expiration = None
def Latest_Mailing_List():
global latest_widget
global latest_widget_expiration
if not latest_widget or time.time() > latest_widget_expiration:
latest_widget = Latest_Mailing_List_Widget()
latest_widget_expiration = time.time() + CACHE_EXPIRATION
return latest_widget