from clipboard import get_paste_img_file
from upload import upload_qiniu
import util
import os
import subprocess
import sys
import time
if not os.path.exists(util.CONFIG_FILE):
util.generate_config_file()
config = util.read_config()
if not config:
util.notice('请先设置你的七牛图床信息')
util.open_with_editor(util.CONFIG_FILE)
sys.exit(0)
url = '%s/%s' % (config['url'], config['prefix'])
img_file, need_format, format = get_paste_img_file()
if img_file:
upload_name = "%s.%s" % (int(time.time() * 1000), format)
if need_format:
markdown_url = '![](%s/%s)' % (url, upload_name)
else:
markdown_url = '%s/%s' % (url, upload_name)
os.system("echo '%s' | pbcopy" % markdown_url)
os.system('osascript -e \'tell application "System Events" to keystroke "v" using command down\'')
upload_file = util.try_compress_png(img_file, format!='gif')
if not upload_qiniu(upload_file.name, upload_name): util.notice("上传图片到图床失败,请检查网络后重试")
else:
util.notice("剪切版里没有图片!")