Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
download
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
download
Commits
c626d9ab
Commit
c626d9ab
authored
Oct 28, 2022
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
155227b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
29 deletions
+31
-29
download.py
download.py
+31
-29
No files found.
download.py
View file @
c626d9ab
...
...
@@ -12,6 +12,7 @@ import threading
class
DownFile
:
download_num
=
0
old_num
=
0
local
=
threading
.
local
()
def
__init__
(
self
,
url
,
save_path
=
"./"
,
call_date_string
=
"call_date"
,
page_string
=
"page_no"
):
"""
...
...
@@ -79,81 +80,82 @@ class DownFile:
:param data:
:return:
"""
url
=
local_file
=
""
count_sleep
=
0
self
.
local
.
url
=
self
.
local
.
local_file
=
""
self
.
local
.
count_sleep
=
0
for
item
in
data
:
if
count_sleep
>=
50
:
if
self
.
local
.
count_sleep
>=
50
:
self
.
log
(
'sleep'
,
'-----10s-----'
)
time
.
sleep
(
10
)
count_sleep
=
0
self
.
local
.
count_sleep
=
0
if
len
(
item
[
'voice_file'
])
>
0
:
local_file
=
self
.
save_path
+
item
[
'voice_file'
]
if
self
.
check_file
(
local_file
):
self
.
local
.
local_file
=
self
.
save_path
+
item
[
'voice_file'
]
if
self
.
check_file
(
self
.
local
.
local_file
):
self
.
lock
.
acquire
()
self
.
old_num
=
self
.
old_num
+
1
self
.
lock
.
release
()
continue
time_array
=
time
.
strptime
(
item
[
'call_time'
],
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
local_dir
=
time
.
strftime
(
'
%
Y
%
m
%
d'
,
time_array
)
self
.
local
.
time_array
=
time
.
strptime
(
item
[
'call_time'
],
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
self
.
local
.
local_dir
=
time
.
strftime
(
'
%
Y
%
m
%
d'
,
self
.
local
.
time_array
)
if
int
(
item
[
'type'
])
==
1
:
try
:
count_sleep
=
count_sleep
+
1
# 增加暂停计数
url
=
self
.
ali_yun_sdk
(
item
[
'call_time'
],
item
[
'call_id'
])
is_ok
=
0
self
.
local
.
count_sleep
=
self
.
local
.
count_sleep
+
1
# 增加暂停计数
self
.
local
.
url
=
self
.
ali_yun_sdk
(
item
[
'call_time'
],
item
[
'call_id'
])
self
.
local
.
is_ok
=
0
except
Exception
as
result
:
self
.
log
(
"exception 20s------------"
,
str
(
result
))
time
.
sleep
(
20
)
is_ok
=
1
self
.
local
.
is_ok
=
1
# 第二次尝试
if
is_ok
==
1
:
if
self
.
local
.
is_ok
==
1
:
try
:
count_sleep
=
count_sleep
+
1
# 增加暂停计数
url
=
self
.
ali_yun_sdk
(
item
[
'call_time'
],
item
[
'call_id'
])
self
.
local
.
count_sleep
=
self
.
local
.
count_sleep
+
1
# 增加暂停计数
self
.
local
.
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
:
if
len
(
self
.
local
.
url
)
==
0
:
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
:]
# 阿里云文件名
self
.
local
.
string_end
=
self
.
local
.
url
.
find
(
"?"
)
self
.
local
.
file_url
=
self
.
local
.
url
[
0
:
self
.
local
.
string_end
]
self
.
local
.
local_file
=
self
.
save_path
+
self
.
local
.
local_dir
+
'/'
+
\
re
.
findall
(
r".com\D.*"
,
self
.
local
.
file_url
)[
0
][
5
:]
# 阿里云文件名
else
:
local_file
=
self
.
save_path
+
'/'
+
item
[
'voice_file'
]
# 使用已载录音文件名
self
.
local
.
local_file
=
self
.
save_path
+
'/'
+
item
[
'voice_file'
]
# 使用已载录音文件名
else
:
if
not
item
[
'mp3_url'
]:
continue
url
=
item
[
'mp3_url'
]
array
=
url
.
split
(
'/'
)
local_file
=
self
.
save_path
+
local_dir
+
'/'
+
array
[
-
1
]
# 容联云文件名
self
.
local
.
url
=
item
[
'mp3_url'
]
self
.
local
.
array
=
self
.
local
.
url
.
split
(
'/'
)
self
.
local
.
local_file
=
self
.
save_path
+
self
.
local
.
local_dir
+
'/'
+
self
.
local
.
array
[
-
1
]
# 容联云文件名
if
len
(
local_file
)
==
0
:
if
len
(
self
.
local
.
local_file
)
==
0
:
continue
if
self
.
check_file
(
local_file
):
if
self
.
check_file
(
self
.
local
.
local_file
):
self
.
lock
.
acquire
()
self
.
old_num
=
self
.
old_num
+
1
self
.
lock
.
release
()
continue
self
.
check_dir
(
self
.
save_path
+
local_dir
)
result
=
request
.
urlretrieve
(
url
,
local_file
)
self
.
check_dir
(
self
.
save_path
+
self
.
local
.
local_dir
)
self
.
local
.
result
=
request
.
urlretrieve
(
self
.
local
.
url
,
self
.
local
.
local_file
)
self
.
lock
.
acquire
()
self
.
download_num
=
self
.
download_num
+
1
self
.
lock
.
release
()
self
.
log
(
'url'
,
url
)
self
.
log
(
'download_file'
,
result
)
self
.
log
(
'url'
,
self
.
local
.
url
)
self
.
log
(
'download_file'
,
self
.
local
.
result
)
self
.
log
(
"download_num"
,
self
.
download_num
)
self
.
log
(
"old_num"
,
self
.
old_num
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment