aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhyfc <[email protected]>2018-07-21 11:53:49 +0800
committerhyfc <[email protected]>2020-10-22 11:37:48 +0800
commit594b88b8dca478541dc783dc5f4f829fec73dc83 (patch)
tree865897d6ec69e9e013e12b5fbe6515072c0cd6e8
parent01541d3182371f24a7f46ac889003b04cba09919 (diff)
downloadtelegram-mail-bot-594b88b8dca478541dc783dc5f4f829fec73dc83.tar.gz
telegram-mail-bot-594b88b8dca478541dc783dc5f4f829fec73dc83.tar.bz2
telegram-mail-bot-594b88b8dca478541dc783dc5f4f829fec73dc83.zip
add logfile, using task queue instead of schedule
-rw-r--r--Pipfile1
-rw-r--r--Pipfile.lock16
-rw-r--r--bot.py15
3 files changed, 12 insertions, 20 deletions
diff --git a/Pipfile b/Pipfile
index 56f137c..076dc6b 100644
--- a/Pipfile
+++ b/Pipfile
@@ -7,7 +7,6 @@ name = "pypi"
pytz = "*"
python-telegram-bot = "*"
pyzmail36 = "*"
-schedule = "*"
[dev-packages]
pylint = "*"
diff --git a/Pipfile.lock b/Pipfile.lock
index b70305f..bfdf0cd 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "6f87426f7508c223525fced9e8b6552a833fc6402296d17b95700ffe186e3f02"
+ "sha256": "65ffd10327170095842dff53978ba96e55245c9e61073a9fca7cc117a9bdf85b"
},
"pipfile-spec": 6,
"requires": {
@@ -51,23 +51,15 @@
],
"index": "pypi",
"version": "==1.0.3"
- },
- "schedule": {
- "hashes": [
- "sha256:1003a07c2dce12828c25a03a611a7371cedfa956e5f1b4abc32bcc94eb5a335b",
- "sha256:a24e75fc5e5acbd204049d55329e39a2a9a3479bca2e34c7fde81386c9d8d2fa"
- ],
- "index": "pypi",
- "version": "==0.5.0"
}
},
"develop": {
"astroid": {
"hashes": [
- "sha256:8704779744963d56a2625ec2949eb150bd499fc099510161ddbb2b64e2d98138",
- "sha256:add3fd690e7c1fe92436d17be461feeaa173e6f33e0789734310334da0f30027"
+ "sha256:0a0c484279a5f08c9bcedd6fa9b42e378866a7dcc695206b92d59dc9f2d9760d",
+ "sha256:218e36cf8d98a42f16214e8670819ce307fa707d1dcf7f9af84c7aede1febc7f"
],
- "version": "==2.0"
+ "version": "==2.0.1"
},
"colorama": {
"hashes": [
diff --git a/bot.py b/bot.py
index 2d97de3..887461b 100644
--- a/bot.py
+++ b/bot.py
@@ -1,13 +1,13 @@
import logging
import os
-import schedule
from telegram import ParseMode
from telegram.constants import MAX_MESSAGE_LENGTH
from telegram.ext import (Updater, CommandHandler)
from utils.client import EmailClient
-logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
+logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s:%(lineno)d'
+ ' - %(message)s', filename='mailbot.log',
level=logging.INFO)
logger = logging.getLogger(__name__)
@@ -39,7 +39,7 @@ def _help(bot, update):
parse_mode=ParseMode.MARKDOWN,
text=help_str)
-def setting_email(bot, update, args):
+def setting_email(bot, update, args, job_queue):
global email_addr, email_passwd, inbox_num
email_addr = args[0]
email_passwd = args[1]
@@ -47,9 +47,11 @@ def setting_email(bot, update, args):
update.message.reply_text("Configure email success!")
with EmailClient(email_addr, email_passwd) as client:
inbox_num = client.get_mails_count()
- schedule.every(10).minutes.do(periodic_task, bot, update)
+ job_queue.run_repeating(periodic_task, 600)
+
def periodic_task(bot, update):
+ logger.info("entering periodic task.")
with EmailClient(email_addr, email_passwd) as client:
new_inbox_num = client.get_mails_count()
if new_inbox_num > inbox:
@@ -85,7 +87,8 @@ def main():
dp.add_handler(CommandHandler("help", _help))
#
# Add command handler to set email address and account.
- dp.add_handler(CommandHandler("setting", setting_email, pass_args=True))
+ dp.add_handler(CommandHandler("setting", setting_email, pass_args=True,
+ pass_job_queue=True))
dp.add_handler(CommandHandler("inbox", inbox))
@@ -97,8 +100,6 @@ def main():
# Start the Bot
updater.start_polling()
- schedule.run_pending()
-
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.