Delete Teg/1
Browse files
Teg/1
DELETED
|
@@ -1,202 +0,0 @@
|
|
| 1 |
-
# =======================
|
| 2 |
-
# 1) المتطلبات والرفع
|
| 3 |
-
# =======================
|
| 4 |
-
import os, zipfile, re
|
| 5 |
-
import pandas as pd
|
| 6 |
-
import folium
|
| 7 |
-
from folium.plugins import LocateControl
|
| 8 |
-
from google.colab import files
|
| 9 |
-
|
| 10 |
-
print("↥ ارفع ملف Excel...")
|
| 11 |
-
uploaded = files.upload()
|
| 12 |
-
excel_file = list(uploaded.keys())[0]
|
| 13 |
-
print(f"تم الرفع: {excel_file}")
|
| 14 |
-
|
| 15 |
-
# =======================
|
| 16 |
-
# 2) قراءة الملف وتوحيد الأعمدة
|
| 17 |
-
# =======================
|
| 18 |
-
df = pd.read_excel(excel_file)
|
| 19 |
-
|
| 20 |
-
# إزالة أي مسافات من أسماء الأعمدة
|
| 21 |
-
df.columns = df.columns.str.strip()
|
| 22 |
-
print("الأعمدة الموجودة:", df.columns.tolist())
|
| 23 |
-
|
| 24 |
-
# التأكد أن العمود موجود
|
| 25 |
-
if "رقم الباحث" not in df.columns:
|
| 26 |
-
raise ValueError("الملف لا يحتوي على عمود 'رقم الباحث'!")
|
| 27 |
-
|
| 28 |
-
# إنشاء عمود researcher بناءً على "رقم الباحث"
|
| 29 |
-
df['researcher'] = df['رقم الباحث'].astype(str).str.strip()
|
| 30 |
-
df['researcher'] = df['researcher'].apply(lambda x: f"باحث رقم {x}" if x.isdigit() else x)
|
| 31 |
-
|
| 32 |
-
# الأعمدة الأخرى (معالجة الأسماء لو اختلفت)
|
| 33 |
-
rename_map = {}
|
| 34 |
-
if 'اسم المنشأة' in df.columns: rename_map['اسم المنشأة'] = 'est'
|
| 35 |
-
if 'x' in df.columns: rename_map['x'] = 'lon'
|
| 36 |
-
if 'y' in df.columns: rename_map['y'] = 'lat'
|
| 37 |
-
if 'lon' in df.columns: rename_map['lon'] = 'lon'
|
| 38 |
-
if 'lat' in df.columns: rename_map['lat'] = 'lat'
|
| 39 |
-
df = df.rename(columns=rename_map)
|
| 40 |
-
|
| 41 |
-
# تحويل الإحداثيات إلى أرقام (لكن لا نحذف الفارغ)
|
| 42 |
-
df['lon'] = pd.to_numeric(df['lon'], errors='coerce')
|
| 43 |
-
df['lat'] = pd.to_numeric(df['lat'], errors='coerce')
|
| 44 |
-
|
| 45 |
-
# تنظيف النصوص
|
| 46 |
-
if 'est' in df.columns:
|
| 47 |
-
df['est'] = df['est'].astype(str).fillna('بدون اسم').str.strip()
|
| 48 |
-
else:
|
| 49 |
-
df['est'] = 'بدون اسم'
|
| 50 |
-
|
| 51 |
-
# =======================
|
| 52 |
-
# 3) مجلد الخرج
|
| 53 |
-
# =======================
|
| 54 |
-
OUT_DIR = "pages"
|
| 55 |
-
os.makedirs(OUT_DIR, exist_ok=True)
|
| 56 |
-
pages = []
|
| 57 |
-
|
| 58 |
-
# =======================
|
| 59 |
-
# 4) دوال مساعدة
|
| 60 |
-
# =======================
|
| 61 |
-
def make_footer_html():
|
| 62 |
-
return """
|
| 63 |
-
<div style="
|
| 64 |
-
position: fixed;
|
| 65 |
-
bottom: 8px; left: 8px;
|
| 66 |
-
background: rgba(255,255,255,0.85);
|
| 67 |
-
padding: 6px 10px;
|
| 68 |
-
border-radius: 8px;
|
| 69 |
-
font-size: 13px;
|
| 70 |
-
direction: rtl;
|
| 71 |
-
z-index: 9999;
|
| 72 |
-
box-shadow: 0 1px 6px rgba(0,0,0,0.15);
|
| 73 |
-
">
|
| 74 |
-
تصميم وإعداد <b>نوف الناصر</b>
|
| 75 |
-
</div>
|
| 76 |
-
"""
|
| 77 |
-
|
| 78 |
-
def esri_world_imagery():
|
| 79 |
-
return folium.TileLayer(
|
| 80 |
-
tiles="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
|
| 81 |
-
attr="© Esri",
|
| 82 |
-
name="أقمار صناعية (Esri)",
|
| 83 |
-
overlay=False,
|
| 84 |
-
control=True
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
# =======================
|
| 88 |
-
# 5) إنشاء صفحات الباحثين (ديناميكي)
|
| 89 |
-
# =======================
|
| 90 |
-
# نجيب كل الأرقام الموجودة في "رقم الباحث"
|
| 91 |
-
all_ids = pd.to_numeric(df['رقم الباحث'], errors='coerce').dropna().astype(int).unique()
|
| 92 |
-
all_ids.sort()
|
| 93 |
-
researcher_order = [f"باحث رقم {i}" for i in all_ids]
|
| 94 |
-
|
| 95 |
-
for idx, researcher in enumerate(researcher_order, start=1):
|
| 96 |
-
g = df[df['researcher'] == researcher].copy()
|
| 97 |
-
|
| 98 |
-
if g.empty or (g['lon'].isna().all() or g['lat'].isna().all()):
|
| 99 |
-
# صفحة فارغة للباحث اللي ما عنده إحداثيات
|
| 100 |
-
html_empty = f"""
|
| 101 |
-
<html lang='ar' dir='rtl'>
|
| 102 |
-
<head><meta charset='utf-8'/></head>
|
| 103 |
-
<body style='font-family:Arial;text-align:center;margin-top:50px'>
|
| 104 |
-
<h3>لا توجد بيانات جغرافية لهذا الباحث ({researcher})</h3>
|
| 105 |
-
<div style='margin-top:20px;color:#666;'>تصميم وإعداد نوف الناصر</div>
|
| 106 |
-
</body>
|
| 107 |
-
</html>
|
| 108 |
-
"""
|
| 109 |
-
with open(os.path.join(OUT_DIR, f"{idx:02d}.html"), "w", encoding="utf-8") as f:
|
| 110 |
-
f.write(html_empty)
|
| 111 |
-
pages.append((f"{idx:02d}", researcher))
|
| 112 |
-
continue
|
| 113 |
-
|
| 114 |
-
# مركز الخريطة
|
| 115 |
-
center_lat = g['lat'].mean(skipna=True)
|
| 116 |
-
center_lon = g['lon'].mean(skipna=True)
|
| 117 |
-
zoom = 15 if len(g) == 1 else 13
|
| 118 |
-
|
| 119 |
-
m = folium.Map(location=[center_lat, center_lon], zoom_start=zoom, control_scale=True)
|
| 120 |
-
folium.TileLayer('OpenStreetMap', name='خريطة الشارع').add_to(m)
|
| 121 |
-
esri_world_imagery().add_to(m)
|
| 122 |
-
LocateControl(auto_start=False, flyTo=True).add_to(m)
|
| 123 |
-
|
| 124 |
-
# العنوان
|
| 125 |
-
m.get_root().html.add_child(
|
| 126 |
-
folium.Element(f"<h3 style='direction:rtl;text-align:center;margin:10px 0'>{researcher}</h3>")
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
# النقاط
|
| 130 |
-
for _, r in g.iterrows():
|
| 131 |
-
if pd.isna(r['lat']) or pd.isna(r['lon']):
|
| 132 |
-
continue
|
| 133 |
-
link = f"https://www.google.com/maps?q={r['lat']},{r['lon']}"
|
| 134 |
-
html = f"""
|
| 135 |
-
<div style="direction:rtl">
|
| 136 |
-
<b>{r.get('est','-')}</b><br>
|
| 137 |
-
الباحث: {researcher}<br>
|
| 138 |
-
السجل التج��ري: {r.get('السجل التجاري','-')}<br>
|
| 139 |
-
المنطقة: {r.get('اسم المنطقة','-')}<br>
|
| 140 |
-
الحارة: {r.get('اسم الحارة','-')}<br>
|
| 141 |
-
<a href="{link}" target="_blank">فتح في خرائط جوجل</a>
|
| 142 |
-
</div>
|
| 143 |
-
"""
|
| 144 |
-
folium.Marker(
|
| 145 |
-
location=[r['lat'], r['lon']],
|
| 146 |
-
tooltip=r['est'],
|
| 147 |
-
popup=folium.Popup(html, max_width=250),
|
| 148 |
-
icon=folium.Icon(color="red", icon="info-sign")
|
| 149 |
-
).add_to(m)
|
| 150 |
-
|
| 151 |
-
folium.LayerControl(collapsed=False).add_to(m)
|
| 152 |
-
m.get_root().html.add_child(folium.Element(make_footer_html()))
|
| 153 |
-
|
| 154 |
-
fname = f"{idx:02d}.html"
|
| 155 |
-
m.save(os.path.join(OUT_DIR, fname))
|
| 156 |
-
pages.append((f"{idx:02d}", researcher))
|
| 157 |
-
|
| 158 |
-
print(f"✓ تم إنشاء {len(pages)} صفحة في المجلد: {OUT_DIR}")
|
| 159 |
-
|
| 160 |
-
# =======================
|
| 161 |
-
# 6) صفحة الفهرس
|
| 162 |
-
# =======================
|
| 163 |
-
list_items = ''.join([
|
| 164 |
-
f'<li><a href="{num}.html" target="_blank">{num} — {res}</a></li>'
|
| 165 |
-
for num, res in pages
|
| 166 |
-
])
|
| 167 |
-
|
| 168 |
-
index_html = f"""
|
| 169 |
-
<!DOCTYPE html>
|
| 170 |
-
<html lang="ar" dir="rtl">
|
| 171 |
-
<head>
|
| 172 |
-
<meta charset="utf-8"/>
|
| 173 |
-
<title>روابط الخرائط</title>
|
| 174 |
-
<style>
|
| 175 |
-
body {{ font-family: Arial, sans-serif; margin: 24px; }}
|
| 176 |
-
h1 {{ margin-bottom: 10px; }}
|
| 177 |
-
ul {{ line-height: 1.9; }}
|
| 178 |
-
a {{ color: #0b6efd; text-decoration: none; }}
|
| 179 |
-
a:hover {{ text-decoration: underline; }}
|
| 180 |
-
.footer {{ margin-top: 28px; color:#666; }}
|
| 181 |
-
</style>
|
| 182 |
-
</head>
|
| 183 |
-
<body>
|
| 184 |
-
<h1>اختر صفحة الباحث</h1>
|
| 185 |
-
<ul>{list_items}</ul>
|
| 186 |
-
<div class="footer">تصميم وإعداد نوف الناصر</div>
|
| 187 |
-
</body>
|
| 188 |
-
</html>
|
| 189 |
-
"""
|
| 190 |
-
with open(os.path.join(OUT_DIR, "index.html"), "w", encoding="utf-8") as f:
|
| 191 |
-
f.write(index_html)
|
| 192 |
-
|
| 193 |
-
# =======================
|
| 194 |
-
# 7) ضغط الصفحات وتنزيلها
|
| 195 |
-
# =======================
|
| 196 |
-
zip_name = "خرائط_الباحثين.zip"
|
| 197 |
-
with zipfile.ZipFile(zip_name, "w", compression=zipfile.ZIP_DEFLATED) as z:
|
| 198 |
-
for fn in os.listdir(OUT_DIR):
|
| 199 |
-
z.write(os.path.join(OUT_DIR, fn), arcname=fn)
|
| 200 |
-
|
| 201 |
-
print(f"✓ تم إنشاء الملف المضغوط: {zip_name}")
|
| 202 |
-
files.download(zip_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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