import os
import time
import codecs
import re
import requests
def workfile(mypath):
for root, dirs, files in os.walk(mypath):
for name in files:
if name.endswith(".md"):
filename = os.path.join(root, name)
content = codecs.open(filename, 'r', 'UTF-8')
matchObj = re.findall(r'(?:!\[(.*?\]\((.*?)\)))', content.read())
print(filename)
for pic in matchObj:
print(root)
print(filename)
picPath = os.path.join(os.path.abspath(root), pic[1])
print(picPath)
# picupload(picPath)
(path, picname) = os.path.split(picPath)
print(picname)
basic_url = 'https://pic.itstephen.cn/images/2021/02/25/'
replaceContent = content.read().replace(pic[1], basic_url + picname)
content.write(replaceContent)
def picupload(pic):
url = 'https://pic.itstephen.cn/api/1/upload/?key=6e4aaef5e9f3f696bfb8f4f'
action = 'upload'
form = {'source': open(pic, 'rb')}
r = requests.post(url, files=form)
print(r.content)
if __name__ == '__main__':
print('hello, world')
path = os.path.curdir
print(os.path.abspath("../"))
os.listdir
ss = 'ssasas'
print(ss.endswith('as'))
workfile(path)
time.sleep(5)
python脚本文件遍历,字符串查找,图片上传
未经允许不得转载:Stephen Young » python脚本文件遍历,字符串查找,图片上传
相关推荐
-      阿里云ddns脚本全流程+python、pip环境安装
-      图片脚本上传最终版
-      Python版autoSummary脚本
-      Pythonista
评论前必须登录!
注册