added a config file

This commit is contained in:
ClF3 2024-04-27 15:29:59 +08:00
parent 4b9fbd4d36
commit 882fe5e8a3
3 changed files with 13 additions and 8 deletions

View File

@ -2,11 +2,13 @@ import os
import sys import sys
from PIL import Image from PIL import Image
import argparse import argparse
import json
if __name__ == '__main__': if __name__ == '__main__':
defaults=json.load(open('defaults.json'))
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--original', help='Path to the original images', default='original') parser.add_argument('--original', help='Path to the original images', default=defaults['original'])
parser.add_argument('--webp', help='Path to the webp images', default='webp') parser.add_argument('--webp', help='Path to the webp images', default=defaults['webp'])
parser.add_argument('--quality', help='Quality of the webp images', default=90, type=int) parser.add_argument('--quality', help='Quality of the webp images', default=defaults['quality'], type=int)
parser.add_argument('--overwrite', help='Overwrite existing images', action='store_true') parser.add_argument('--overwrite', help='Overwrite existing images', action='store_true')
args = parser.parse_args() args = parser.parse_args()

1
defaults.json Normal file
View File

@ -0,0 +1 @@
{ "original": "../pictures", "webp": "../webp1", "quality": 90, "container": "tmp", "remote": "", "local": "../pictures", "ignore": []}

12
sync.py
View File

@ -2,15 +2,17 @@ import os, uuid
from azure.identity import DefaultAzureCredential from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
import argparse import argparse
import json
defaults=json.load(open('defaults.json'))
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--container', help='Name of the container', default='blog') parser.add_argument('--container', help='Name of the container', default=defaults['container'])
parser.add_argument('--remote', help='Path to the remote images', default='posts') parser.add_argument('--remote', help='Path to the remote images', default=defaults['remote'])
parser.add_argument('--local', help='Path to the local images', default='webp') parser.add_argument('--local', help='Path to the local images', default=defaults['local'])
parser.add_argument('--ignore', help='Files to ignore', default=['background.webp'], action='append') parser.add_argument('--ignore', help='Files to ignore', default=defaults['ignore'], action='append')
parser.add_argument('--overwrite', help='Overwrite existing images', action='store_true') parser.add_argument('--overwrite', help='Overwrite existing images', action='store_true')
args=parser.parse_args() args=parser.parse_args()
if args.remote[-1] != '/': if args.remote!='' and args.remote[-1] != '/':
args.remote += '/' args.remote += '/'
try: try: