joermd commited on
Commit
720c5af
·
verified ·
1 Parent(s): b6ed99e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -153
app.py CHANGED
@@ -1,180 +1,81 @@
1
  import gradio as gr
2
- import whois
3
  import requests
4
  from urllib.parse import urlparse
 
5
 
6
- def check_website(url):
 
7
  """
8
- Check website details and return information, tips, and traffic estimates
9
  """
 
 
 
 
 
 
 
10
  try:
11
- # Get basic URL info
12
  response = requests.get(url, timeout=10)
13
  response.raise_for_status()
14
-
15
- domain = urlparse(url).netloc
16
- domain_info = whois.whois(domain)
 
17
 
18
- # Gather website information
19
- info = {
20
- 'رابط': url,
21
- 'بروتوكول': urlparse(url).scheme,
22
- 'النطاق': domain,
23
- 'رمز الحالة': response.status_code,
24
- 'حجم المحتوى (بايت)': len(response.content),
25
- 'نوع المحتوى': response.headers.get('Content-Type', 'غير متوفر'),
26
- 'تاريخ الاستجابة': response.headers.get('Date', 'غير متوفر'),
27
- 'مسجل النطاق': domain_info.get('registrar', 'غير متوفر'),
28
- 'تاريخ تسجيل النطاق': str(domain_info.get('creation_date', 'غير متوفر')),
29
- 'تاريخ انتهاء النطاق': str(domain_info.get('expiration_date', 'غير متوفر'))
30
- }
31
 
32
- # Generate tips based on status code
33
- tips = []
34
- if response.status_code == 200:
35
- tips.append("- الموقع يعمل بشكل جيد. تأكد من تحسين سرعة التحميل وتجربة المستخدم.")
36
- elif response.status_code == 404:
37
- tips.append("- الصفحة غير موجودة. تأكد من تحديث الروابط أو إنشاء صفحة 404 مخصصة.")
38
- elif response.status_code >= 500:
39
- tips.append("- خطأ في الخادم. تحقق من تكوين الخادم وتأكد من عدم وجود مشاكل في البرمجة.")
40
 
41
- # Generate traffic estimates
42
- traffic_estimate = []
43
- if 'example.com' in url:
44
- traffic_estimate.append("- الموقع يستخدم مثالاً، لذا تقدير الزيارات غير ممكن.")
45
- else:
46
- if 'edu' in domain:
47
- traffic_estimate.append("- المواقع التعليمية غالباً ما يكون لديها حركة مرور معتدلة إلى مرتفعة.")
48
- else:
49
- traffic_estimate.append("- تقدير عدد الزيارات غير متاح بدون أدوات تحليل متقدمة.")
50
-
51
- # Format information for display
52
- info_str = "\n".join([f"{k}: {v}" for k, v in info.items()])
53
- tips_str = "\n".join(tips)
54
- traffic_str = "\n".join(traffic_estimate)
55
-
56
- return info_str, tips_str, traffic_str
57
 
58
  except requests.RequestException as e:
59
- error_msg = f'خطأ في الوصول إلى الرابط: {str(e)}'
60
- return error_msg, error_msg, error_msg
61
- except Exception as e:
62
- error_msg = f'حدث خطأ أثناء جمع المعلومات: {str(e)}'
63
- return error_msg, error_msg, error_msg
64
 
65
- # Custom CSS for the interface
66
- custom_css = """
67
- @import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');
68
- :root {
69
- --speedy-primary: #8B4513;
70
- --speedy-dark: #5C2C0B;
71
- --speedy-light: #F5E6DB;
72
- --speedy-accent: #D2691E;
73
- --speedy-bg: #FDF9F6;
74
- --speedy-text: #3E2723;
75
- --speedy-border: #DEB887;
76
- }
77
- .gradio-container {
78
- font-family: 'Cairo', sans-serif !important;
79
- background-color: var(--speedy-bg) !important;
80
- margin: 0 auto;
81
- max-width: 900px !important;
82
- padding: 2rem !important;
83
- }
84
- .main-header {
85
- text-align: center;
86
- color: var(--speedy-primary);
87
- font-size: 2.5em;
88
- margin-bottom: 1rem;
89
- }
90
- .sub-header {
91
- text-align: center;
92
- color: var(--speedy-accent);
93
- font-size: 1.2em;
94
- margin-bottom: 2rem;
95
- }
96
- .gradio-button {
97
- background: linear-gradient(135deg, #8B4513 0%, #5C2C0B 100%) !important;
98
- color: white !important;
99
- border: none !important;
100
- border-radius: 12px !important;
101
- padding: 0.8em 1.5em !important;
102
- font-weight: 600 !important;
103
- transition: transform 0.3s ease, box-shadow 0.3s ease !important;
104
- }
105
- .gradio-button:hover {
106
- transform: translateY(-2px) !important;
107
- box-shadow: 0 6px 12px rgba(92, 44, 11, 0.3) !important;
108
- }
109
- .gradio-textbox {
110
- border: 2px solid var(--speedy-border) !important;
111
- border-radius: 12px !important;
112
- padding: 0.8em !important;
113
- }
114
- .gradio-textbox:focus {
115
- border-color: var(--speedy-primary) !important;
116
- box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.2) !important;
117
- }
118
- .output-panel {
119
- background: white !important;
120
- border-radius: 16px !important;
121
- padding: 1.5rem !important;
122
- margin-top: 1rem !important;
123
- border: 1px solid var(--speedy-border) !important;
124
- transition: transform 0.3s ease, box-shadow 0.3s ease !important;
125
- }
126
- .output-panel:hover {
127
- transform: translateY(-3px) !important;
128
- box-shadow: 0 4px 6px rgba(139, 69, 19, 0.2) !important;
129
- }
130
- """
131
 
132
- # Create Gradio interface
133
- with gr.Blocks(css=custom_css) as demo:
134
- gr.HTML("""
135
- <div class="main-header" dir="rtl">سبيدي</div>
136
- <div class="sub-header" dir="rtl">فاحص المواقع السريع والذكي</div>
137
- """)
138
 
139
  with gr.Row():
140
- url_input = gr.Textbox(
141
- label="أدخل رابط الموقع",
142
- placeholder="https://example.com",
143
- rtl=True
144
- )
145
 
146
  with gr.Row():
147
- check_button = gr.Button("فحص سريع", variant="primary")
 
148
 
149
  with gr.Row():
150
- with gr.Column():
151
- info_output = gr.Textbox(
152
- label="معلومات الموقع",
153
- lines=10,
154
- interactive=False,
155
- rtl=True
156
- )
157
- with gr.Column():
158
- tips_output = gr.Textbox(
159
- label="نصائح تحسين الموقع",
160
- lines=4,
161
- interactive=False,
162
- rtl=True
163
- )
164
- with gr.Column():
165
- traffic_output = gr.Textbox(
166
- label="تحليل الزيارات",
167
- lines=4,
168
- interactive=False,
169
- rtl=True
170
- )
171
 
172
- check_button.click(
173
- fn=check_website,
174
  inputs=[url_input],
175
- outputs=[info_output, tips_output, traffic_output]
176
  )
177
 
178
- # Launch the app
179
  if __name__ == "__main__":
180
- demo.launch()
 
1
  import gradio as gr
 
2
  import requests
3
  from urllib.parse import urlparse
4
+ from bs4 import BeautifulSoup
5
 
6
+
7
+ def analyze_website(url):
8
  """
9
+ تحليل شامل للموقع.
10
  """
11
+ results = {
12
+ "أداء الموقع": "",
13
+ "تحليل الترافيك": "",
14
+ "تحليل الأمان": "",
15
+ "تحليل تجربة المستخدم": ""
16
+ }
17
+
18
  try:
19
+ # 1. تحليل الأداء
20
  response = requests.get(url, timeout=10)
21
  response.raise_for_status()
22
+ load_time = response.elapsed.total_seconds()
23
+ results["أداء الموقع"] = f"- وقت الاستجابة: {load_time} ثانية.\n" \
24
+ f"- حالة الموقع: {response.status_code}\n" \
25
+ f"- حجم المحتوى: {len(response.content)} بايت."
26
 
27
+ # 2. تحليل الترافيك
28
+ parsed_url = urlparse(url)
29
+ domain = parsed_url.netloc
30
+ alexa_url = f"https://www.alexa.com/siteinfo/{domain}"
31
+ results["تحليل الترافيك"] = f"- تحقق من ترتيب أليكسا هنا: {alexa_url}"
 
 
 
 
 
 
 
 
32
 
33
+ # 3. تحليل الأمان
34
+ ssl_labs_url = f"https://www.ssllabs.com/ssltest/analyze.html?d={domain}"
35
+ sucuri_url = f"https://sitecheck.sucuri.net/results/{domain}"
36
+ results["تحليل الأمان"] = f"- تحقق من شهادة SSL: {ssl_labs_url}\n" \
37
+ f"- تحقق من الأمان مع Sucuri: {sucuri_url}"
 
 
 
38
 
39
+ # 4. تحليل تجربة المستخدم
40
+ soup = BeautifulSoup(response.text, "html.parser")
41
+ title = soup.title.string if soup.title else "غير متوفر"
42
+ meta_desc = soup.find("meta", attrs={"name": "description"})
43
+ description = meta_desc["content"] if meta_desc else "غير متوفرة"
44
+ results["تحليل تجربة المستخدم"] = f"- عنوان الصفحة: {title}\n" \
45
+ f"- وصف الصفحة: {description}\n" \
46
+ f"- عدد الروابط الداخلية: {len(soup.find_all('a'))}"
 
 
 
 
 
 
 
 
47
 
48
  except requests.RequestException as e:
49
+ error_msg = f"حدث خطأ أثناء الوصول إلى الموقع: {str(e)}"
50
+ return {"أداء الموقع": error_msg, "تحليل الترافيك": error_msg,
51
+ "تحليل الأمان": error_msg, "تحليل تجربة المستخدم": error_msg}
52
+
53
+ return results
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
+ # تصميم الواجهة باستخدام Gradio
57
+ with gr.Blocks() as app:
58
+ gr.Markdown("<h1 style='text-align: center; color: #8B4513;'>محلل المواقع الذكي</h1>")
59
+ gr.Markdown("<p style='text-align: center;'>أدخل رابط الموقع لتحليله من حيث الأداء، الأمان، الترافيك، وتجربة المستخدم.</p>")
 
 
60
 
61
  with gr.Row():
62
+ url_input = gr.Textbox(label="رابط الموقع", placeholder="https://example.com", lines=1)
63
+ analyze_button = gr.Button("تحليل الموقع")
 
 
 
64
 
65
  with gr.Row():
66
+ performance_output = gr.Textbox(label="أداء الموقع", lines=4, interactive=False)
67
+ traffic_output = gr.Textbox(label="تحليل الترافيك", lines=2, interactive=False)
68
 
69
  with gr.Row():
70
+ security_output = gr.Textbox(label="تحليل الأمان", lines=3, interactive=False)
71
+ ux_output = gr.Textbox(label="تحليل تجربة المستخدم", lines=4, interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
+ analyze_button.click(
74
+ analyze_website,
75
  inputs=[url_input],
76
+ outputs=[performance_output, traffic_output, security_output, ux_output]
77
  )
78
 
79
+ # إطلاق التطبيق
80
  if __name__ == "__main__":
81
+ app.launch()