Add a wrapper function for pywikibot output functions to add a timestamp to each message
This commit is contained in:
27
__init__.py
Normal file
27
__init__.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# __init__.py
|
||||
#
|
||||
# Copyright 2015 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
#
|
||||
#
|
||||
"""
|
||||
Scripts for our redundances bot
|
||||
"""
|
||||
from jogobot.jogobot import output # noqa
|
||||
35
jogobot.py
35
jogobot.py
@@ -23,11 +23,46 @@
|
||||
#
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
from email.mime.text import MIMEText
|
||||
from subprocess import Popen, PIPE, TimeoutExpired
|
||||
|
||||
import pywikibot
|
||||
|
||||
from pywikibot.bot import(
|
||||
DEBUG, INFO, WARNING, ERROR, CRITICAL, STDOUT, VERBOSE, logoutput )
|
||||
|
||||
|
||||
def output( text, level="STDOUT", decoder=None, newline=True,
|
||||
layer=None, **kwargs ):
|
||||
"""
|
||||
Wrapper for pywikibot output functions
|
||||
"""
|
||||
|
||||
text = datetime.utcnow().strftime( "%Y-%m-%d %H:%M:%S (UTC) " ) + text
|
||||
|
||||
if ( level.upper() == "STDOUT" ):
|
||||
_level = STDOUT
|
||||
elif( level.upper() == "INFO" ):
|
||||
_level = INFO
|
||||
elif( level.upper() == "WARNING" ):
|
||||
_level = WARNING
|
||||
elif( level.upper() == "ERROR" ):
|
||||
_level = ERROR
|
||||
elif( level.upper() == "LOG" or level.upper() == "VERBOSE" ):
|
||||
_level = VERBOSE
|
||||
elif( level.upper() == "CRITICAL" ):
|
||||
_level = CRITICAL
|
||||
elif( level.upper() == "DEBUG" ):
|
||||
_level = DEBUG
|
||||
else:
|
||||
pass
|
||||
|
||||
if ( level == DEBUG ):
|
||||
logoutput(text, decoder, newline, _level, layer, **kwargs)
|
||||
else:
|
||||
logoutput(text, decoder, newline, _level, **kwargs)
|
||||
|
||||
|
||||
class JogoBot:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user