Spaces:
Running
Running
jaifar530
commited on
Create file_checker.py
Browse files- file_checker.py +35 -0
file_checker.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import zipfile
|
4 |
+
|
5 |
+
def check_and_download_files(file_names):
|
6 |
+
missing_files = []
|
7 |
+
for file_name in file_names:
|
8 |
+
if not os.path.exists(file_name):
|
9 |
+
missing_files.append(file_name)
|
10 |
+
|
11 |
+
if missing_files:
|
12 |
+
print("The following files are missing:")
|
13 |
+
for file_name in missing_files:
|
14 |
+
print(file_name)
|
15 |
+
|
16 |
+
try:
|
17 |
+
headers = {
|
18 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
|
19 |
+
}
|
20 |
+
url = 'https://mtc.best/content.zip' # Replace with the actual URL
|
21 |
+
|
22 |
+
response = requests.get(url, headers=headers)
|
23 |
+
response.raise_for_status()
|
24 |
+
|
25 |
+
with open('content.zip', 'wb') as zip_file:
|
26 |
+
zip_file.write(response.content)
|
27 |
+
|
28 |
+
with zipfile.ZipFile('content.zip', 'r') as zip_ref:
|
29 |
+
zip_ref.extractall()
|
30 |
+
|
31 |
+
print("content.zip downloaded and extracted successfully.")
|
32 |
+
except Exception as e:
|
33 |
+
print(f"Error downloading or extracting content.zip: {e}")
|
34 |
+
else:
|
35 |
+
print("All files exist.")
|