-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews.py
100 lines (68 loc) · 2.29 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import tkinter as tk
import nltk
from textblob import TextBlob
from newspaper import Article
import pyttsx3
nltk.download('punkt')
def summarize():
url =utext.get('1.0', "end").strip()
article =Article(url)
article.download()
article.parse()
article.nlp()
title.config(state='normal')
summary.config(state='normal')
sentiment.config(state='normal')
title.delete('1.0', 'end')
title.insert('1.0', article.title)
summary.delete('1.0', 'end')
summary.insert('1.0', article.summary)
analysis = TextBlob(article.text)
sentiment.delete('1.0','end')
sentiment.insert('1.0',f'Polarity:{analysis.polarity}, Sentiment: {"postive" if analysis.polarity > 0 else "negative" if analysis.polarity < 0 else " neutral"}')
title.config(state='disabled')
summary.config(state='disabled')
sentiment.config(state='disabled')
summary.delete('1.0', 'end')
summary.insert('1.0', article.summary)
print(f'Title:{article.title}')
print(f'Authors:{article.authors}')
print(f'Publish Date:{article.publish_date}')
print(f'Summary:{article.summary}')
def audio_summary():
url =utext.get('1.0', "end").strip()
article =Article(url)
article.download()
article.parse()
article.nlp()
mytext=article.summary
engine = pyttsx3.init()
engine.say(mytext)
engine.runAndWait()
root=tk.Tk()
root.title("News Summarize")
root.geometry('600x600')
ulabel = tk.Label(root, text="URL")
ulabel.pack()
utext =tk.Text(root, height=1, width=70)
utext.pack()
tlable=tk.Label(root,text="Title")
tlable.pack()
title=tk.Text(root, height=1, width=70)
title.config(state='disabled',bg='#dddddd')
title.pack()
slable=tk.Label(root,text="Summarize")
slable.pack()
summary=tk.Text(root, height=20, width=70)
summary.config(state='disabled',bg='#dddddd')
summary.pack()
selabel =tk.Label(root, text="Sentiment Analysis")
selabel.pack()
sentiment =tk.Text(root, height=1, width=70)
sentiment.config(state='disabled',bg='#dddddd')
sentiment.pack()
btn =tk.Button(root,text="Summarize",command=summarize)
btn.pack()
btn =tk.Button(root,text="Audio",command=audio_summary)
btn.pack()
root.mainloop()