Files
xiaoli-cli/operit_py/time.py
T
shuiyu1123 dc77dfd304 feat: 将 47 个 Operit TypeScript 脚本全面翻译为 Python
- 新增 operit_runtime.py: 跨平台 Python 运行时
  - 实现 Tools.System/Files/Net/UI/Memory/FFmpeg/Workflow/Chat/SoftwareSettings/Tasker
  - 实现 OkHttp 链式 HTTP 客户端兼容层
  - 实现 complete()/exports/console 全局对象
  - 实现 OperitScriptLoader 脚本加载器
  - 支持 Windows/macOS/Linux 三平台

- 新增 operit_py/ 目录: 47 个 Python 翻译脚本
  - 搜索类: duckduckgo, google_search, tavily, zhipu_search, various_search, crossref
  - 绘图类: openai_draw, qwen_draw, xai_draw, minimax_draw, siliconflow_draw, zhipu_draw, nanobanana_draw
  - 媒体类: ffmpeg, file_converter, douyin_download, bilibili_tools, jmcomic
  - 文件类: extended_file_tools, hex_editor, reader, beeimg_image_uploader
  - 网络类: extended_http_tools, network_test
  - 自动化类: browser, automatic_ui_base, automatic_ui_subagent, automatic_bilibili_assistant, automatic_xiaohongshu_assistant, automatic_baidu_map_assistant
  - 系统类: system_tools, super_admin, daily_life, operit_editor
  - 对话类: ai_chat, extended_chat, qq_intelligent
  - 工作流类: workflow, vflow_trigger, tasker
  - 工具类: time, code_runner, quick_start, extended_memory_tools, baidu_map, 12306, pdf_vision_parser

- 测试结果: 47/47 语法检查通过, 38 脚本加载成功, 280 个工具注册
- Android 专属功能已降级处理(保留接口,返回不支持提示)
2026-06-23 12:27:18 +00:00

86 lines
2.1 KiB
Python

# METADATA
# {
# name: time
#
# display_name: {
# zh: "时间"
# en: "Time"
# }
# description: {
# zh: "提供时间相关功能。实际上,激活本包的同时已经能够获取时间了。"
# en: "Provides time-related utilities. In practice, current time is already available once this package is enabled."
# }
# enabledByDefault: true
# category: "Utility"
# tools: [
# {
# name: get_time
# description: {
# zh: "获取当前时间。当使用此包时,AI已经自动获取了当前的时间信息。"
# en: "Get the current time. When using this package, the AI may already have the current time context."
# }
# parameters: []
# },
# {
# name: format_time
# description: {
# zh: "格式化时间。提供各种时间格式化选项。"
# en: "Format time. Provides various time formatting options."
# }
# parameters: []
# }
# ]
# }
import time
import datetime
async def get_time():
now = datetime.datetime.now()
return {
"timestamp": int(time.time() * 1000),
"iso": now.isoformat(),
"local": now.strftime("%Y-%m-%d %H:%M:%S"),
"date": {
"year": now.year,
"month": now.month,
"day": now.day,
"weekday": now.strftime("%A")
},
"time": {
"hours": now.hour,
"minutes": now.minute,
"seconds": now.second
}
}
async def format_time():
now = datetime.datetime.now()
def pad(n):
return str(n).zfill(2)
hours = now.hour
minutes = now.minute
seconds = now.second
time24h = f"{pad(hours)}:{pad(minutes)}:{pad(seconds)}"
suffix = "PM" if hours >= 12 else "AM"
hour12 = 12 if hours % 12 == 0 else hours % 12
time12h = f"{pad(hour12)}:{pad(minutes)}:{pad(seconds)} {suffix}"
return {
"iso": now.isoformat(),
"date": f"{now.year}-{pad(now.month)}-{pad(now.day)}",
"time24h": time24h,
"time12h": time12h
}
exports.get_time = get_time
exports.format_time = format_time