-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSC_web.py
executable file
·88 lines (55 loc) · 2.61 KB
/
SSC_web.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
#!/usr/bin/env python
'''----------------------------------------------------------------------------
License:
This program is free software: you can redistribute it and/or modify
it. 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.
If you use this software (or a part of it) in your research, please cite
the authors. For more information how to cite this work properly please
visit the official webside. THANKS!
http://ssc.sheffield.ac.uk
SSC_web.py
The Flask framework is used to develop web applications.
http://flask.pocoo.org
----------------------------------------------------------------------------'''
import web.framework
import datetime
import smtplib
import sys
import os
__author__ = ["Gyenge, Norbert", "Yu, Haidong"]
__email__ = ["[email protected]", "[email protected]"]
# SETUP -------------------------------------------------------------------'''
# STEP 1: Define the ip address of the server. 127.0.0.1 for local server.
ip = '127.0.0.1'
# STEP 2: Define the port. Must be integer.
port = 5000
# SETUP -------------------------------------------------------------------'''
# Switching off the maintenance site
if os.path.isfile('web/templates/maintenance.html') is True:
os.rename('web/templates/maintenance.html', 'web/templates/maintenance_off.html')
try:
# Start the Flask server
web.framework.start(ip, port)
except:
# Do not send email if KeyboardInterrupt()
if "KeyboardInterrupt()" not in str(sys.exc_info()):
# Send an email if server fails
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("[email protected]", "sscerror1234")
# Compose the email
SUBJECT = "SSC Server failed at " + str(datetime.datetime.now())
TO = "[email protected]"
FROM = "[email protected]"
text1 = "Dear SSC Admins,\n\n"
text2 = "The SSC server is terminated due an unexpected error:\n\n"
text3 = str(sys.exc_info()) + "\n" + str(datetime.datetime.now())
text4 = "\n\n SSC Web Service"
BODY = "\r\n".join(["From: %s" % FROM, "To: %s" % __email__[0],
"Subject: %s" % SUBJECT , "", text1+text2+text3+text4])
server.sendmail(FROM, __email__[0], BODY)
server.quit()
# Maintenance page activation
os.rename('web/templates/maintenance_off.html', 'web/templates/maintenance.html')