Skip to content

Commit 12e13af

Browse files
committedAug 19, 2020
added: bug detected email
1 parent 2d1d20e commit 12e13af

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed
 

‎details_soup.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ def contest_rating_details_get():
8686
start_ind = page.text.find('[', page.text.find('all_rating'))
8787
end_ind = page.text.find(']', start_ind) + 1
8888

89-
next_opening_brack = page.text.find('[', start_ind+1)
90-
while next_opening_brack < end_ind:
91-
end_ind = page.text.find(']', end_ind+1) + 1
92-
next_opening_brack = page.text.find('[', next_opening_brack+1)
89+
# next_opening_brack = page.text.find('[', start_ind+1)
90+
# while next_opening_brack < end_ind:
91+
# end_ind = page.text.find(']', end_ind+1) + 1
92+
# next_opening_brack = page.text.find('[', next_opening_brack+1)
9393

9494
all_rating = json.loads(page.text[start_ind: end_ind])
9595
for rating_contest in all_rating:

‎main.py

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from flask_cors import CORS
44

55
from details_soup import UserData, UsernameError, PlatformError
6+
from send_mail import Mail
67

78
app = Flask(__name__)
89
CORS(app)
@@ -23,6 +24,12 @@ def get(self, platform, username):
2324
except PlatformError:
2425
return {'status': 'Failed', 'details': 'Invalid Platform'}
2526

27+
except Exception as e:
28+
# Reporting bug to me via Email for faster bug detection
29+
# Comment this part
30+
mail = Mail()
31+
mail.send_bug_detected()
32+
2633

2734
api.add_resource(Details,'/api/<string:platform>/<string:username>')
2835

‎send_mail.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import smtplib
2+
import datetime
3+
import os
4+
5+
6+
class Mail:
7+
def __init__(self):
8+
self.__timeStamp = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%Z")
9+
self.__server = smtplib.SMTP('smtp.gmail.com', 587)
10+
11+
self.__server.ehlo()
12+
self.__server.starttls()
13+
self.__server.ehlo()
14+
15+
self.__server.login(os.environ.get("g_mail"), os.environ.get("g_pass"))
16+
17+
def send_bug_detected(self):
18+
subject = 'Bug detected in Competitive Programming Score API'
19+
body = 'Bug detected in Competitive Programming Score API at {date}.\n'.format(date=self.__timeStamp)
20+
21+
body += '\nCheck logs for more information\n'
22+
body += 'https://dashboard.heroku.com/apps/competitive-coding-api/logs'
23+
24+
message = f'Subject : {subject}\n\n{body}\n'
25+
26+
self.__server.sendmail('', ['abhijeet_abhi@live.co.uk'], message)
27+
28+
29+
if __name__ == '__main__':
30+
mail = Mail()
31+
mail.send_bug_detected()

0 commit comments

Comments
 (0)
Please sign in to comment.