Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (81 sloc) 3 KB
#coding:utf-8
#author:国光
#name:Mac平台下免费的剪贴板图片外链上传工具
import re
import os
import requests
import pyperclip
import subprocess
import prettytable as pt
from multiprocessing import Queue
from pynput.keyboard import Key, Listener
q = Queue(2)
#欢迎界面
def WelCome():
tb = pt.PrettyTable()
tb.field_names = ["FreeBuf图片外链一键上传脚本"]
tb.add_row(['运行环境'])
tb.add_row(['Python3 in Mac OS'])
tb.add_row(['使用方法'])
tb.add_row(['截图后使用 组合键 Ctrl + Shift 来上传'])
tb.add_row(['上传成功后 外链将直接拷贝到剪贴板中'])
tb.add_row(['相关依赖包'])
tb.add_row(['sudo pip3 install pyperclip prettytable'])
tb.add_row(['brew install pngpaste'])
print(tb)
# 使用Freebuf的图床
def FbUpload(file_name):
try:
with open(file_name, 'rb') as file:
url = 'http://www.freebuf.com/buf/plugins/ueditor/ueditor/php/imageUp.php?&post_id='
headers = {
'Cookie':'3cb185a485c81b23211eb80b75a406fd=1529045953; Hm_lvt_cc53db168808048541c6735ce30421f5=1529045957,1529246161; acw_tc=AQAAABCx0Xx00gMANBLOt2cOXOmatLy0; acw_sc__=5b2a6741e23733ca2c4f902c823361a8ea25ca86; PHPSESSID=85p73eamjnti741gmd42hof9n2',
'Host': 'www.freebuf.com',
'Origin': 'http://www.freebuf.com',
'Referer': 'http://www.freebuf.com/video/175166.html',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
}
r = requests.post(url,headers=headers,files={'upfile':file})
return r.text
except Exception as e:
print("获取图片失败")
print(e)
# 剪贴板图片保存
def SaveImage():
try:
p = subprocess.Popen('pngpaste test.png',shell=True)
p.wait()
return p.returncode
except OSError:
print('Mac下请使用 brew install pngpaste 命令来安装缺失的依赖包')
def Key_press(key):
# 监听按键
if format(key) == 'Key.ctrl':
q.put(1)
if format(key) == 'Key.shift':
q.put(2)
if q.full():
Get_imgurl()
def Key_release(keys):
# 监听释放
if format(keys) == 'Key.ctrl':
q.get_nowait()
if format(keys) == 'Key.shift':
q.get_nowait()
if keys == Key.esc:
return False
def Get_imgurl():
image_status = SaveImage()
if image_status == 0:
response = FbUpload('test.png')
url_pattern = re.compile(r'images(.*?).png')
url = url_pattern.findall(response)
image_url = '![](http://image.3001.net/images'+url[0]+'.png)'
pyperclip.copy(image_url)
else:
pyperclip.copy("在剪贴板中没有发现图片数据,或者图片没有转换成功!")
if __name__ == '__main__':
WelCome()
with Listener(on_press=Key_press, on_release=Key_release) as listener:
listener.join()
You can’t perform that action at this time.