首次提交
This commit is contained in:
0
photo_review/util/__init__.py
Normal file
0
photo_review/util/__init__.py
Normal file
50
photo_review/util/data_util.py
Normal file
50
photo_review/util/data_util.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# 处理金额类数据
|
||||
def handle_decimal(string):
|
||||
if not string:
|
||||
return ""
|
||||
return re.sub(r'[^0-9.]', '', string)
|
||||
|
||||
|
||||
# 处理日期类数据
|
||||
def handle_date(string):
|
||||
if not string:
|
||||
return ""
|
||||
|
||||
string = string.replace("年", "-").replace("月", "-").replace("日", "")
|
||||
string = re.sub(r'[^0-9-]', '', string)
|
||||
if is_valid_date_format(string):
|
||||
return string
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
# 判断是否是合法的日期格式
|
||||
def is_valid_date_format(date_str):
|
||||
if len(date_str) < 6:
|
||||
return False
|
||||
|
||||
# 定义可能的日期格式
|
||||
formats = [
|
||||
# yyyy-MM-dd
|
||||
'%Y-%m-%d',
|
||||
# yy-MM-dd
|
||||
'%y-%m-%d',
|
||||
# yyyyMMdd
|
||||
'%Y%m%d',
|
||||
# yyMMdd
|
||||
'%y%m%d',
|
||||
]
|
||||
|
||||
# 遍历所有格式,尝试解析日期
|
||||
for fmt in formats:
|
||||
try:
|
||||
datetime.strptime(date_str, fmt)
|
||||
return True
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return False
|
||||
27
photo_review/util/ucloud.py
Normal file
27
photo_review/util/ucloud.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# https://github.com/ucloud/ufile-sdk-python
|
||||
import logging
|
||||
|
||||
from ufile import filemanager
|
||||
|
||||
public_key = "4Z7QYI7qml36QRjcCjKrls7aHl1R6H6uq"
|
||||
private_key = "FIdW1Kev1Ge3K7GHXzSLyGG1wTnaG6LE9BxmIVubcCaG"
|
||||
bucket = "drg100"
|
||||
upload_suffix = ".cn-sh2.ufileos.com"
|
||||
download_suffix = ".cn-sh2.ufileos.com"
|
||||
|
||||
|
||||
def get_private_url(key):
|
||||
get_ufile_handler = filemanager.FileManager(public_key, private_key, upload_suffix, download_suffix)
|
||||
|
||||
# 判断文件是否存在
|
||||
_, resp = get_ufile_handler.head_file(bucket, key)
|
||||
if resp.status_code != 200:
|
||||
logging.warning("uCloud中未找到(%s)! status: %d error: %s", key, resp.status_code, resp.error)
|
||||
return None
|
||||
|
||||
# 获取公有空间下载url
|
||||
# url = get_ufile_handler.public_download_url(bucket, key)
|
||||
|
||||
# 获取私有空间下载url, expires为下载链接有效期,单位为秒
|
||||
url = get_ufile_handler.private_download_url(bucket, key, expires=60)
|
||||
return url
|
||||
Reference in New Issue
Block a user