又是受国光这篇文章的启发>>>Python编写一个免费简单的图床上传工具 | 国光
国光把京东的上传点告诉我并推荐使用pngpaste命令(获取粘贴板的图片),于是乎就写了此小工具。

工具详情:

  • 只支持在mac下(待完善)
  • 还不支持gif上传(因为京东的论坛评论不能上传gif)(待完善)
  • 只支持截图。或者将想要复制的图片用qq或者微信等发送,再将聊天记录的文件拷贝就可以使用快捷键上传至上传点了。

如何使用:

  • python3 useGroupJDupPic.py
  • 截图
  • 按下快捷键,获取保存粘贴板图片,上传,并返回markdown图片外链格式
  • 粘贴至markdown文档中
  • 停止:暴力的ctrl + c

⭕️🐴如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/local/bin/python3
import os
import requests
import pyperclip
from subprocess import call
from multiprocessing import Queue
from pynput.keyboard import Key, Listener

q = Queue(2)

def upfiel2JD(filename):
try:
with open(filename, 'rb') as file:
url = 'https://group.jd.com/ueditor/jsp/imageUp.jsp?action=uploadimage&encode=utf-8'
headers = {
'Host': 'group.jd.com',
'Origin': 'https://group.jd.com',
'Referer': 'https://group.jd.com/ueditor/dialogs/imag',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36',
}
response = requests.post(url, headers=headers,files={'upfile':file})
return '![](%s)'%('http://img30.360buyimg.com/club_community/'+response.json()['url'])
except:
return "获取图片失败"

def getCopyFile():
try:
call(['/usr/local/bin/pngpaste', '-v'], stderr=open('/dev/null', 'w'))
except OSError:
print('使用命令安装`brew install pngpaste`.')
sys.exit()
filename = "test.png"
file_path = os.path.join('/tmp', filename)
save = call(['/usr/local/bin/pngpaste', file_path])
if save:
return ''
return file_path

def on_press(key):
# 监听按键
if format(key) == 'Key.ctrl':
# print('press{}'.format(key))
q.put(1)
if format(key) == 'Key.shift':
# print('press{}'.format(key))
q.put(2)
if q.full():
pyperclip.copy(upfiel2JD(getCopyFile()))

def on_release(keys):
# 监听释放
if format(keys) == 'Key.ctrl':
q.get_nowait()
if format(keys) == 'Key.shift':
q.get_nowait()
if keys == Key.esc:
# Stop listener
return False


if __name__ == '__main__':
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()


然后我就把把博客的图片都上传上去了这样就访问的速度就快多了。

留言

2018-06-13

⬆︎TOP