markdown-img-icexmoon 0.3.9__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
markdown_img/config.py CHANGED
@@ -16,6 +16,7 @@ class Config():
16
16
  PARAM_QCLOUD_INFO = 'qcloud_info'
17
17
  PARAM_QINIU_INFO = "qiniu_info"
18
18
  PARAM_UPYUN_INFO = "upyun_info"
19
+ PARAM_FZ_INFO = "fz_info"
19
20
  PARAM_URL_ENCODE_MODE = 'url_encode_mode'
20
21
  PARAM_LANGUAGE = 'language'
21
22
  PARAM_COMPRESS = "compress"
@@ -42,6 +43,8 @@ class Config():
42
43
  UPYUN_INFO_PASSWORD = "password"
43
44
  UPYUN_INFO_DIR = "dir"
44
45
  UPYUN_INFO_DOMAIN = "domain"
46
+ FZ_INFO_PHONE = 'phone'
47
+ FZ_INFO_PWD = 'pwd'
45
48
  IMG_SERVICE_YUJIAN = 'yujian'
46
49
  IMG_SERVICE_SMMS = 'smms'
47
50
  IMG_SERVICE_RRUU = 'rruu'
@@ -61,6 +64,7 @@ class Config():
61
64
  IMG_SERVICE_BKIMG = "bkimg"
62
65
  IMG_SERVICE_MUKE = "muke"
63
66
  IMG_SERVICE_UPYUN = "upyun"
67
+ IMG_SERVICE_FZ = "fz"
64
68
  # 图片压缩相关配置
65
69
  COMPRESS_INFO_STATUS = "status"
66
70
  COMPRESS_INFO_LIMIT = "limit"
@@ -255,7 +259,7 @@ class Config():
255
259
  if info == '':
256
260
  raise UserException(UserException.CODE_NO_QINIU_INFO)
257
261
  return info
258
-
262
+
259
263
  def writeSmmsToken(self, token: str):
260
264
  with open(file=self.getSmmsTokenFile(), mode='w') as configFileOpen:
261
265
  print(token, file=configFileOpen)
@@ -49,6 +49,9 @@ class Globalization:
49
49
  "image_web_configs_changed": "图床配置已更新",
50
50
  "input_error_and_hint": "输入的值{}不合法,请阅读帮助文档。",
51
51
  "related_configs_changed": "相关配置已更新",
52
+ "fz_info_required": "缺少风筝图床相关配置,请输入",
53
+ "fz_info_phone":"手机号",
54
+ "fz_info_pwd":"密码",
52
55
  "qiniu_info_saved": "七牛云的相关信息已保存,请重新运行程序",
53
56
  "qiniu_info_required": "缺少七牛云的相关配置,请按提示输入",
54
57
  "qiniu_access_key_input": "请输入七牛云存储的access_key",
@@ -195,6 +198,9 @@ class Globalization:
195
198
  "current_operation_success": "Current operation executed successfully",
196
199
  "config_name": "Config name",
197
200
  "create_time": "Create time",
201
+ "fz_info_required": "Requre FZ image bed config, please enter",
202
+ "fz_info_phone":"phone",
203
+ "fz_info_pwd":"password",
198
204
  }
199
205
 
200
206
  def __new__(cls) -> Any:
markdown_img/help.info CHANGED
@@ -18,6 +18,7 @@
18
18
  qcloud 腾讯云对象存储(需要提供必要连接信息)
19
19
  qiniu 七牛云(需要提供必要连接信息)
20
20
  upyun 又拍云(需要提供必要连接信息)
21
+ fz 风筝图床(需要提供必要的连接信息)
21
22
  bilibili,sougou,huluxia,catbox,360,postimages,ai58,gtimg,bkimg,muke
22
23
  -c --change_token 替换图床访问令牌
23
24
  this 当前图床
markdown_img/help_en.info CHANGED
@@ -18,6 +18,7 @@
18
18
  qcloud Tencent Cloud Object Storage (required to provide necessary connection information)
19
19
  qiniu Qiniu Cloud (required to provide necessary connection information)
20
20
  upyun UPYun Cloud (required to provide necessary connection information)
21
+ fz fengzhen image bed (required to provide necessary connection information)
21
22
  bilibili,sougou,huluxia,catbox,360,postimages,ai58,gtimg,bkimg,muke
22
23
  -c --change_token Replace the image bed access token.
23
24
  this current image bed.
@@ -0,0 +1,107 @@
1
+ from .img_service import ImgService
2
+ import requests
3
+ from ..config import Config
4
+ from ..user_exception import UserException
5
+ import json
6
+ from typing import Any
7
+
8
+
9
+ class FzImgService(ImgService):
10
+ '''风筝图床'''
11
+
12
+ def __init__(self) -> None:
13
+ super().__init__()
14
+ self.sysConfig = Config.getInstance()
15
+
16
+ def __getToken(self):
17
+ if hasattr(self, "__token"):
18
+ return self.__token
19
+ phone = self.__getInfo('phone')
20
+ pwd = self.__getInfo('pwd')
21
+ self.__token = self.__login(phone, pwd)
22
+ return self.__token
23
+
24
+ def __login(self, phone: str, pwd: str) -> str:
25
+ '''登录并获取token'''
26
+ r = requests.post('https://imgbed.link/imgbed/user/login',
27
+ data={'phoneNum': phone, 'pwd': pwd})
28
+ try:
29
+ respJson = r.json()
30
+ except json.decoder.JSONDecodeError as e:
31
+ self.sysConfig.writeErrorLog("接口解析错误:"+str(e)+"\n返回信息:"+r.text)
32
+ raise UserException(UserException.CODE_UPLOAD_ERROR)
33
+ except Exception as e:
34
+ self.sysConfig.writeErrorLog("未知的接口调用错误:"+str(e))
35
+ raise UserException(UserException.CODE_UPLOAD_ERROR)
36
+ if respJson['code'] != 0:
37
+ raise UserException(
38
+ UserException.CODE_UPLOAD_ERROR, '接口调用出错:'+respJson['msg'])
39
+ return respJson['token']
40
+
41
+ def __getInfo(self, key: str) -> Any:
42
+ info = self.getConfigInfo()
43
+ if key in info:
44
+ return info[key]
45
+ raise UserException(UserException.CODE_OTHER, '缺少图床配置:'+key)
46
+
47
+ def getConfigInfo(self) -> dict:
48
+ sysConfig = Config.getInstance()
49
+ info = sysConfig.getConfigParam(Config.PARAM_FZ_INFO)
50
+ if info == '':
51
+ raise UserException(UserException.CODE_NO_IMG_SERVICE_CONFIG)
52
+ return info
53
+
54
+ def upload(self, localImg: str) -> str:
55
+ url = "https://imgbed.link/imgbed/file/upload"
56
+ payload = {}
57
+ imgOpen = open(localImg, 'rb')
58
+ files = {'file': imgOpen}
59
+ headers = {
60
+ 'User-Agent': 'Apifox/1.0.0 (https://www.apifox.cn)',
61
+ 'token': self.__getToken()
62
+ }
63
+
64
+ r = requests.request("POST", url, headers=headers,
65
+ data=payload, files=files)
66
+ imgOpen.close()
67
+ try:
68
+ respJson = r.json()
69
+ except json.decoder.JSONDecodeError as e:
70
+ self.sysConfig.writeErrorLog("接口解析错误:"+str(e)+"\n返回信息:"+r.text)
71
+ raise UserException(UserException.CODE_UPLOAD_ERROR)
72
+ except Exception as e:
73
+ self.sysConfig.writeErrorLog("未知的接口调用错误:"+str(e))
74
+ raise UserException(UserException.CODE_UPLOAD_ERROR)
75
+ return respJson['rows'][0]['url']
76
+
77
+ def inputConfig(self) -> None:
78
+ info = {}
79
+ print(self.globalization.getTextWithColon("fz_info_required"))
80
+ info[Config.FZ_INFO_PHONE] = input(
81
+ self.globalization.getTextWithColon("fz_info_phone"))
82
+ info[Config.FZ_INFO_PWD] = input(
83
+ self.globalization.getTextWithColon("fz_info_pwd"))
84
+ sysConfig = self.sysConfig
85
+ sysConfig.setConfigParam(Config.PARAM_FZ_INFO, info)
86
+ sysConfig.writeMainConfig()
87
+ print(self.globalization.getText("config_info_saved"))
88
+
89
+ def inputNewConfig(self) -> None:
90
+ info = {}
91
+ info[Config.FZ_INFO_PHONE] = input(
92
+ self.globalization.getTextWithColon("fz_info_phone"))
93
+ info[Config.FZ_INFO_PWD] = input(
94
+ self.globalization.getTextWithColon("fz_info_pwd"))
95
+ sysConfig = self.sysConfig
96
+ sysConfig.setConfigParam(Config.PARAM_FZ_INFO, info)
97
+ sysConfig.writeMainConfig()
98
+ print(self.globalization.getText("config_info_saved"))
99
+
100
+ def getConfigInfoText(self) -> tuple:
101
+ lines = list()
102
+ info = self.getConfigInfo()
103
+ lines.append(self.globalization.getTextWithParam(
104
+ "fz_info_phone", info[Config.FZ_INFO_PHONE]))
105
+ lines.append(self.globalization.getTextWithParam(
106
+ "fz_info_pwd", info[Config.FZ_INFO_PWD]))
107
+ return tuple(lines)
@@ -7,6 +7,7 @@ from .img_service.qcloud_img_service import QcloudImgService
7
7
  from .img_service.qiniu_img_service import QiniuImgService
