-
-
Save chihane/065cf94d24267f7bd2fb9a2d0df9554b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Required parameters: | |
# @raycast.schemaVersion 1 | |
# @raycast.title TimeConverter | |
# @raycast.mode compact | |
# Optional parameters: | |
# @raycast.icon 🤖 | |
# @raycast.argument1 { "type": "text", "placeholder": "timestamp / datetime", "optional": true } | |
# @raycast.packageName chihane.ts2dt | |
# Documentation: | |
# @raycast.description Convert between timestamp & datetime & date | |
# @raycast.author Chihane | |
import sys, time, subprocess, datetime | |
arg = sys.argv[1] if len(sys.argv) > 1 else None | |
if not arg: | |
arg = str(datetime.datetime.now()) | |
result = '' | |
try: | |
if arg.isdigit(): | |
dt = datetime.datetime.fromtimestamp(int(arg)) | |
result = dt.strftime('%Y-%m-%d %H:%M:%S') | |
else: | |
try: | |
dt = datetime.datetime.strptime(arg, '%Y-%m-%d %H:%M:%S') | |
except ValueError: | |
try: | |
dt = datetime.datetime.strptime(arg, '%Y-%m-%d') | |
except ValueError: | |
dt = datetime.datetime.strptime(arg, '%Y-%m-%d %H:%M:%S.%f') | |
timestamp = int(dt.timestamp()) | |
result = str(timestamp) | |
except Exception as e: | |
print('时间解析失败') | |
exit(1) | |
try: | |
subprocess.run('pbcopy', universal_newlines=True, input=result) | |
print(result) | |
except Exception as e: | |
print('结果拷贝失败') | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment