Skip to content

Commit

Permalink
feat(download): add {time} download variable
Browse files Browse the repository at this point in the history
- 新增 图片日期变量
- 新增 今日日期变量
  • Loading branch information
txperl committed Aug 22, 2021
1 parent 80b21c5 commit 134ca90
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/lib/core/biu.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def appWorksPurer(self, da):
"type": typer,
"title": c["title"],
"caption": c["caption"],
"created_time": c["create_date"][:10],
"created_time": c["create_date"],
"image_urls": {
"small": c["image_urls"]["square_medium"],
"medium": c["image_urls"]["medium"],
Expand Down
18 changes: 17 additions & 1 deletion app/plugin/do_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import re
import time
from datetime import datetime, timedelta, timezone

from altfe.interface.root import interRoot

Expand Down Expand Up @@ -141,7 +142,8 @@ def getTemp(self, url, folder, name, suf="", fun=None, id_="-1", type_="file", t
path_ = "/".join(splitPath[:-1]) + "/" + new_ + "/"
finalPath = path_ + name_ if type_ == "file" else path_
maybePath = path_ + name + f"_{timeStr}{suf}" if type_ == "file" else folder[:-1] + f"_{timeStr}/"
impossiblePath = path_ + name + f"_{timeStr2}{suf}" if type_ == "file" else folder[:-1] + f"_{timeStr2}/"
impossiblePath = path_ + name + f"_{timeStr2}{suf}" if type_ == "file" else folder[
:-1] + f"_{timeStr2}/"
atdeterPaths = {
"ori": deterPath,
"dst": finalPath,
Expand All @@ -164,12 +166,26 @@ def getTemp(self, url, folder, name, suf="", fun=None, id_="-1", type_="file", t
return r

def __deName(self, name, data):
# name = time.strftime(name, time.localtime())
# 格式化图片时间
localTimeZone = time.strftime("%z")
try:
timeImageLocal = datetime.strptime(data["create_date"], "%Y-%m-%dT%H:%M:%S%z").astimezone(
timezone(timedelta(hours=int(localTimeZone[1:3]), minutes=int(localTimeZone[3:5]))))
timeImageLocalStr = timeImageLocal.strftime("%Y-%m-%d")
except:
timeImageLocalStr = "unknown"
# 格式化现在时间
timeNowLocalStr = time.strftime("%Y-%m-%d", time.localtime())

return (
name.replace("{title}", self.__pureName(str(data["title"])))
.replace("{work_id}", self.__pureName(str(data["id"])))
.replace("{user_name}", self.__pureName(str(data["user"]["name"])))
.replace("{user_id}", self.__pureName(str(data["user"]["id"])))
.replace("{type}", self.__pureName(str(data["type"])))
.replace("{date_image}", timeImageLocalStr)
.replace("{date_today}", timeNowLocalStr)
)

def __pureName(self, name):
Expand Down
4 changes: 4 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ biu:
# - {user_name}: 作者名称
# - {user_id}: 作者 ID
# - {type}: 作品类型
# - {date_image}: 作品的日期
# - {date_today}: 今天的日期

saveFileName: "{title}_{work_id}"
# 下载图片的标题
Expand All @@ -91,6 +93,8 @@ biu:
# - {user_name}: 作者名称
# - {user_id}: 作者 ID
# - {type}: 作品类型
# - {date_image}: 作品的日期
# - {date_today}: 今天的日期

autoArchive: true
# 自动将拥有多张图片的作品归档(放入一个文件夹中)
Expand Down

0 comments on commit 134ca90

Please sign in to comment.