Commit e33ea827 authored by Kyryll Parolis's avatar Kyryll Parolis
Browse files

Added mail notification.

parent 066a12e8
......@@ -8,3 +8,4 @@ src/pipelines/__pycache__
src/spiders/__pycache__
src/alembic/versions/__pycache__
src/alembic/__pycache__
log.txt
......@@ -4,14 +4,11 @@
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/spider-middleware.html
import scrapy
from dotenv import load_dotenv
from scrapy import signals
import os
from scrapy.mail import MailSender
import settings
from scrapy.utils.project import get_project_settings
class BuildzoomParserSpiderMiddleware:
......@@ -76,17 +73,20 @@ class BuildzoomParserDownloaderMiddleware:
return s
def process_request(self, request, spider):
request.meta['proxy'] = os.getenv('http_proxy')
# request.meta['proxy'] = os.getenv('http_proxy')
pass
def process_response(self, request, response: scrapy.http.Response, spider):
mailer = MailSender().from_settings(settings)
def process_response(self, request, response, spider):
mailer = MailSender(mailfrom='kyryllpar@gmail.com', smtphost='smtp.gmail.com', smtpport=587,
smtpuser='kyryllpar@gmail.com', smtppass='Bc279811')
if response.status == 407:
mailer.send(subject="407 status code <buildzoom_parser>",
mailer.send(to=["kyryllpar@gmail.com"],
subject="407 status code <buildzoom_parser>",
body="Proxy authentication required.",
cc=["another@example.com"])
elif response.status == 429:
mailer.send(subject="429 status code <buildzoom_parser>",
mailer.send(to=["kyryllpar@gmail.com"],
subject="429 status code <buildzoom_parser>",
body="Too many requests.",
cc=["another@example.com"])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment