Python下载Unraid的community.applications apps应用商店插件并上传到国内网站服务器

本文涉及的产品
文件存储 NAS,50GB 3个月
简介: Python下载Unraid的community.applications apps应用商店插件并上传到国内网站服务器

Python下载Unraid的community.applications apps应用商店插件并上传到国内网站服务器

需要在IIS中MIME 为.plg .txz 添加类型 application/octet-stream 这样打开下面文件时才会变成下载而非提示此文件不可打开

https://www.52help.net/ad/nas/Squidly271/community.applications/master/archive/community.applications-2020.06.13a-x86_64-1.txz

from urllib import request
from ftplib import FTP

blnver = False
blnname = False
blngithub = False
str_ver=""

替换文本函数

def alter(file,old_str,new_str):
file_data = ""
with open(file, "r", encoding="utf-8") as f:
for line in f:
print(line)
if old_str in line:
line = line.replace(old_str,new_str)
file_data += line
with open(file,"w",encoding="utf-8") as f:
f.write(file_data)

使用代理上网 才能连到unraid官网

proxies = {
'https': 'https://127.0.0.1:1080',
'http': 'http://127.0.0.1:1080'
}

需要加上headers, 否则报错: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 8974: invalid start byte

headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36'
}

community_url = 'https://raw.githubusercontent.com/Squidly271/community.applications/master/plugins/community.applications.plg'
opener = request.build_opener(request.ProxyHandler(proxies))
request.install_opener(opener)

req = request.Request(community_url, headers=headers)

f = request.urlopen(req)
data = f.read()
with open("community.applications.plg", "wb") as code:
code.write(data)

file_data = ""

获取文件中的软件名 版本号 路径

with open("community.applications.plg", "r", encoding="utf-8") as f:
    for line in f:
      if not blnver:
         char_1='<!ENTITY version'
         if char_1 in line: 
            print("charfind")
            str_ver = line.replace(char_1,"")
            str_ver= str_ver.replace(" ","")
            str_ver= str_ver.replace(">","")
            str_ver= str_ver.replace('"','')
            str_ver= str_ver.replace('\n', '').replace('\r', '')
            print(str_ver)
            blnver = True 
      if not blnname:
         char_1='<!ENTITY name'
         if char_1 in line: 
            str_name = line.replace(char_1,"")
            str_name= str_name.replace(" ","")
            str_name= str_name.replace(">","")
            str_name= str_name.replace('"','')
            str_name= str_name.replace('\n', '').replace('\r', '')
            print(str_name)
            blnname = True  
      if not blngithub:
         char_1='<!ENTITY github'
         if char_1 in line: 
            str_github = line.replace(char_1,"")
            str_github= str_github.replace(" ","")
            str_github= str_github.replace(">","")
            str_github= str_github.replace('"','')
            str_github= str_github.replace('\n', '').replace('\r', '')
            print(str_github)
            blngithub = True  
      if "https://raw.githubusercontent.com/" in line:
        line = line.replace("https://raw.githubusercontent.com/","https://www.52help.net/ad/nas/")
      file_data += line
with open("community.applications.plg","w",encoding="utf-8") as f:
      f.write(file_data)

str_url=''
str_filename='&name;-&version;-x86_64-1.txz'
;/master/archive/'  #&name;-&version;-x86_64-1.txz
str_url = str_1.replace("&github;",str_github)
str_filename = str_filename.replace("&name;",str_name)
str_filename = str_filename.replace("&version;",str_ver)
str_url =str_url + str_filename 
print(str_url)

req = request.Request(str_url, headers=headers)
f = request.urlopen(req) 
data = f.read() 
with open(str_filename, "wb") as code: 
 code.write(data)

alter("community.applications.plg", "https://raw.githubusercontent.com/", "https://www.52help.net/ad/nas/")

将下载的文件修改后再上传到网站服务器

ftp = FTP()

打开调试级别2, 显示详细信息

ftp.set_debuglevel(2)

服务器IP和端口

ftp.connect("www.52help.net", 21)

匿名登陆, 如果需要登陆, 就把两个空字符串写上用户名和密码就行了("username", "password")

ftp.login("52help", "FTP登录密码")

切换目录, 相对于ftp目录, 比如设置的ftp根目录为/vat/ftp, 那么pub就是/var/ftp下面的目录

ftp.cwd("/52help/web/ad/nas/Squidly271/community.applications/master/plugins/")

