AnesKAM commited on
Commit
ed10f86
·
verified ·
1 Parent(s): a8d98f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -176
app.py CHANGED
@@ -1,182 +1,16 @@
1
- # أضف هذا الكود إلى app.py لدمج Google CSE مع محركك الخاص
2
- from flask import Flask, request, render_template_string, jsonify
3
- import requests
4
- import json
5
 
6
- app = Flask(__name__)
7
-
8
- HTML_TEMPLATE = '''
9
- <!DOCTYPE html>
10
- <html dir="rtl">
11
- <head>
12
- <meta charset="UTF-8">
13
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
14
- <title>محرك بحث شامل - أخبار صور فيديوهات</title>
15
- <style>
16
- * { margin: 0; padding: 0; box-sizing: border-box; }
17
- body {
18
- font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
19
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
20
- min-height: 100vh;
21
- }
22
- .container { max-width: 1200px; margin: auto; padding: 20px; }
23
- .header {
24
- background: white;
25
- border-radius: 15px;
26
- padding: 30px;
27
- margin-bottom: 30px;
28
- box-shadow: 0 10px 30px rgba(0,0,0,0.2);
29
- text-align: center;
30
- }
31
- h1 { color: #333; margin-bottom: 10px; font-size: 2.5em; }
32
- .subtitle { color: #666; margin-bottom: 30px; }
33
- .search-form { display: flex; gap: 10px; flex-wrap: wrap; }
34
- .search-box {
35
- flex: 1;
36
- padding: 15px;
37
- border: 2px solid #ddd;
38
- border-radius: 10px;
39
- font-size: 16px;
40
- }
41
- .search-box:focus { outline: none; border-color: #667eea; }
42
- button {
43
- padding: 15px 30px;
44
- background: #667eea;
45
- color: white;
46
- border: none;
47
- border-radius: 10px;
48
- cursor: pointer;
49
- }
50
- .tabs {
51
- display: flex;
52
- gap: 10px;
53
- margin: 20px 0;
54
- justify-content: center;
55
- }
56
- .tab {
57
- padding: 10px 20px;
58
- background: #f0f0f0;
59
- border: none;
60
- border-radius: 10px;
61
- cursor: pointer;
62
- transition: all 0.3s;
63
- }
64
- .tab.active {
65
- background: #667eea;
66
- color: white;
67
- }
68
- .results-container {
69
- background: white;
70
- border-radius: 15px;
71
- padding: 20px;
72
- min-height: 400px;
73
- }
74
- .result {
75
- padding: 15px;
76
- border-bottom: 1px solid #eee;
77
- }
78
- .result-title {
79
- color: #1a0dab;
80
- text-decoration: none;
81
- font-size: 18px;
82
- font-weight: bold;
83
- }
84
- .result-url {
85
- color: #006621;
86
- font-size: 14px;
87
- }
88
- .footer { text-align: center; margin-top: 30px; color: white; }
89
- .loading { text-align: center; padding: 40px; color: #666; }
90
- </style>
91
- </head>
92
- <body>
93
- <div class="container">
94
- <div class="header">
95
- <h1>🔍 محرك البحث المتكامل</h1>
96
- <p class="subtitle">محرك خاص + Google CSE للحصول على أفضل النتائج</p>
97
-
98
- <form method="get" class="search-form">
99
- <input type="text" name="q" class="search-box" placeholder="ابحث عن أي شيء..." value="{{ query }}" autocomplete="off">
100
- <button type="submit">🔍 بحث</button>
101
- </form>
102
-
103
- <div class="tabs">
104
- <button class="tab {% if engine == 'hybrid' %}active{% endif %}" onclick="switchEngine('hybrid')">🚀 محرك هجين</button>
105
- <button class="tab {% if engine == 'custom' %}active{% endif %}" onclick="switchEngine('custom')">⚙️ محركي الخاص</button>
106
- <button class="tab {% if engine == 'google' %}active{% endif %}" onclick="switchEngine('google')">🔎 Google CSE</button>
107
- </div>
108
- </div>
109
-
110
- <div class="results-container">
111
- {% if query %}
112
- {% if engine == 'google' %}
113
- <!-- نتائج Google CSE -->
114
- <div class="gcse-searchresults-only"></div>
115
- {% else %}
116
- <!-- نتائج محركك الخاص -->
117
- {% for result in results %}
118
- <div class="result">
119
- <a href="{{ result.link }}" class="result-title" target="_blank">{{ result.title }}</a>
120
- <div class="result-url">{{ result.link }}</div>
121
- <div style="color: #545454;">{{ result.summary }}</div>
122
- <div style="color: #808080; font-size: 12px;">{{ result.source }} - {{ result.date }}</div>
123
- </div>
124
- {% endfor %}
125
-
126
- {% if results|length == 0 %}
127
- <div class="loading">❌ لا توجد نتائج في محركي الخاص. جرب محرك Google CSE</div>
128
- {% endif %}
129
- {% endif %}
130
- {% else %}
131
- <div class="loading">
132
- ✨ اكتب ما تبحث عنه في مربع البحث أعلاه<br>
133
- 💡 جرب: رياضة، تقنية، أخبار الجزائر
134
- </div>
135
- {% endif %}
136
- </div>
137
-
138
- <div class="footer">
139
- <p>🚀 محرك بحث هجين | خاص بك + Google CSE</p>
140
- </div>
141
- </div>
142
-
143
- <script>
144
- function switchEngine(engine) {
145
- const url = new URL(window.location.href);
146
- url.searchParams.set('engine', engine);
147
- window.location.href = url.toString();
148
- }
149
-
150
- // تحميل Google CSE فقط عند الحاجة
151
- {% if engine == 'google' and query %}
152
- var cx = '2342fc17cd34f4cba'; // ضع معرف Google CSE الخاص بك هنا
153
- var gcse = document.createElement('script');
154
- gcse.type = 'text/javascript';
155
- gcse.async = true;
156
- gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
157
- var s = document.getElementsByTagName('script')[0];
158
- s.parentNode.insertBefore(gcse, s);
159
- {% endif %}
160
- </script>
161
- </body>
162
- </html>
163
- '''
164
-
165
- # ... أضف دوال البحث الخاصة بك هنا (search_news, get_sample_news, إلخ)
166
 
167
  @app.route('/')
168
  def index():
169
- query = request.args.get('q', '')
170
- engine = request.args.get('engine', 'hybrid')
171
- results = []
172
-
173
- if query and engine in ['custom', 'hybrid']:
174
- results = search_news(query) # استخدام محركك الخاص
175
-
176
- return render_template_string(HTML_TEMPLATE,
177
- query=query,
178
- results=results,
179
- engine=engine)
180
 
181
  if __name__ == '__main__':
182
- app.run(host='0.0.0.0', port=7860, debug=True)
 
 
1
+ from flask import Flask, send_from_directory
2
+ import os
 
 
3
 
4
+ app = Flask(__name__, static_folder='.')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  @app.route('/')
7
  def index():
8
+ return send_from_directory('.', 'index.html')
9
+
10
+ @app.route('/<path:path>')
11
+ def static_files(path):
12
+ return send_from_directory('.', path)
 
 
 
 
 
 
13
 
14
  if __name__ == '__main__':
15
+ port = int(os.environ.get('PORT', 7860))
16
+ app.run(host='0.0.0.0', port=port, debug=False)