adpro commited on
Commit
1083661
·
verified ·
1 Parent(s): 0f94dc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -16
app.py CHANGED
@@ -10,23 +10,31 @@ from urllib.parse import parse_qs
10
  def run_lora(prompt,site,start,end):
11
  url = f"https://www.googleapis.com/customsearch/v1?q=site:{site}+{prompt}&cx={SEARCH_ENGINE_ID}&key=AIzaSyCnsm9J-9zkLTKLHrt7UiMXNuOU5ddas08&sort=date:r:{start}:{end}"
12
 
13
- response = requests.get(url)
14
- results = response.json()
15
-
16
- # Trích xuất các kết quả tìm kiếm
17
- search_results = []
18
- if "items" in results:
19
- for item in results['items']:
20
- title = item['title']
21
- link = item['link']
22
- snippet = item.get('snippet', '')
23
- search_results.append({
24
- 'title': title,
25
- 'link': link,
26
- 'snippet': snippet
27
- })
28
 
29
- return search_results
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  def extract_href(href):
32
  url = urlparse(href)
 
10
  def run_lora(prompt,site,start,end):
11
  url = f"https://www.googleapis.com/customsearch/v1?q=site:{site}+{prompt}&cx={SEARCH_ENGINE_ID}&key=AIzaSyCnsm9J-9zkLTKLHrt7UiMXNuOU5ddas08&sort=date:r:{start}:{end}"
12
 
13
+ # API key từ NewsAPI
14
+ api_key = 'your_newsapi_key'
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ # URL API của NewsAPI
17
+ url = (f'https://newsapi.org/v2/everything?'
18
+ f'q={prompt}&'
19
+ f'domains={site}&'
20
+ f'from={start}&to={end}&'
21
+ f'sortBy=relevancy&'
22
+ f'apiKey={}'.format(api_key))
23
+
24
+ # Gửi yêu cầu GET tới NewsAPI
25
+ response = requests.get(url)
26
+ data = response.json()
27
+ links=""
28
+ if data["status"] == "ok":
29
+ for article in data["articles"]: # Lấy 5 bài báo đầu tiên
30
+ print(f"Title: {article['title']}")
31
+ print(f"Link: {article['url']}")
32
+ print(f"Published At: {article['publishedAt']}")
33
+ print('-' * 80)
34
+ links+="/n"+{article['url']}
35
+ else:
36
+ print("Error fetching data.")
37
+ return links
38
 
39
  def extract_href(href):
40
  url = urlparse(href)