-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.py
More file actions
64 lines (53 loc) · 2.03 KB
/
mail.py
File metadata and controls
64 lines (53 loc) · 2.03 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
from datetime import datetime
from datetime import timedelta
from google.appengine.api import mail
from search import search_posts
from config import EMAIL_SENDER
from config import EMAIL_DOMAIN
def send_report(user):
now = datetime.now()
first_day_this_month = datetime(now.year, now.month, 1)
last_day_last_month = first_day_this_month - timedelta(days=1)
first_day_last_month = datetime(
last_day_last_month.year,
last_day_last_month.month,
1
)
subject = 'Social Keep | %s Report' % last_day_last_month.strftime('%B') # e.g. 'Jan 2014'
body = ''
author = user.author or user.first_name
for page in user.pages:
from_date = first_day_last_month.strftime('%Y-%m-%d')
to_date = last_day_last_month.strftime('%Y-%m-%d')
link = EMAIL_DOMAIN + '/pages/%s?from=%s&to=%s&author=%s' % (
page.key.id(),
from_date,
to_date,
author,
)
results = search_posts(
page,
'created_time >= %s AND created_time <= %s AND author: %s' % (from_date, to_date, author)
)
body += '%s\nYou (%s) have been involved in %s post(s) and %s comment(s).\n%s\n\n' % (
page.name,
author,
results['nr_of_posts'],
results['nr_of_comments'],
link
)
body += '\nThis report was generated by Social Keep on the basis of posts you signed with "/%s".\n' % author
body += 'The report includes only Facebook pages you administer and is generated once a month.\n'
body += 'Social Keep is a product of The Danish Agency of Higher Education to aid public officials to journal and keep their communication on social media for future reference.\n'
body += 'Want this product for other fellow officials? Sign them up at %s.\n\n' % EMAIL_DOMAIN
body += 'Product Technology provided by Thulin Industries.\n\n'
body += 'Not interested in receiving these emails anymore? You can delete your account here: %s' % (
EMAIL_DOMAIN + '/settings'
)
print body
mail.send_mail(
sender=EMAIL_SENDER,
to="%s <%s>" % (user.name, user.email),
subject=subject,
body=body
)