8
8
  from .img_service.smms_img_service import SmmsImgService
9
9
  from .img_service.Upyun_img_service import UpyunImgService
10
+ from .img_service.fz_img_service import FzImgService
10
11
 
11
12
 
12
13
  class ImgServiceManager:
@@ -72,6 +73,8 @@ class ImgServiceManager:
72
73
  webImage = YujianImgService(YujianImgService.API_TYPE_MUKE)
73
74
  elif imgService == Config.IMG_SERVICE_UPYUN:
74
75
  webImage = UpyunImgService()
76
+ elif imgService == Config.IMG_SERVICE_FZ:
77
+ webImage = FzImgService()
75
78
  else:
76
79
  webImage = SmmsImgService()
77
80
  return webImage
@@ -86,7 +89,8 @@ class ImgServiceManager:
86
89
  Config.IMG_SERVICE_QCLOUD, Config.IMG_SERVICE_QINIU, Config.IMG_SERVICE_BILIBILI,
87
90
  Config.IMG_SERVICE_SOUGOU, Config.IMG_SERVICE_HULUXIA, Config.IMG_SERVICE_CATBOX,
88
91
  Config.IMG_SERVICE_360, Config.IMG_SERVICE_POSTIMAGES, Config.IMG_SERVICE_AI58,
89
- Config.IMG_SERVICE_GTIMG, Config.IMG_SERVICE_BKIMG, Config.IMG_SERVICE_MUKE, Config.IMG_SERVICE_UPYUN}
92
+ Config.IMG_SERVICE_GTIMG, Config.IMG_SERVICE_BKIMG, Config.IMG_SERVICE_MUKE, Config.IMG_SERVICE_UPYUN,
93
+ Config.IMG_SERVICE_FZ}
90
94
  if flag in supportedService:
91
95
  return True
92
96
  return False
markdown_img/main.py CHANGED
@@ -152,7 +152,8 @@ class Main():
152
152
  shutil.copyfile(localImg, relativeLocalImage)
153
153
  # 替换图片路径为相对路径
154
154
  line = line.replace(
155
- localImg, "."+sysConfig.getPathSplit()+"images"+sysConfig.getPathSplit()+imgName)
155
+ # 改为使用/而非\
156
+ localImg, "."+"/"+"images"+"/"+imgName)
156
157
  copyFileOpen.write(line)
157
158
  copyFileOpen.close()
158
159
  # 保存原始文件备份
markdown_img/smms_img.py CHANGED
@@ -39,6 +39,10 @@ class SmmsImg():
39
39
  images[MAX_SAME_TIME_DEAL:len(images)], results)
40
40
 
41
41
  def uploadOne(self, localImg):
42
+ # 如果是 gif 而非静态图片,不压缩
43
+ if (localImg.endswith(".gif")):
44
+ imgService = ImgServiceManager.getImgService()
45
+ return imgService.upload(localImg)
42
46
  # 如果设置了压缩选项,进行压缩
43
47
  info = self.sysConfig.getCompressInfo()
44
48
  if(info[Config.COMPRESS_INFO_STATUS] == "on"):
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: markdown-img-icexmoon
3
- Version: 0.3.9
3
+ Version: 1.0.0
4
4
  Summary: A program for find and upload images in markdown file and will replace them.
5
5
  Home-page: https://github.com/icexmoon/markdown-img
6
6
  Author: icexmoon
@@ -18,6 +18,7 @@ Requires-Dist: qiniu
18
18
  Requires-Dist: upyun
19
19
  Requires-Dist: Pillow
20
20
  Requires-Dist: tinify
21
+ Dynamic: license-file
21
22
 
22
23
  # Markdown-img User's Guide
23
24
 
