5 from optparse import OptionParser
6 from textwrap import dedent
9 from get_renewees import get_members_which_need_renewal, send_email
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 __author__ = "Tobias Mueller"
25 __license__ = "GPLv3+"
26 __email__ = "tobiasmue@gnome.org"
31 as per point 1.3 of [1], here it comes a list of members in need of a
32 renew in case they didn't receive their individual e-mail:
34 First name, Last name (Last renewed on)
37 The Renewal form can be found at [2].
40 GNOME Membership and Elections Committee
42 [1] https://mail.gnome.org/archives/foundation-list/2011-November/msg00000.html
43 [2] http://www.gnome.org/foundation/membership/apply/
47 def format_members_for_mail(members, template=TEMPLATE):
48 fmt = " * %(firstname)s, %(lastname)s (%(token_or_last_renewed_on)s)"
49 member_lines = [fmt % member.__dict__ for member in members]
51 members_formatted = '\n'.join(member_lines)
53 mail = template % {'members': members_formatted}
57 def main(options=None):
58 log = logging.getLogger()
60 options = options or {}
63 template = open(options.template, 'r').read()
68 to = options.recipient
70 to = 'foundation-list@gnome.org'
73 sendmail = options.sendmail
79 members = get_members_which_need_renewal('month')
81 log.warn('No one needs renewals! :-)')
83 else: # We do have members
84 emailtext = format_members_for_mail(members)
86 today = datetime.date.today()
87 subject = "Memberships needing renewal (%s)" % today.strftime("%02Y-%02m")
90 log.warn('Sending mail to %s: %s', to, subject)
91 send_email(to, subject, emailtext)
93 log.info('Not sending mail to %s', to)
94 log.info('%s', subject)
95 log.info('%s', emailtext)
99 if __name__ == "__main__":
100 parser = OptionParser()
101 parser.add_option("-f", "--from-address", dest="fromaddress",
102 help="Use that as sending address [default: %default]",
103 default="Tobias Mueller <tobiasmue@gnome.org>")
104 parser.add_option("-s", "--send-mail", dest="sendmail",
105 help="Do indeed send mail [default: %default]",
108 parser.add_option("-l", "--loglevel", dest="loglevel",
109 help="Sets the loglevel to one of debug, info, warn, "
110 "error, critical", default="info")
111 parser.add_option("-r", "--recipient", dest="recipient",
112 help="Address to send an email to",
114 parser.add_option("-t", "--template", dest="template",
115 help="Use this file as a template, instead of the "
116 "hardcoded default one. "
117 "Please look at the source to see the available "
120 (options, args) = parser.parse_args()
121 loglevel = {'debug': logging.DEBUG, 'info': logging.INFO,
122 'warn': logging.WARN, 'error': logging.ERROR,
123 'critical': logging.CRITICAL}.get(options.loglevel, "warn")
124 LOGFORMAT = "%(asctime)s %(levelname)-8s %(name)s %(message)s"
125 DATEFORMAT = '%Y-%m-%d %H:%M:%S'
126 logging.basicConfig(level=loglevel, format=LOGFORMAT, datefmt=DATEFORMAT)
127 log = logging.getLogger('main')
129 sys.exit (main (options))