Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,37 +1,56 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import time
|
| 3 |
-
import shutil
|
| 4 |
-
import subprocess
|
| 5 |
-
|
| 6 |
-
gh_token = os.getenv("gh_token")
|
| 7 |
-
|
| 8 |
-
repo = "Genarabia-Islam-Web"
|
| 9 |
-
|
| 10 |
-
url_with_token = f"https://{gh_token}@github.com/Eslam-Magdy-1297/{repo}.git"
|
| 11 |
-
|
| 12 |
-
os.system(f"git clone {url_with_token}")
|
| 13 |
-
|
| 14 |
-
time.sleep(10)
|
| 15 |
-
|
| 16 |
-
source_dir = repo
|
| 17 |
-
destination_dir = "."
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
d = os.path.join(destination_dir, item)
|
| 31 |
-
shutil.move(s, d)
|
| 32 |
-
|
| 33 |
-
os.rmdir(source_dir)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
exec(code)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import shutil
|
| 4 |
+
import subprocess
|
| 5 |
+
|
| 6 |
+
gh_token = os.getenv("gh_token")
|
| 7 |
+
|
| 8 |
+
repo = "Genarabia-Islam-Web"
|
| 9 |
+
|
| 10 |
+
url_with_token = f"https://{gh_token}@github.com/Eslam-Magdy-1297/{repo}.git"
|
| 11 |
+
|
| 12 |
+
os.system(f"git clone {url_with_token}")
|
| 13 |
+
|
| 14 |
+
time.sleep(10)
|
| 15 |
+
|
| 16 |
+
source_dir = repo
|
| 17 |
+
destination_dir = "."
|
| 18 |
+
|
| 19 |
+
current_directory = os.getcwd()
|
| 20 |
+
|
| 21 |
+
items = os.listdir(current_directory)
|
| 22 |
+
|
| 23 |
+
for item in items:
|
| 24 |
+
print(item)
|
| 25 |
+
|
| 26 |
+
# Improved merging logic
|
| 27 |
+
for item in os.listdir(source_dir):
|
| 28 |
+
s = os.path.join(source_dir, item)
|
| 29 |
+
d = os.path.join(destination_dir, item)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# If it's a directory that exists in both locations, merge them
|
| 32 |
+
if os.path.isdir(s) and os.path.isdir(d):
|
| 33 |
+
print(f"Merging directory: {item}")
|
| 34 |
+
# Copy contents from source to destination
|
| 35 |
+
for sub_item in os.listdir(s):
|
| 36 |
+
sub_s = os.path.join(s, sub_item)
|
| 37 |
+
sub_d = os.path.join(d, sub_item)
|
| 38 |
+
if os.path.isfile(sub_s):
|
| 39 |
+
shutil.copy2(sub_s, sub_d)
|
| 40 |
+
print(f" Copied: {sub_item}")
|
| 41 |
+
elif os.path.isdir(sub_s):
|
| 42 |
+
shutil.copytree(sub_s, sub_d, dirs_exist_ok=True)
|
| 43 |
+
print(f" Merged subdirectory: {sub_item}")
|
| 44 |
+
# If destination doesn't exist, just move it
|
| 45 |
+
elif not os.path.exists(d):
|
| 46 |
+
shutil.move(s, d)
|
| 47 |
+
print(f"Moved: {item}")
|
| 48 |
+
else:
|
| 49 |
+
print(f"Skipped (already exists): {item}")
|
| 50 |
+
|
| 51 |
+
# Clean up the cloned repo directory
|
| 52 |
+
shutil.rmtree(source_dir)
|
| 53 |
+
|
| 54 |
+
with open("app.py", "r") as file:
|
| 55 |
+
code = file.read()
|
| 56 |
exec(code)
|