查看目录下有哪些文件, 如果文件名已经存在, 那么再次上传同一个文件就会报错, 返回列表

ftp.nlst("/pub")

使用二进制的方式打开文件

f = open("community.applications.plg", 'rb')

上传文件, bufsize缓冲区大小

ftp.storbinary("STOR {}".format("community.applications.plg"), f [, bufsize])

ftp.storbinary('STOR %s' % "community.applications.plg", f)
f.close()

ftp.cwd("/52help/web/ad/nas/Squidly271/community.applications/master/archive/")
f = open(str_filename, 'rb')
ftp.storbinary('STOR %s' % str_filename, f)
f.close()

关闭调试模式

ftp.set_debuglevel(0)

退出FTP连接

ftp.quit()

相关实践学习
函数计算部署PuLID for FLUX人像写真实现智能换颜效果
只需一张图片,生成程序员专属写真!本次实验在函数计算中内置PuLID for FLUX,您可以通过函数计算+Serverless应用中心一键部署Flux模型,快速体验超写实图像生成的魅力。
相关文章
|
3月前
|
人工智能 JavaScript API
零基础构建MCP服务器:TypeScript/Python双语言实战指南
作为一名深耕技术领域多年的博主摘星,我深刻感受到了MCP(Model Context Protocol)协议在AI生态系统中的革命性意义。MCP作为Anthropic推出的开放标准,正在重新定义AI应用与外部系统的交互方式,它不仅解决了传统API集成的复杂性问题,更为开发者提供了一个统一、安全、高效的连接框架。在过去几个月的实践中,我发现许多开发者对MCP的概念理解透彻,但在实际动手构建MCP服务器时却遇到了各种技术壁垒。从环境配置的细节问题到SDK API的深度理解,从第一个Hello World程序的调试到生产环境的部署优化,每一个环节都可能成为初学者的绊脚石。因此,我决定撰写这篇全面的实
565 67
零基础构建MCP服务器:TypeScript/Python双语言实战指南
|
2月前
|
人工智能 自然语言处理 安全
Python构建MCP服务器:从工具封装到AI集成的全流程实践
MCP协议为AI提供标准化工具调用接口,助力模型高效操作现实世界。
445 1
|
4月前
|
C# 图形学 开发者
Unity开发中使用UnityWebRequest从HTTP服务器下载资源。
总之,UnityWebRequest就是游戏开发者手中的万能钓鱼竿,既可以获取文本数据,也能钓上图片资源,甚至是那声音的涟漪。使用UnityWebRequest的时候,你需要精心准备,比如确定URL、配置请求类型和头信息;发起请求;巧妙处理钓获的数据;还需要机智面对网络波澜,处理各种可能出现的错误。按照这样的过程,数据的钓取将会是一次既轻松愉快也效率高效的编程钓鱼之旅。
212 18
|
3月前
|
安全 Linux 网络安全
Python极速搭建局域网文件共享服务器:一行命令实现HTTPS安全传输
本文介绍如何利用Python的http.server模块,通过一行命令快速搭建支持HTTPS的安全文件下载服务器,无需第三方工具,3分钟部署,保障局域网文件共享的隐私与安全。
613 0
|
5月前
|
人工智能 安全 Shell
Jupyter MCP服务器部署实战:AI模型与Python环境无缝集成教程
Jupyter MCP服务器基于模型上下文协议(MCP),实现大型语言模型与Jupyter环境的无缝集成。它通过标准化接口,让AI模型安全访问和操作Jupyter核心组件,如内核、文件系统和终端。本文深入解析其技术架构、功能特性及部署方法。MCP服务器解决了传统AI模型缺乏实时上下文感知的问题,支持代码执行、变量状态获取、文件管理等功能,提升编程效率。同时,严格的权限控制确保了安全性。作为智能化交互工具,Jupyter MCP为动态计算环境与AI模型之间搭建了高效桥梁。
337 2
Jupyter MCP服务器部署实战:AI模型与Python环境无缝集成教程
|
21天前
|
数据采集 机器学习/深度学习 人工智能
Python:现代编程的首选语言
Python:现代编程的首选语言
191 102
|
21天前
|
数据采集 机器学习/深度学习 算法框架/工具
Python:现代编程的瑞士军刀
Python:现代编程的瑞士军刀
194 104
|
21天前
|
人工智能 自然语言处理 算法框架/工具
Python:现代编程的首选语言
Python:现代编程的首选语言
185 103

热门文章

最新文章

推荐镜像

更多