@@ -41,6 +42,10 @@ English | [**简体中文**](https://github.com/icexmoon/markdown-img/blob/maste
41
42
  - [**Update the image bed acess token**](https://github.com/icexmoon/markdown-img#update-the-image-bed-access-token)
42
43
  - [**Scan images and create indexes**](https://github.com/icexmoon/markdown-img#scan-images-and-create-indexes)
43
44
  - [**Refreshing a copy of the image bed**](https://github.com/icexmoon/markdown-img#refreshing-a-copy-of-the-image-bed)
45
+ - [**Backing up the system configuration**](https://github.com/icexmoon/markdown-img#backing-up-the-system-configuration)
46
+ - [**List saved configurations**](https://github.com/icexmoon/markdown-img#list-saved-configurations)
47
+ - [**Replacing configurations**](https://github.com/icexmoon/markdown-img#replacing-configurations)
48
+ - [**Relative path image**](https://github.com/icexmoon/markdown-img#relative-path-image)
44
49
  - [**Acknowledgements**](https://github.com/icexmoon/markdown-img#acknowledgements)
45
50
  - [**Update Log**](https://github.com/icexmoon/markdown-img#update-log)
46
51
 
@@ -246,6 +251,19 @@ pymdimg --change_config xxx
246
251
 
247
252
  where `xxx` is the file name of the saved configuration you want to replace. To see what saved configurations are available, please use [Function: List saved configurations]. In addition, it is better to save the current configuration before using this function.
248
253
 
254
+ ### Relative path image
255
+
256
+ You can process the MD file using absolute path pictures to use relative path pictures, and the program will copy the original pictures to the images subdirectory of the current directory as relative path pictures.
257
+
258
+ The purpose of this function is to provide convenience for some cross-platform, multi-device users, using relative paths, raw images and MD files can be easily moved, or using a synchronization service similar to Nut Cloud for multi-device synchronization.
259
+
260
+ ```shell
261
+ pymdimg -m relative_img
262
+ ```
263
+
264
+ > - In order to avoid the corruption of the original MD file caused by program errors, one original file will be kept and backed up in the backup subdirectory.
265
+ > - Because of the difference between Windows and Linux platform separators, there is no guarantee that the relative directories of both will behave properly.
266
+
249
267
 
250
268
  ## Acknowledgements
251
269
 
@@ -302,3 +320,7 @@ Fix the bug that can't create img dir normally in Linux.
302
320
  ### 0.3.9
303
321
 
304
322
  Added the function to modify the absolute path image in the MD file to relative path.
323
+
324
+ ### 0.4.0
325
+
326
+ Added the support to fengzhen image bed.
@@ -1,16 +1,16 @@
1
1
  markdown_img/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  markdown_img/__main__.py,sha256=a4Fyl_gjDgwOVcWEdqXMlB10rVrX4Kkqri0jTel_HYs,3780
3
- markdown_img/config.py,sha256=6S0ueJdTS4tS1H8KbdbrTOU_XIq8sHpQRIVTYULH1U8,10732
3
+ markdown_img/config.py,sha256=YxsTYkZOFNvoCfKPlFnEVg7doE3s3pwW5E5q3CTJ3e0,10848
4
4
  markdown_img/config_backup.py,sha256=0xnrYgZ0Z6u3p-NkYkYX8xjZ7hESdWXI1Bem_65D3g4,3001
5
5
  markdown_img/download_help.py,sha256=rRxYoaC8e7cLQZC4WGp4yegAGH4VLr85ATjFZAWEn04,1201
6
- markdown_img/globalization.py,sha256=P_Ado91dx0F_hFY3AVJ9A-dn3utrlcpsMiGNIcSFj88,16436
7
- markdown_img/help.info,sha256=b8UKEkNewo18O-xJh3DZktSck3qznlKmva4v4aagPbg,2505
8
- markdown_img/help_en.info,sha256=I7ll3GcthBc5u6waoPWLAKWxlOKsqqL_b-yVaD6dUE4,2909
9
- markdown_img/img_service_manager.py,sha256=o0vwS3wvlOSOjMvEROX2U8JpVKuoGG4x7tfO_gLmiks,4630
10
- markdown_img/main.py,sha256=SPjrk5Eob-EbkJ_SQq6zdKZr4ke2aLpcAYNSybuNeXk,24247
6
+ markdown_img/globalization.py,sha256=QU9iRLUIgBubwbUu4aaYnYPN9hzLL6RcOUAaBUq5wr4,16760
7
+ markdown_img/help.info,sha256=4XdTWxoUpmlb95NOmoH8c5G92PDUcIAfZWAs0EWVgS4,2570
8
+ markdown_img/help_en.info,sha256=bwBxksZ0fwPmQanLRCZVWQtiyQK5pdlY-BuftLng0GE,2996
9
+ markdown_img/img_service_manager.py,sha256=hD7RCge7Qn7TInGZV-ZExfOegL3yIu7Ll0WI7SiVAXc,4826
10
+ markdown_img/main.py,sha256=J635RXyR0DWcwHI3qMlCqimeeiWIwWUZRZw3DiBXkWc,24257
11
11
  markdown_img/qcloud_client.py,sha256=hQdQK9kBJbqQjO5cNaD6tjGol5sueH2hxP-hbM82yVc,2658
12
12
  markdown_img/qiniu_client.py,sha256=iXb9otEj3JX4QPf0YOSmmZ2XO0eHjPJJDMV_JfPn-7E,1259
13
- markdown_img/smms_img.py,sha256=ILlpS60T3dTWlwlrpv21WDNrwjuXWd6_eH2EVsL1KAA,2334
13
+ markdown_img/smms_img.py,sha256=OziO9o5ON05EQiLTIilOu0wAj9FOdv8jXsFGMuCZhh8,2539
14
14
  markdown_img/time_helper.py,sha256=nmh8YxUoGsudCtywk3hjguuj3KczYPqwbcm_3g-gcYU,710
15
15
  markdown_img/user_exception.py,sha256=Nu0d629DJFspIrNNmnV8rpTgp_1A3EU0M3gCpssWBYA,655
16
16
  markdown_img/compress/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -23,6 +23,7 @@ markdown_img/compress/tinypng_compress_service.py,sha256=De6IyonsUau-zs_svid9OFg
23
23
  markdown_img/img_service/Upyun_img_service.py,sha256=L-i3QIBSTfq8h4FCOAk28Mb3fzyXP89j5rajwpvZSdw,4744
24
24
  markdown_img/img_service/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  markdown_img/img_service/bilibili_img_service.py,sha256=0NdOeXQyOnHu8wX13CxIwviAcJzrimoogYRzneCvd64,851
26
+ markdown_img/img_service/fz_img_service.py,sha256=5UGoBP5lH6e6jGAcCaneeWCnc8Bu4POhNbtZsBQPW9Y,4307
26
27
  markdown_img/img_service/img_service.py,sha256=hRc6OmCK_oKQzM2xHNQbfPPA0OMskBS5VWPU3Rgd3VY,999
27
28
  markdown_img/img_service/none_img_service.py,sha256=gghDgjIALJW7CIk_B0kqSNm8SDbQbcUmjZlt-ZmxZrw,413
28
29
  markdown_img/img_service/qcloud_img_service.py,sha256=dxjEZ1oAlKYHt3V0VwTfRzHgiBU2WkTr7CxIO9Rulhg,5341
@@ -34,9 +35,9 @@ markdown_img/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
34
35
  markdown_img/tools/debug.py,sha256=ja_hrJV3kHF9xjSMTJCfrKP8yv4BCWWtRZwcsBMXodk,340
35
36
  markdown_img/tools/file_tools.py,sha256=Zu_gBbIHK3fYlhgyhHiCK-fIuHVK-x4_uba3KDFCJfw,1228
36
37
  markdown_img/tools/my_time.py,sha256=EwtBktfzVA6oFrWatzNUVncORR32XlLPo6dKGD1hpyQ,181
37
- markdown_img_icexmoon-0.3.9.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
38
- markdown_img_icexmoon-0.3.9.dist-info/METADATA,sha256=3mObgxpuoFK71Wf1Ssw3aBvIdDgDi8crFsv2Bm0yCTw,19258
39
- markdown_img_icexmoon-0.3.9.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
40
- markdown_img_icexmoon-0.3.9.dist-info/entry_points.txt,sha256=Bts6o2l_i_ugWfMJcXicmG62vkqpkNM9RPF3ecRqJz0,55
41
- markdown_img_icexmoon-0.3.9.dist-info/top_level.txt,sha256=hv32rwsEalALIYhSivTuOK17QqDeRD8RiNm_BuLIdk4,13
42
- markdown_img_icexmoon-0.3.9.dist-info/RECORD,,
38
+ markdown_img_icexmoon-1.0.0.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
39
+ markdown_img_icexmoon-1.0.0.dist-info/METADATA,sha256=FAFIaM1fJXjBxOhQxnItxbG1IjAIxG0D29FfxauaBfk,20634
40
+ markdown_img_icexmoon-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
+ markdown_img_icexmoon-1.0.0.dist-info/entry_points.txt,sha256=Bts6o2l_i_ugWfMJcXicmG62vkqpkNM9RPF3ecRqJz0,55
42
+ markdown_img_icexmoon-1.0.0.dist-info/top_level.txt,sha256=hv32rwsEalALIYhSivTuOK17QqDeRD8RiNm_BuLIdk4,13
43
+ markdown_img_icexmoon-1.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5