Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added wrapper functions for scraper to pipe errors to email. #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified BruinBiteSecrets.tar.gz
Binary file not shown.
19 changes: 13 additions & 6 deletions menu_backend/menu_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
]

CRONJOBS = [
('*/5 * * * *', 'scraper.db_insertion.insert_activity_level'),
('*/5 * * * *', 'scraper.db_insertion.insert_activity_level_wrapper'),
# everything else runs three times a day: one at 0:01, one at 10:00, one at 15:30
('1 0 * * *', 'scraper.db_insertion.insert_hours'),
('0 10 * * *', 'scraper.db_insertion.insert_hours'),
('30 15 * * *', 'scraper.db_insertion.insert_hours'),
('0 3 * * *', 'scraper.db_insertion.insert_slow_scrape'),
('1 * * * *', 'scraper.db_insertion.insert_hourly_scrape')
('1 0 * * *', 'scraper.db_insertion.insert_hours_wrapper'),
('0 10 * * *', 'scraper.db_insertion.insert_hours_wrapper'),
('30 15 * * *', 'scraper.db_insertion.insert_hours_wrapper'),
('0 3 * * *', 'scraper.db_insertion.insert_slow_scrape_wrapper'),
('1 * * * *', 'scraper.db_insertion.insert_hourly_scrape_wrapper')
]

MIDDLEWARE = [
Expand Down Expand Up @@ -146,3 +146,10 @@
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]


EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT=587
EMAIL_HOST_USER="[email protected]"
EMAIL_HOST_PASSWORD=os.getenv('ERRORS_EMAIL_PASSWORD')
EMAIL_USE_TLS=True
35 changes: 35 additions & 0 deletions menu_backend/scraper/db_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,44 @@
from .models import *
from datetime import date
from .scraper_thread import Scraper_thread
from django.core.mail import send_mail

days_to_scrape = 7

def sendLogEmail(err, funcName):
print(funcName + "() threw an error: \n" + str(err))
send_mail(
'Error in menu scraper',
'Error in function ' + funcName + "() with the following message: \n" + str(err),
'[email protected]',
['[email protected]'],
fail_silently=False)

def insert_activity_level_wrapper():
try:
insert_activity_level()
except Exception as err:
sendLogEmail(err, "insert_activity_level")

def insert_hours_wrapper():
try:
insert_hours()
except Exception as err:
sendLogEmail(err, "insert_hours")

def insert_slow_scrape_wrapper():
try:
insert_slow_scrape()
except Exception as err:
sendLogEmail(err, "insert_slow_scrape")

def insert_hourly_scrape_wrapper():
try:
insert_hourly_scrape()
except Exception as err:
sendLogEmail(err, "insert_hourly_scrape")


def insert_activity_level():
activity_level = scraper_for_activity_level()
ActivityLevel.objects.create(level=activity_level)
Expand Down