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

简介: 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模型,快速体验超写实图像生成的魅力。
相关文章
|
10月前
|
Web App开发 安全 数据安全/隐私保护
利用Python+Requests实现抖音无水印视频下载
利用Python+Requests实现抖音无水印视频下载
|
7月前
|
存储 数据采集 监控
Python定时爬取新闻网站头条:从零到一的自动化实践
在信息爆炸时代,本文教你用Python定时爬取腾讯新闻头条,实现自动化监控。涵盖请求、解析、存储、去重、代理及异常通知,助你构建高效新闻采集系统,适用于金融、电商、媒体等场景。(238字)
1223 2
|
9月前
|
SQL 前端开发 JavaScript
基于python+django开发的在线求职招聘网站-网上招聘管理系统
该系统是基于python+django的求职招聘网站、网上招聘管理系统、网上人才招聘系统、毕业生求职招聘系统、大学生求职招聘系统、校园招聘系统、企业招聘系统。系统适合场景:大学生、课程作业、毕业设计。这是一个前后端分离的项目,需要同学们学习django技术和vue技术。
627 3
|
8月前
|
小程序 PHP 图形学
热门小游戏源码(Python+PHP)下载-微信小程序游戏源码Unity发实战指南​
本文详解如何结合Python、PHP与Unity开发并部署小游戏至微信小程序。涵盖技术选型、Pygame实战、PHP后端对接、Unity转换适配及性能优化,提供从原型到发布的完整指南,助力开发者快速上手并发布游戏。
|
10月前
|
API 数据安全/隐私保护 Python
批量发短信的软件,自动群发短信批量工具,手机号电话生成脚本插件【python】
该工具包含三个核心模块:短信发送核心功能、配置管理系统和命令行界面。使用时需先配置API密钥和短信模板
|
10月前
|
机器学习/深度学习 数据安全/隐私保护 计算机视觉
过三色刷脸技术,过三色刷脸技术教程,插件过人脸python分享学习
三色刷脸技术是基于RGB三通道分离的人脸特征提取方法,通过分析人脸在不同颜色通道的特征差异
|
11月前
|
C# 图形学 开发者
Unity开发中使用UnityWebRequest从HTTP服务器下载资源。
总之,UnityWebRequest就是游戏开发者手中的万能钓鱼竿,既可以获取文本数据,也能钓上图片资源,甚至是那声音的涟漪。使用UnityWebRequest的时候,你需要精心准备,比如确定URL、配置请求类型和头信息;发起请求;巧妙处理钓获的数据;还需要机智面对网络波澜,处理各种可能出现的错误。按照这样的过程,数据的钓取将会是一次既轻松愉快也效率高效的编程钓鱼之旅。
650 18
|
10月前
|
JSON 机器人 API
微信机器人自动回复插件,vx自动回复机器人脚本助手,python框架分享
这个微信机器人系统包含三个主要模块:主程序基于itchat实现微信消息监听和自动回复功能
|
10月前
|
API 数据安全/隐私保护 Python
贴吧私信自动群发神器,百度贴吧群发批量私信脚本插件,python框架分享
这个贴吧私信群发工具包含三个主要文件:主程序、配置文件和入口文件。主程序实现了登录
|
10月前
|
机器人 API 数据安全/隐私保护
QQ机器人插件源码,自动回复聊天机器人,python源码分享
消息接收处理:通过Flask搭建HTTP服务接收go-cqhttp推送的QQ消息47 智能回复逻辑

推荐镜像

更多