欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python easyicon图标下载工具

程序员文章站 2022-06-19 13:26:09
...

OBJ

https://www.easyicon.net

流程

检测剪切板变化->检测是否为url->提取ico链接及名字->下载->使用PythonMagick转为ico(可省略)

效果

UI版
python easyicon图标下载工具

console版
python easyicon图标下载工具

Code

  1. 监测剪切板变化
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  #更新
  1. 检测是否为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
  1. requests下载
            if is_url(string):  #检测是否为url
                img_url = get_imgurl(string)  #从链接网址中提取url
                img_name = urltoname(string)  #从链接网址中提取name
                download(img_url, img_name)  #爬虫下载

具体代码就不贴了,项目已开源

  1. UI部分

代码几乎全靠ctrl+c +v
参考了以下文章 o( ̄▽ ̄)ブ

相关标签: python 图标设计