summaryrefslogtreecommitdiff
path: root/ATRI/modules
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-08-24 00:22:29 +0800
committerKyomotoi <[email protected]>2020-08-24 00:22:29 +0800
commitc413c33b246bb49e31f070d781a8515bb61f7909 (patch)
treed369a283b9229acc6e93c39e2809ad5bae749c47 /ATRI/modules
parent2007f15a7f3f5ad866fa78ab77d2a04d654c8e2a (diff)
downloadATRI-c413c33b246bb49e31f070d781a8515bb61f7909.tar.gz
ATRI-c413c33b246bb49e31f070d781a8515bb61f7909.tar.bz2
ATRI-c413c33b246bb49e31f070d781a8515bb61f7909.zip
[Update]
Diffstat (limited to 'ATRI/modules')
-rw-r--r--ATRI/modules/b64/__init__.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/ATRI/modules/b64/__init__.py b/ATRI/modules/b64/__init__.py
index f54334b..a8a6bb6 100644
--- a/ATRI/modules/b64/__init__.py
+++ b/ATRI/modules/b64/__init__.py
@@ -11,12 +11,15 @@ path_temp_img = Path('.') / 'ATRI' / 'data' / 'temp' / 'img'
def b64_str_img_url(url: str):
img_d = requests.get(url)
name = 'temp.jpg'
- with open(str(path_temp_img) + '/' + name, 'wb') as f:
+ find_img = Path('.') / 'ATRI' / 'data' / 'temp' / 'img' / f'{name}'
+ with open(find_img, 'wb') as f:
f.write(img_d.content)
- find_img = os.path.join(str(path_temp_img) + '/' + name)
- with open(find_img, 'rb') as f:
- content = f.read()
- b64_str = base64.b64encode(content).decode()
- time.sleep(1)
- os.remove(str(path_temp_img) + '/' + name)
- return b64_str \ No newline at end of file
+ if find_img.stat().st_size >= 1000000:
+ print('超过1MB,跳过!')
+ else:
+ with open(find_img, 'rb') as f:
+ content = f.read()
+ b64_str = base64.b64encode(content).decode()
+ time.sleep(1)
+ os.remove(str(path_temp_img) + '/' + name)
+ return b64_str \ No newline at end of file