-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
78 lines (72 loc) · 2.38 KB
/
server.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
import apscheduler.scheduler as sch
import config
import so.process
import bottle as bt
import emailsender as es
import log as Log
from pushover.target import pushover
log = Log.getLogger('server')
sched = sch.Scheduler()
sched.start()
@Log.fn_logger(log.debug)
@sched.cron_schedule(day = '1-31', hour = '8', minute = '0')
def so_growth_stats_mail():
'''Sends statistics of stack overflow'''
# Collect results
top_day_growth, top_week_growth, top_month_growth = so.process.get_growth_results()
# Create a template
msg = bt.template('so_stats',
top_day_growth = top_day_growth,
top_week_growth = top_week_growth,
top_month_growth = top_month_growth
)
#Send to email results
es.sendmail(
frm = config.Config().get_conf("mail", "from_addr"),
to = config.Config().get_conf("mail", "recipient"),
subject = "Stack Overflow Statistics",
message = msg,
login = config.Config().get_conf("mail", "user-login"),
password = config.Config().get_conf("mail", "password")
)
@Log.fn_logger(log.debug)
@sched.cron_schedule(day = '1-31', hour = '5,17', minute = '0')
def so_bulletin_mail():
# Collect the results
questions = so.process.so_bulletin_get()
if not questions:
return
# Create the template
msg = bt.template('so_bulletin',questions=questions)
# Send the email
es.sendmail(
frm = config.Config().get_conf("mail", "from_addr"),
to = config.Config().get_conf("mail", "recipient"),
subject = "Stack Overflow Bulletin",
message = msg,
login = config.Config().get_conf("mail", "user-login"),
password = config.Config().get_conf("mail", "password")
)
# Save the result
so.process.save_questions(questions)
@Log.fn_logger(log.debug)
@sched.cron_schedule(day = '1-31', hour = '8,16,17,21', minute = '0,5,10,15,20,25,30,35,40,45,50,55')
def so_potential_answer_push_notification():
log.info('so_potential_answer_push_notification')
# Collect the results
questions = so.process.so_potential_answer_get(minutes = 3)
log.info('%d questions' % len(questions))
# Send the push notifications
for q in questions:
pushover().send_notification(
token = config.Config().get_conf("pushover", "token"),
user = config.Config().get_conf("pushover", "user"),
title = "SO Question",
message = q["title"],
url = q["link"]
)
# Save the result
so.process.save_questions(questions)
s = ""
while not s or s[0]!= "q":
s = raw_input('Hit q<Enter> to finish')