kopia lustrzana https://github.com/mkdryden/telegram-stats-bot
Added time zone support
rodzic
d6555a28d6
commit
d2f2f408b5
|
@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_,
|
||||
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
|
||||
|
||||
----------
|
||||
Unreleased
|
||||
----------
|
||||
Added
|
||||
-----
|
||||
- Time zone support with ``--tz`` option
|
||||
|
||||
---------------------
|
||||
`0.5.0`_ - 2021-06-11
|
||||
---------------------
|
||||
|
|
21
README.rst
21
README.rst
|
@ -140,15 +140,30 @@ Once installed, you can run the bot by calling the ``main`` module with a few re
|
|||
|
||||
$ python -m telegram_stats_bot.main BOT_TOKEN CHAT_ID POSTGRESQL_URL
|
||||
|
||||
- BOT_TOKEN: Your bot's token e.g., ``110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw``
|
||||
- ``BOT_TOKEN``: Your bot's token e.g., ``110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw``
|
||||
|
||||
- CHAT_ID: The chat id to monitor (will be a large integer, possibly negative, if unknown, set to 0 and see below)
|
||||
- ``CHAT_ID``: The chat id to monitor (will be a large integer, possibly negative, if unknown, set to 0 and see below)
|
||||
|
||||
- POSTGRESQL_URL: Connection information in the form: ``postgresql://USERNAME:PASSWORD@ADDRESS/DB_NAME``
|
||||
- ``POSTGRESQL_URL``: Connection information in the form: ``postgresql://USERNAME:PASSWORD@ADDRESS/DB_NAME``
|
||||
|
||||
- if DB_NAME exists, there must not be tables called ``messages_utc``, ``user_events``, or ``user_names``
|
||||
with incorrect columns
|
||||
|
||||
Two optional arguments exist as well:
|
||||
|
||||
- ``json-path``: Specifying a path here will log messages to json files in addition to the database.
|
||||
If only a prefix is specified, they will be saved under that prefix in your platform's preferred app data directory.
|
||||
This was mostly for development purposes and is not necessary in normal use.
|
||||
|
||||
- ``tz``: Specify a tz database time zone string here (e.g., ``America/New_York``) to return statistics queries in this time zone.
|
||||
(Defaults to ``Etc./UTC``)
|
||||
|
||||
A complete command might look like:
|
||||
|
||||
.. code:: shell
|
||||
|
||||
$ python -m telegram_stats_bot.main --tz="America/Toronto" "110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw" "postgresql://telegram:CoolPassword@localhost/telegram_bot"
|
||||
|
||||
On startup, the bot will attempt to create the database and tables, if they do not already exist.
|
||||
If you do not know the chat's id and have set it to 0 as mentioned above, you can send the ``/chatid`` command inside
|
||||
the group, and the bot will reply with it, then restart the bot with the id.
|
||||
|
|
|
@ -199,6 +199,9 @@ if __name__ == '__main__':
|
|||
parser.add_argument('--json-path', type=str,
|
||||
help="Either full path to backup storage folder or prefix (will be stored in app data dir.",
|
||||
default="chat")
|
||||
parser.add_argument('--tz', type=str,
|
||||
help="tz database time zone string, e.g. Europe/London",
|
||||
default='Etc/UTC')
|
||||
args = parser.parse_args()
|
||||
|
||||
updater = Updater(token=args.token, use_context=True)
|
||||
|
@ -211,7 +214,7 @@ if __name__ == '__main__':
|
|||
os.makedirs(path, exist_ok=True)
|
||||
bak_store = JSONStore(path)
|
||||
store = PostgresStore(args.postgres_url)
|
||||
stats = StatsRunner(store.engine)
|
||||
stats = StatsRunner(store.engine, tz=args.tz)
|
||||
|
||||
stats_handler = CommandHandler('stats', print_stats, filters=~Filters.update.edited_message, run_async=True)
|
||||
dispatcher.add_handler(stats_handler)
|
||||
|
|
|
@ -83,7 +83,7 @@ class StatsRunner(object):
|
|||
'words': "get_word_stats",
|
||||
'random': "get_random_message"}
|
||||
|
||||
def __init__(self, engine: Engine, tz: str = 'America/Toronto'):
|
||||
def __init__(self, engine: Engine, tz: str = 'Etc/UTC'):
|
||||
self.engine = engine
|
||||
self.tz = tz
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue