@gzm1997
2018-05-22T08:40:01.000000Z
字数 1185
阅读 1239
图片 python
因为我经常在markdown书写过程中需要获取我一些图片或者截图的在线url,但是有些图片云盘需要收费或者要自己手动上传不方便。自己上传github固然可以,但是还是不够方便,所以写了个小脚本。


可以看见后面会输出这张图片的url,最后会提示你确认退出,其实这个确认退出只是为了造成阻塞,不然这个cmd文件运行完就自动关闭窗口不留时间给你复制url了。
只用了一点点很简单的py
def deliver_image():raw = os.listdir("raw")if raw == []:return Falsef = open("num.txt", "rb")num_str = f.read().decode("utf-8")num = int(num_str)f.close()old_name = "raw/" + raw[0]image_to_add = Image.open(old_name)new_name = str(num + 1) + ".png"image_to_add.save("mature/" + new_name)f = open("num.txt", "wb")f.write(str(num + 1).encode("utf-8"))f.close()os.remove("raw/" + raw[0])return new_name
def push_to_github():subprocess.call("git add .", shell = True)subprocess.call("git commit -m 新增一张图片", shell = True)subprocess.call("git push origin master", shell = True)
if __name__ == "__main__":pic_name = deliver_image()if pic_name != False:push_to_github()print("图片的url:")print("https://raw.githubusercontent.com/gzm1997/gallery/master/mature/" + pic_name)stop = input("确认退出:")
python add.py
