-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews.py
executable file
·52 lines (45 loc) · 1.14 KB
/
news.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python3
from newspaper import Article
from newspaper import Config
import shorten
import nltk
def article_image(url):
config = Config()
config.browser_user_agent = "Mozilla/5.0"
article = Article(url)
try:
article.download()
except Exception as e:
print(f'unable to download article, {e}')
return None
article.parse()
if article.top_image is not None:
return f'\n\n'
#print(article.summary)
#print(article.title)
#print(article.text)
return None
def article(url, rapidkey):
config = Config()
config.browser_user_agent = "Mozilla/5.0"
art = Article(url)
try:
art.download()
except Exception as e:
print(f'unable to download article, {e}')
return None
art.parse()
nltk.download('punkt')
art.nlp()
t = ''
if art.top_image is not None:
t = f'\n\n'
if art.title is not None:
t += f'*{art.title}*\n\n'
if (art.summary is not None) and (len(art.summary) > 0):
t += f'{art.summary} 🖊️️🤖\n\n'
elif art.text is not None:
t += shorten.shorten_text(art.text, rapidkey)
if len(t) > 0:
return t
return None