-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
68 lines (47 loc) · 1.65 KB
/
fabfile.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
import os
import smtplib
from email.mime.text import MIMEText
from dateutil.rrule import rrule, MONTHLY, TU
from dateutil.parser import parse as dateutil_parse
from fabric.api import task, prompt, local
from fabric.utils import abort, fastprint
@task
def new_meeting():
with open('_templates/meeting.txt.tpl', 'r') as f:
meeting_template = f.read()
date_prompt = dateutil_parse(prompt('Date:'))
title_prompt = prompt('Title:')
date = list(rrule(MONTHLY, count=1, byweekday=TU, bysetpos=2,
dtstart=date_prompt))[0]
filepath = 'meetings/{0}.txt'.format(date.strftime('%Y-%m'))
if os.path.isfile(filepath):
return abort('Meeting already exists.')
data = {
'date': date,
'title': title_prompt,
'body': '====\nREPLACE\n===='
}
with open(filepath, 'w') as f:
f.write(meeting_template.format(**data))
@task
def send_meeting():
date = prompt('Date:', validate=r'(\d{4})-(\d{2})')
subject = prompt('Subject:')
email_from = 'hi@gtalug.org'
email_to = 'announce@gtalug.org'
filepath = 'meetings/{0}.txt'.format(date)
local('git pull')
if not os.path.isfile(filepath):
return abort('There is no meeting at that date.')
with open(filepath, 'r') as f:
msg = MIMEText(f.read())
msg['Subject'] = subject
msg['From'] = email_from
msg['To'] = email_to
preview = "{0}".format(msg.as_string())
fastprint(preview)
send = prompt('Everything look okay?', validate=r'(yes|no)')
if send == 'yes':
s = smtplib.SMTP('127.0.0.1')
s.sendmail(email_from, [email_to], msg.as_string())
s.quit()