python easyicon图标下载工具
程序员文章站
2022-06-19 13:26:09
...
OBJ
流程
检测剪切板变化->检测是否为url->提取ico链接及名字->下载->使用PythonMagick转为ico(可省略)
效果
UI版
console版
Code
- 监测剪切板变化
import pyperclip,time
#检测剪切板变化
last_string = pyperclip.paste()
while True:
time.sleep(0.2) # 检测频率
string = pyperclip.paste() #获取字符串
if string != last_string and string != '': #如果两次不同
last_string = string #更新
- 检测是否为url
if is_url(string): #检测是否为url
def is_url(url): #检测链接是否为url
import re
regex = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain...
r'localhost|' # localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
r'(?:/?|[/?]\S+)$',
re.IGNORECASE)
if re.match(regex, url) != None:
return 1
else:
return 0
- requests下载
if is_url(string): #检测是否为url
img_url = get_imgurl(string) #从链接网址中提取url
img_name = urltoname(string) #从链接网址中提取name
download(img_url, img_name) #爬虫下载
具体代码就不贴了,项目已开源
- UI部分
代码几乎全靠ctrl+c +v
参考了以下文章 o( ̄▽ ̄)ブ
上一篇: xv6操作系统源码阅读之锁
下一篇: python 多进程编程