joermd commited on
Commit
8d0daad
·
verified ·
1 Parent(s): fd4db94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -49
app.py CHANGED
@@ -17,7 +17,6 @@ import requests_html
17
  from selenium import webdriver
18
  from selenium.webdriver.chrome.options import Options
19
  from googleapiclient.discovery import build
20
- import semrush_api
21
  import speedtest
22
  import dns.resolver
23
  import tld
@@ -31,37 +30,37 @@ st.set_page_config(page_title="محلل المواقع الشامل", layout="wi
31
  # تصميم CSS محسن
32
  st.markdown("""
33
  <style>
34
- .main {
35
- background-color: #f8f9fa;
36
- }
37
- .stButton>button {
38
- background-color: #0066cc;
39
- color: white;
40
- border-radius: 5px;
41
- padding: 10px 24px;
42
- font-weight: bold;
43
- }
44
- .metric-card {
45
- background-color: white;
46
- padding: 20px;
47
- border-radius: 10px;
48
- box-shadow: 0 4px 6px rgba(0,0,0,0.1);
49
- margin: 10px 0;
50
- }
51
- .highlight {
52
- background-color: #e9ecef;
53
- padding: 10px;
54
- border-radius: 5px;
55
- margin: 5px 0;
56
- }
57
- .warning {
58
- color: #dc3545;
59
- font-weight: bold;
60
- }
61
- .success {
62
- color: #28a745;
63
- font-weight: bold;
64
- }
65
  </style>
66
  """, unsafe_allow_html=True)
67
 
@@ -72,14 +71,63 @@ st.markdown("---")
72
  # إدخال رابط الموقع
73
  url = st.text_input("أدخل رابط الموقع للتحليل", "https://example.com")
74
 
75
- # API Keys (في الواقع يجب وضعها في متغيرات بيئية)
76
  GOOGLE_API_KEY = "YOUR_GOOGLE_API_KEY"
77
- SEMRUSH_API_KEY = "YOUR_SEMRUSH_API_KEY"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  async def get_website_traffic(domain):
80
- """تقدير حركة المرور للموقع باستخدام SemRush API"""
81
  try:
82
- # هذه مجرد محاكاة - في الواقع ستستخدم API حقيقي
83
  monthly_visits = np.random.randint(10000, 1000000)
84
  bounce_rate = np.random.uniform(30, 70)
85
  avg_visit_duration = np.random.uniform(60, 300)
@@ -94,7 +142,6 @@ async def get_website_traffic(domain):
94
  async def check_google_ranking(domain):
95
  """فحص ترتيب الموقع في جوجل"""
96
  try:
97
- # محاكاة نتائج الترتيب - في الواقع ستستخدم Google Search Console API
98
  keywords = ["keyword1", "keyword2", "keyword3"]
99
  rankings = {k: np.random.randint(1, 100) for k in keywords}
100
  return rankings
@@ -131,17 +178,10 @@ async def get_website_size(url):
131
 
132
  def estimate_website_cost(traffic_data, speed_data, security_info):
133
  """تقدير التكلفة التقريبية للموقع"""
134
- base_cost = 1000 # تكلفة أساسية
135
-
136
- # زيادة التكلفة بناءً على حركة المرور
137
  traffic_cost = (traffic_data['monthly_visits'] / 10000) * 100
138
-
139
- # زيادة التكلفة بناءً على الأداء
140
  performance_cost = speed_data['performance_score'] * 5
141
-
142
- # زيادة التكلفة بناءً على الأمان
143
  security_cost = 500 if security_info['secure'] else 0
144
-
145
  total_cost = base_cost + traffic_cost + performance_cost + security_cost
146
  return round(total_cost, 2)
147
 
@@ -158,10 +198,15 @@ if st.button("تحليل الموقع"):
158
 
159
  # تحليل حركة المرور والسرعة والحجم
160
  domain = urlparse(url).netloc
161
- traffic_data = await get_website_traffic(domain)
162
- speed_data = await analyze_website_speed(url)
163
- website_size = await get_website_size(url)
164
- rankings = await check_google_ranking(domain)
 
 
 
 
 
165
 
166
  # تقدير التكلفة
167
  estimated_cost = estimate_website_cost(traffic_data, speed_data, security_info)
 
17
  from selenium import webdriver
18
  from selenium.webdriver.chrome.options import Options
19
  from googleapiclient.discovery import build
 
20
  import speedtest
21
  import dns.resolver
22
  import tld
 
30
  # تصميم CSS محسن
31
  st.markdown("""
32
  <style>
33
+ .main {
34
+ background-color: #f8f9fa;
35
+ }
36
+ .stButton>button {
37
+ background-color: #0066cc;
38
+ color: white;
39
+ border-radius: 5px;
40
+ padding: 10px 24px;
41
+ font-weight: bold;
42
+ }
43
+ .metric-card {
44
+ background-color: white;
45
+ padding: 20px;
46
+ border-radius: 10px;
47
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
48
+ margin: 10px 0;
49
+ }
50
+ .highlight {
51
+ background-color: #e9ecef;
52
+ padding: 10px;
53
+ border-radius: 5px;
54
+ margin: 5px 0;
55
+ }
56
+ .warning {
57
+ color: #dc3545;
58
+ font-weight: bold;
59
+ }
60
+ .success {
61
+ color: #28a745;
62
+ font-weight: bold;
63
+ }
64
  </style>
65
  """, unsafe_allow_html=True)
66
 
 
71
  # إدخال رابط الموقع
72
  url = st.text_input("أدخل رابط الموقع للتحليل", "https://example.com")
73
 
74
+ # API Keys
75
  GOOGLE_API_KEY = "YOUR_GOOGLE_API_KEY"
76
+
77
+ def analyze_security(url):
78
+ """تحليل أمان الموقع"""
79
+ try:
80
+ parsed_url = urlparse(url)
81
+ domain = parsed_url.netloc
82
+
83
+ # فحص SSL
84
+ ssl_context = ssl.create_default_context()
85
+ with socket.create_connection((domain, 443)) as sock:
86
+ with ssl_context.wrap_socket(sock, server_hostname=domain) as ssock:
87
+ cert = ssock.getpeercert()
88
+ ssl_valid = True
89
+
90
+ # فحص HTTPS
91
+ is_https = parsed_url.scheme == "https"
92
+
93
+ return {
94
+ "secure": ssl_valid and is_https,
95
+ "ssl_valid": ssl_valid,
96
+ "https_enabled": is_https,
97
+ "certificate": cert if ssl_valid else None
98
+ }
99
+ except Exception as e:
100
+ return {
101
+ "secure": False,
102
+ "ssl_valid": False,
103
+ "https_enabled": False,
104
+ "certificate": None
105
+ }
106
+
107
+ def analyze_seo(soup, url):
108
+ """تحليل SEO للموقع"""
109
+ title = soup.find('title')
110
+ meta_description = soup.find('meta', {'name': 'description'})
111
+ h1_tags = soup.find_all('h1')
112
+
113
+ # حساب درجة SEO بسيطة
114
+ seo_score = 0
115
+ if title: seo_score += 20
116
+ if meta_description: seo_score += 20
117
+ if len(h1_tags) > 0: seo_score += 20
118
+ if url.startswith('https'): seo_score += 20
119
+ if len(url) < 100: seo_score += 20
120
+
121
+ return {
122
+ "title": title.text if title else None,
123
+ "meta_description": meta_description.get('content') if meta_description else None,
124
+ "h1_count": len(h1_tags),
125
+ "seo_score": seo_score
126
+ }
127
 
128
  async def get_website_traffic(domain):
129
+ """تقدير حركة المرور للموقع"""
130
  try:
 
131
  monthly_visits = np.random.randint(10000, 1000000)
132
  bounce_rate = np.random.uniform(30, 70)
133
  avg_visit_duration = np.random.uniform(60, 300)
 
142
  async def check_google_ranking(domain):
143
  """فحص ترتيب الموقع في جوجل"""
144
  try:
 
145
  keywords = ["keyword1", "keyword2", "keyword3"]
146
  rankings = {k: np.random.randint(1, 100) for k in keywords}
147
  return rankings
 
178
 
179
  def estimate_website_cost(traffic_data, speed_data, security_info):
180
  """تقدير التكلفة التقريبية للموقع"""
181
+ base_cost = 1000
 
 
182
  traffic_cost = (traffic_data['monthly_visits'] / 10000) * 100
 
 
183
  performance_cost = speed_data['performance_score'] * 5
 
 
184
  security_cost = 500 if security_info['secure'] else 0
 
185
  total_cost = base_cost + traffic_cost + performance_cost + security_cost
186
  return round(total_cost, 2)
187
 
 
198
 
199
  # تحليل حركة المرور والسرعة والحجم
200
  domain = urlparse(url).netloc
201
+
202
+ # Create event loop and run async functions
203
+ loop = asyncio.new_event_loop()
204
+ asyncio.set_event_loop(loop)
205
+ traffic_data = loop.run_until_complete(get_website_traffic(domain))
206
+ speed_data = loop.run_until_complete(analyze_website_speed(url))
207
+ website_size = loop.run_until_complete(get_website_size(url))
208
+ rankings = loop.run_until_complete(check_google_ranking(domain))
209
+ loop.close()
210
 
211
  # تقدير التكلفة
212
  estimated_cost = estimate_website_cost(traffic_data, speed_data, security_info)