Commit 120092d6 authored by hujun's avatar hujun

兼容容联云下载

parent 525e1618
......@@ -65,7 +65,7 @@ class DownFile:
下载录音
:return:
"""
url = ""
url = local_file = ""
download_num = 0
old_num = 0
count_sleep = 0
......@@ -83,36 +83,48 @@ class DownFile:
if self.check_file(local_file):
old_num = old_num + 1
continue
try:
count_sleep = count_sleep + 1 # 增加暂停计数
url = self.ali_yun_sdk(item['call_time'], item['call_id'])
is_ok = 0
except Exception as result:
self.log("exception 20s------------", str(result))
time.sleep(20)
is_ok = 1
# 第二次尝试
if is_ok == 1:
time_array = time.strptime(item['call_time'], '%Y-%m-%d %H:%M:%S')
local_dir = time.strftime('%Y%m%d', time_array)
if item['type'] == 1:
try:
count_sleep = count_sleep + 1 # 增加暂停计数
url = self.ali_yun_sdk(item['call_time'], item['call_id'])
is_ok = 0
except Exception as result:
self.log(
"two exception error-----call_time=" + item['call_time'] + '&call_id=' + item['call_id'],
str(result))
self.log("exception 20s------------", str(result))
time.sleep(20)
is_ok = 1
# 第二次尝试
if is_ok == 1:
try:
count_sleep = count_sleep + 1 # 增加暂停计数
url = self.ali_yun_sdk(item['call_time'], item['call_id'])
except Exception as result:
self.log(
"two exception error-----call_time=" + item['call_time'] + '&call_id=' + item['call_id'],
str(result))
if len(url) == 0:
continue
if url == '':
continue
# 当数据库未有记录
if item['voice_file'] == '':
string_end = url.find("?")
file_url = url[0:string_end]
local_file = self.save_path + local_dir + '/' + re.findall(r".com\D.*", file_url)[0][5:] # 阿里云文件名
else:
if len(item['mp3_url']) == 0:
continue
#当数据库未有记录
if item['voice_file'] == '':
string_end = url.find("?")
file_url = url[0:string_end]
url = item['mp3_url']
array = url.split('/')
local_file = self.save_path + local_dir + '/' + array[-1] # 容联云文件名
time_array = time.strptime(item['call_time'], '%Y-%m-%d %H:%M:%S')
local_dir = time.strftime('%Y%m%d', time_array)
local_file = self.save_path + local_dir + '/' + re.findall(r".com\D.*", file_url)[0][5:]
if len(local_file) == 0:
continue
if self.check_file(local_file):
old_num = old_num + 1
......@@ -218,14 +230,10 @@ class DownFile:
self.log('download_over', '')
# today = datetime.date.today()
# one_day = datetime.timedelta(days=1)
# yesterday = today - one_day
# params_url = "https://api.tonglianjituan.com/task/getDownVoiceParamsReport?page_size=3000&source=3&call_date=" + str(yesterday)
start_url = "https://api.tonglianjituan.com/task/getDownVoiceParamsReport?source=3&call_date=2019-12-10"
# DownFile(params_url).start()
# start_url = "https://api.tonglianjituan.com/task/getDownVoiceParamsReport?source=3&call_date=2019-12-10"
# DownFile(start_url).start()
#
params_url = "https://api.tonglianjituan.com/task/getDownVoiceParamsReport?source=3"
save_path = "/data/html/tl_estate/public/static/voice/"
DownFile(params_url, save_path).start_thread(3)
# DownFile(start_url, save_path).start()
\ No newline at end of file
# DownFile(start_url, save_path).start()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment