Skip to content

Commit

Permalink
feat: support date format
Browse files Browse the repository at this point in the history
  • Loading branch information
tangyoha committed Oct 31, 2023
1 parent 4b7ab49 commit 4d1c91c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ allowed_user_ids:
- **save_path** - The root directory where you want to store downloaded files.
- **file_path_prefix** - Store file subfolders, the order of the list is not fixed, can be randomly combined.
- `chat_title` - Channel or group title, it will be chat id if not exist title.
- `media_datetime` - Media date, also see pyrogram.types.Message.date.strftime("%Y_%m").
- `media_datetime` - Media date.
- `media_type` - Media type, also see `media_types`.
- **upload_drive** - You can upload file to cloud drive.
- `enable_upload_file` - Enable upload file, default `false`.
Expand All @@ -233,6 +233,7 @@ allowed_user_ids:
- **log_level** - see `logging._nameToLevel`.
- **forward_limit** - Limit the number of forwards per minute, the default is 33, please do not modify this parameter by default.
- **allowed_user_ids** - Who is allowed to use the robot? The default login account can be used. Please add single quotes to the name with @.
- **date_format** Support custom configuration of media_datetime format in file_path_prefix.see [python-datetime](https://docs.python.org/3/library/datetime.html)

## Execution

Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ allowed_user_ids:
- **log_level** - 默认日志等级,请参阅 `logging._nameToLevel`
- **forward_limit** - 限制每分钟转发次数,默认为33,默认请不要修改该参数
- **allowed_user_ids** - 允许哪些人使用机器人,默认登录账号可以使用,带@的名称请加单引号
- **date_format** - 支持自定义配置file_path_prefix中media_datetime的格式,具体格式查看 [python-datetime](https://docs.python.org/zh-cn/3/library/time.html)


## 执行
Expand Down
2 changes: 1 addition & 1 deletion media_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async def _get_media_meta(
dirname = validate_title(f"{message.chat.title}")

if message.date:
datetime_dir_name = message.date.strftime("%Y_%m")
datetime_dir_name = message.darte.strftime(app.date_format)
else:
datetime_dir_name = "0"

Expand Down
16 changes: 16 additions & 0 deletions module/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
from concurrent.futures import ThreadPoolExecutor
from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import List, Optional, Union

Expand Down Expand Up @@ -386,6 +387,7 @@ def __init__(
self.log_level: str = "INFO"
self.start_timeout: int = 60
self.allowed_user_ids: yaml.comments.CommentedSeq = []
self.date_format: str = "%Y_%m"

self.forward_limit_call = LimitCall(max_limit_call_times=33)
self.loop = asyncio.new_event_loop()
Expand Down Expand Up @@ -504,6 +506,20 @@ def assign_config(self, _config: dict) -> bool:
yaml.comments.CommentedSeq,
)

self.date_format = get_config(
_config,
"date_format",
self.date_format,
str,
)

try:
date = datetime(2023, 10, 31)
date.strftime(self.date_format)
except Exception as e:
logger.warning(f"config date format error: {e}")
self.date_format = "%Y_%m"

forward_limit = _config.get("forward_limit", None)
if forward_limit:
try:
Expand Down

0 comments on commit 4d1c91c

Please sign in to comment.