-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API for sending text via Slack, Telegram, or Email (#83)
- Loading branch information
Showing
30 changed files
with
1,037 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
DOCS: https://github.com/my8100/files/blob/master/scrapydweb/README.md | ||
文档:https://github.com/my8100/files/blob/master/scrapydweb/README_CN.md | ||
""" | ||
import os | ||
|
||
|
||
############################## QUICK SETUP start ############################## | ||
|
@@ -174,51 +175,50 @@ | |
DAEMONSTATUS_REFRESH_INTERVAL = 10 | ||
|
||
|
||
############################## Email Notice ################################### | ||
# In order to be notified (and stop or forcestop a job when triggered) in time, | ||
# you can reduce the value of POLL_ROUND_INTERVAL and POLL_REQUEST_INTERVAL, | ||
# at the cost of burdening both CPU and bandwidth of your servers. | ||
|
||
# Tip: set SCRAPYDWEB_BIND to the actual IP of your host, then you can visit ScrapydWeb | ||
# via the links attached in the email. (check out the "ScrapydWeb" section above) | ||
|
||
# Check out this link if you are using ECS of Alibaba Cloud and your SMTP server provides TCP port 25 only: | ||
# https://www.alibabacloud.com/help/doc-detail/56130.htm | ||
|
||
# The default is False, set it to True to enable email notification. | ||
ENABLE_EMAIL = False | ||
|
||
########## smtp settings ########## | ||
SMTP_SERVER = '' | ||
SMTP_PORT = 0 | ||
SMTP_OVER_SSL = False | ||
|
||
# Config for https://mail.google.com using SSL | ||
# SMTP_SERVER = 'smtp.gmail.com' | ||
# SMTP_PORT = 465 | ||
# SMTP_OVER_SSL = True | ||
|
||
# Config for https://mail.google.com | ||
# SMTP_SERVER = 'smtp.gmail.com' | ||
# SMTP_PORT = 587 | ||
# SMTP_OVER_SSL = False | ||
|
||
# Config for https://mail.qq.com/ using SSL | ||
# SMTP_SERVER = 'smtp.qq.com' | ||
# SMTP_PORT = 465 | ||
# SMTP_OVER_SSL = True | ||
|
||
# Config for http:https://mail.10086.cn/ | ||
# SMTP_SERVER = 'smtp.139.com' | ||
# SMTP_PORT = 25 | ||
# SMTP_OVER_SSL = False | ||
|
||
# The timeout in seconds for the connection attempt, the default is 10. | ||
SMTP_CONNECTION_TIMEOUT = 10 | ||
|
||
########## sender & recipients ########## | ||
# Leave this option as '' to default to the FROM_ADDR option below; Otherwise, set it up | ||
# if your email service provider requires an username which is different from the FROM_ADDR option below to login. | ||
############################## Send Text ###################################### | ||
########## usage in scrapy projects ########## | ||
# See the "Send Text" page | ||
|
||
########## slack ########## | ||
# How to create a slack app: | ||
# 1. Visit https://api.slack.com/apps and press the "Create New App" button. | ||
# 2. Enter your App Name (e.g. mybot)and select one of your Slack Workspaces, the press "Create App". | ||
# 3. Click the "OAuth & Permissions" menu in the sidebar on the left side of the page. | ||
# 4. Scroll down the page and find out "Select Permission Scopes" in the "Scopes" section | ||
# 5. Enter "send" and select "Send messages as <your-app-name>", then press "Save Changes" | ||
# 6. Scroll up the page and press "Install App to Workspace", then press "Install" | ||
# 7. Copy the "OAuth Access Token", e.g. xoxp-123-456-789-abcde | ||
# See https://api.slack.com/apps for more info | ||
|
||
# See step 1~7 above, e.g. 'xoxp-123-456-789-abcde' | ||
SLACK_TOKEN = os.environ.get('SLACK_TOKEN', '') | ||
# The default channel to use when sending text via slack, e.g. 'general' | ||
SLACK_CHANNEL = 'general' | ||
|
||
########## telegram ########## | ||
# How to create a telegram bot: | ||
# 1. Visit https://telegram.me/botfather to start a conversation with Telegram's bot that creates other bots. | ||
# 2. Send the /newbot command to create a new bot in a chat with BotFather. | ||
# 3. Follow the instructions to set up name and username (e.g. my_bot) for your bot. | ||
# 4. You would get a token (e.g. 123:abcde) after step 3. | ||
# 5. Visit telegram.me/<bot_username> (e.g. telegram.me/my_bot) and say hi to your bot to initiate a conversation. | ||
# 6. Visit https://api.telegram.org/bot<token-in-setp-4>/getUpdates to get the chat_id. | ||
# (e.g. Visit https://api.telegram.org/bot123:abcde/getUpdates | ||
# and you can find the chat_id in "chat":{"id":123456789,...) | ||
# See https://core.telegram.org/bots#6-botfather for more info | ||
|
||
# See step 1~4 above, e.g. '123:abcde' | ||
TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN', '') | ||
# See step 5~6 above, e.g. 123456789 | ||
TELEGRAM_CHAT_ID = int(os.environ.get('TELEGRAM_CHAT_ID', 0)) | ||
|
||
########## email ########## | ||
# The default subject to use when sending text via email. | ||
EMAIL_SUBJECT = 'Email from #scrapydweb' | ||
|
||
########## email sender & recipients ########## | ||
# Leave this option as '' to default to the EMAIL_SENDER option below; Otherwise, set it up | ||
# if your email service provider requires an username which is different from the EMAIL_SENDER option below to login. | ||
# e.g. 'username' | ||
EMAIL_USERNAME = '' | ||
# As for different email service provider, you might have to get an APP password (like Gmail) | ||
|
@@ -227,41 +227,72 @@ | |
# https://stackoverflow.com/a/27515833/10517783 How to send an email with Gmail as the provider using Python? | ||
# https://stackoverflow.com/a/26053352/10517783 Python smtplib proxy support | ||
# e.g. 'password4gmail' | ||
EMAIL_PASSWORD = '' | ||
EMAIL_PASSWORD = os.environ.get('EMAIL_PASSWORD', '') | ||
|
||
# e.g. '[email protected]' | ||
FROM_ADDR = '' | ||
EMAIL_SENDER = '' | ||
# e.g. ['[email protected]', ] | ||
TO_ADDRS = [FROM_ADDR] | ||
EMAIL_RECIPIENTS = [EMAIL_SENDER] | ||
|
||
########## email working time ########## | ||
# Monday is 1 and Sunday is 7. | ||
# e.g, [1, 2, 3, 4, 5, 6, 7] | ||
EMAIL_WORKING_DAYS = [] | ||
########## email smtp settings ########## | ||
# Check out this link if you are using ECS of Alibaba Cloud and your SMTP server provides TCP port 25 only: | ||
# https://www.alibabacloud.com/help/doc-detail/56130.htm | ||
# Config for https://mail.google.com using SSL: ('smtp.gmail.com', 465, True) | ||
# Config for https://mail.google.com: ('smtp.gmail.com', 587, False) | ||
# Config for https://mail.qq.com using SSL: ('smtp.qq.com', 465, True) | ||
# Config for http:https://mail.10086.cn: ('smtp.139.com', 25, False) | ||
SMTP_SERVER = '' | ||
SMTP_PORT = 0 | ||
SMTP_OVER_SSL = False | ||
# The timeout in seconds for the connection attempt, the default is 30. | ||
SMTP_CONNECTION_TIMEOUT = 30 | ||
|
||
# From 0 to 23. | ||
# e.g. [9] + list(range(15, 18)) >>> [9, 15, 16, 17], or range(24) for 24 hours | ||
EMAIL_WORKING_HOURS = [] | ||
|
||
############################## Monitor & Alert ################################ | ||
# The default is False, set it to True to launch the poll subprocess to monitor your crawling jobs. | ||
ENABLE_MONITOR = False | ||
|
||
########## poll interval ########## | ||
# Tip: In order to be notified (and stop or forcestop a job when triggered) in time, | ||
# you can reduce the value of POLL_ROUND_INTERVAL and POLL_REQUEST_INTERVAL, | ||
# at the cost of burdening both CPU and bandwidth of your servers. | ||
|
||
# Sleep N seconds before starting next round of poll, the default is 300. | ||
POLL_ROUND_INTERVAL = 300 | ||
|
||
# Sleep N seconds between each request to the Scrapyd server while polling, the default is 10. | ||
POLL_REQUEST_INTERVAL = 10 | ||
|
||
########## alert switcher ########## | ||
# Tip: Set the SCRAPYDWEB_BIND option the in "QUICK SETUP" section to the actual IP of your host, | ||
# then you can visit ScrapydWeb via the links attached in the alert. | ||
|
||
# The default is False, set it to True to enable alert via Slack, Telegram, or Email. | ||
# You have to set up your accounts in the "Send text" section above first. | ||
ENABLE_SLACK_ALERT = False | ||
ENABLE_TELEGRAM_ALERT = False | ||
ENABLE_EMAIL_ALERT = False | ||
|
||
########## alert working time ########## | ||
# Monday is 1 and Sunday is 7. | ||
# e.g, [1, 2, 3, 4, 5, 6, 7] | ||
ALERT_WORKING_DAYS = [] | ||
|
||
# From 0 to 23. | ||
# e.g. [9] + list(range(15, 18)) >>> [9, 15, 16, 17], or range(24) for 24 hours | ||
ALERT_WORKING_HOURS = [] | ||
|
||
########## basic triggers ########## | ||
# Trigger email notice every N seconds for each running job. | ||
# Trigger alert every N seconds for each running job. | ||
# The default is 0, set it to a positive integer to enable this trigger. | ||
ON_JOB_RUNNING_INTERVAL = 0 | ||
|
||
# Trigger email notice when a job is finished. | ||
# Trigger alert when a job is finished. | ||
# The default is False, set it to True to enable this trigger. | ||
ON_JOB_FINISHED = False | ||
|
||
########## advanced triggers ########## | ||
# - LOG_XXX_THRESHOLD: | ||
# - Trigger email notice the first time reaching the threshold for a specific kind of log. | ||
# - Trigger alert the first time reaching the threshold for a specific kind of log. | ||
# - The default is 0, set it to a positive integer to enable this trigger. | ||
# - LOG_XXX_TRIGGER_STOP (optional): | ||
# - The default is False, set it to True to stop current job automatically when reaching the LOG_XXX_THRESHOLD. | ||
|
@@ -273,8 +304,8 @@ | |
# - The SIGTERM signal would be sent twice resulting in an UNCLEAN shutdown, without the Scrapy stats dumped! | ||
# - The 'FORCESTOP' action would be executed if both of the 'STOP' and 'FORCESTOP' triggers are enabled. | ||
|
||
# Note that the 'STOP' action and the 'FORCESTOP' action would STILL be executed even when the current time | ||
# is NOT within the EMAIL_WORKING_DAYS and the EMAIL_WORKING_HOURS, though NO email would be sent. | ||
# Note that the 'STOP' action and the 'FORCESTOP' action would still be executed even when the current time | ||
# is NOT within the ALERT_WORKING_DAYS and the ALERT_WORKING_HOURS, though no alert would be sent. | ||
|
||
LOG_CRITICAL_THRESHOLD = 0 | ||
LOG_CRITICAL_TRIGGER_STOP = False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.