如何使用Typora+MinIO+Python代碼打造舒適協(xié)作環(huán)境
不知不覺大半年沒更新了...前面小二介紹過使用Typora+MinIO+Java代碼打造舒適寫作環(huán)境,然后有很多大佬啊,說用Java來實(shí)現(xiàn)簡直是殺雞用上牛刀,小二想了想,確實(shí)有點(diǎn)...正好小二最近在學(xué)習(xí)Python,所以咱們就改用Python實(shí)現(xiàn)一版。
安裝MinIO
安裝參考MinIO官網(wǎng),或者參考小二的博客,搜索關(guān)鍵詞 → Linux安裝MinIO。
安裝完成之后使用域名映射好后臺服務(wù),小二使用nginx配置域名,配置參考如下。
server {
listen 443 ssl;
server_name minio.itwxe.com;
include /usr/local/nginx/conf/conf.d/common.conf;
access_log logs/minioAccess.log;
location / {
proxy_pass http://127.0.0.1:9000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
server {
listen 443 ssl;
server_name minio-console.itwxe.com;
include /usr/local/nginx/conf/conf.d/common.conf;
access_log logs/minioAccess.log;
location / {
proxy_pass http://127.0.0.1:9020;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}其中common.conf為域名通用配置。
ssl_certificate /usr/local/nginx/ssl/fullchain.crt;
ssl_certificate_key /usr/local/nginx/ssl/itwxe.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 30m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5:!EXPORT56:!EXP;
ssl_prefer_server_ciphers on;
proxy_connect_timeout 500;
proxy_send_timeout 500;
proxy_read_timeout 500;
client_max_body_size 100m;配置好之后訪問https://minio-console.itwxe.com即可訪問后臺。
同時為了存儲桶圖片所有人可以訪問,需要將存儲桶設(shè)置為公開。

Python代碼實(shí)現(xiàn)上傳
首先,小二作為一個半吊子Python學(xué)習(xí)者,看了下MinIO官網(wǎng)提供的SDK范例。
安裝依賴。
pip install minio
官網(wǎng)示例代碼。
from minio import Minio
from minio.error import S3Error
def main():
# Create a client with the MinIO server playground, its access key
# and secret key.
client = Minio(
"play.min.io",
access_key="Q3AM3UQ867SPQQA43P2F",
secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
)
# Make 'asiatrip' bucket if not exist.
found = client.bucket_exists("asiatrip")
if not found:
client.make_bucket("asiatrip")
else:
print("Bucket 'asiatrip' already exists")
# Upload '/home/user/Photos/asiaphotos.zip' as object name
# 'asiaphotos-2015.zip' to bucket 'asiatrip'.
client.fput_object(
"asiatrip", "asiaphotos-2015.zip", "/home/user/Photos/asiaphotos.zip",
)
print(
"'/home/user/Photos/asiaphotos.zip' is successfully uploaded as "
"object 'asiaphotos-2015.zip' to bucket 'asiatrip'."
)
if __name__ == "__main__":
try:
main()
except S3Error as exc:
print("error occurred.", exc)于是乎,小二開始依葫蘆畫瓢,代碼如下。
import sys
import time
from pathlib import Path
import random
from minio import Minio
minio_domain = 'minio.itwxe.com'
minio_access_key = '你的賬號名稱'
minio_secret_key = '你的密碼'
# 存儲桶名稱
bucket_name = 'img'
# 存儲桶子文件夾名稱
bucket_name_dir_name = 'blog'
# 獲取minio客戶端連接
minio_client = Minio(minio_domain, minio_access_key, minio_secret_key)
if not minio_client.bucket_exists(bucket_name):
# 如果存儲桶不存在,則創(chuàng)建
minio_client.make_bucket(bucket_name)
# 獲取圖片參數(shù)
images = sys.argv[1:]
for image in images:
# 文件后綴
suffix = Path(image).suffix
# 自定義文件名,使用13位時間戳+2位隨機(jī)數(shù)
file_name = '{}{}{}'.format(round(time.time() * 1000), random.randint(10, 99), suffix)
# 文件存儲桶下子路徑拼接
remote_full_path_name = '{}/{}'.format(bucket_name_dir_name, file_name)
# 上傳文件
minio_client.fput_object(bucket_name, remote_full_path_name, image)
# 打印文件路徑
print("https://minio.itwxe.com/{}/{}".format(bucket_name, remote_full_path_name))寫完之后小二不禁感慨,確實(shí)比Java簡單億點(diǎn)點(diǎn),設(shè)置一下typora,python 你的python文件位置。

這張圖片就是上傳后的路徑結(jié)果啦,在此,小二也祝愿大家可以愉快的寫作。
到此這篇關(guān)于如何使用Typora+MinIO+Python代碼打造舒適協(xié)作環(huán)境的文章就介紹到這了,更多相關(guān)Typora+MinIO+Python內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在Python中使用AOP實(shí)現(xiàn)Redis緩存示例
本篇文章主要介紹了在Python中使用AOP實(shí)現(xiàn)Redis緩存示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07
Python3 實(shí)現(xiàn)將bytes圖片轉(zhuǎn)jpg格式
這篇文章主要介紹了Python3 實(shí)現(xiàn)將bytes圖片轉(zhuǎn)jpg格式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03
如何用Python提取10000份log中的產(chǎn)品信息
這篇文章主要介紹了如何用Python提取10000份log中的產(chǎn)品信息,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2021-01-01
Python數(shù)據(jù)可視化之用Matplotlib繪制常用圖形
Matplotlib能夠繪制折線圖、散點(diǎn)圖、柱狀圖、直方圖、餅圖. 我們需要知道不同的統(tǒng)計(jì)圖的意義,以此來決定選擇哪種統(tǒng)計(jì)圖來呈現(xiàn)我們的數(shù)據(jù),今天就帶大家詳細(xì)了解如何繪制這些常用圖形,需要的朋友可以參考下2021-06-06

