Commit 120092d6 authored by hujun's avatar hujun

兼容容联云下载

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