成功
废弃手机秒变服务器
现在几乎每人家里都有很多废弃的手机,如果将它们变为服务器岂不是很香,搭个简单的文件服务器做网盘用!链接家里的wifi,链接充电器,7724不间断工作,还省了一大笔云服务器费用,想到就动手,几行代码就实现了将网站布置起来,并且公布到外网,随便一个人都能访问,简单又快捷!
第一步
下载安装Termux
下载地址:https://termux.com/
github地址:https://github.com/termux
获得文件管理权限
在终端当中输入termux-setup-storage
第二步
自动换源,下载速度较快
sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/termux-packages-24 stable main@' $PREFIX/etc/apt/sources.list
sed -i 's@^\(deb.*games stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/game-packages-24 games stable@' $PREFIX/etc/apt/sources.list.d/game.list
sed -i 's@^\(deb.*science stable\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/science-packages-24 science stable@' $PREFIX/etc/apt/sources.list.d/science.list
pkg update
第三步
进入自己的python脚本位置
列如我的:
cd /;cd sdcard/cxk_python/linux_page
下载安装python
pkg install python
pip install --upgrade pip -i https://pypi.doubanio.com/simple
pip install flask -i https://pypi.doubanio.com/simple
pip install psutil -i https://pypi.doubanio.com/simple
完成之后编写flask项目
run.py
# -*- coding:utf-8 -*-
from flask import *
import json,os,datetime,random
import shutil
import _thread
import time
app = Flask(__name__)
app.config.from_object(__name__)
def GetNameByEveryDir(file_dir):
# Input Root Dir and get all img in per Dir.
# Out Every img with its filename and its dir and its path
FileNameWithPath = []
FileName = []
FileDir = []
for root, dirs, files in os.walk(file_dir):
for file in files:
FileNameWithPath.append(os.path.join(root, file