|
1 |
| -#!/usr/bin/python |
2 |
| -# |
3 |
| -# Copyright 2024 Kaggle Inc |
4 |
| -# |
5 |
| -# Licensed under the Apache License, Version 2.0 (the "License"); |
6 |
| -# you may not use this file except in compliance with the License. |
7 |
| -# You may obtain a copy of the License at |
8 |
| -# |
9 |
| -# http://www.apache.org/licenses/LICENSE-2.0 |
10 |
| -# |
11 |
| -# Unless required by applicable law or agreed to in writing, software |
12 |
| -# distributed under the License is distributed on an "AS IS" BASIS, |
13 |
| -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
| -# See the License for the specific language governing permissions and |
15 |
| -# limitations under the License. |
16 |
| - |
| 1 | +#!/usr/bin/python |
| 2 | +# |
| 3 | +# Copyright 2024 Kaggle Inc |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
17 | 17 | #!/usr/bin/python
|
18 | 18 | #
|
19 | 19 | # Copyright 2019 Kaggle Inc
|
@@ -1956,8 +1956,12 @@ def download_file(self,
|
1956 | 1956 | size = int(response.headers['Content-Length'])
|
1957 | 1957 | size_read = 0
|
1958 | 1958 | open_mode = 'wb'
|
1959 |
| - remote_date = datetime.strptime(response.headers['Last-Modified'], |
1960 |
| - '%a, %d %b %Y %H:%M:%S %Z') |
| 1959 | + last_modified = response.headers.get('Last-Modified') |
| 1960 | + if last_modified is None: |
| 1961 | + remote_date = datetime.now() |
| 1962 | + else: |
| 1963 | + remote_date = datetime.strptime(response.headers['Last-Modified'], |
| 1964 | + '%a, %d %b %Y %H:%M:%S %Z') |
1961 | 1965 | remote_date_timestamp = time.mktime(remote_date.timetuple())
|
1962 | 1966 |
|
1963 | 1967 | if not quiet:
|
@@ -3757,8 +3761,12 @@ def download_needed(self, response, outfile, quiet=True):
|
3757 | 3761 | quiet: suppress verbose output (default is True)
|
3758 | 3762 | """
|
3759 | 3763 | try:
|
3760 |
| - remote_date = datetime.strptime(response.headers['Last-Modified'], |
3761 |
| - '%a, %d %b %Y %H:%M:%S %Z') |
| 3764 | + last_modified = response.headers.get('Last-Modified') |
| 3765 | + if last_modified is None: |
| 3766 | + remote_date = datetime.now() |
| 3767 | + else: |
| 3768 | + remote_date = datetime.strptime(response.headers['Last-Modified'], |
| 3769 | + '%a, %d %b %Y %H:%M:%S %Z') |
3762 | 3770 | file_exists = os.path.isfile(outfile)
|
3763 | 3771 | if file_exists:
|
3764 | 3772 | local_date = datetime.fromtimestamp(os.path.getmtime(outfile))
|
|
0 commit comments