Skip to content

Commit c2a9d76

Browse files
committed
adding speech recognition news
1 parent 102454a commit c2a9d76

File tree

3 files changed

+218
-0
lines changed

3 files changed

+218
-0
lines changed

speech_recognition_news/newsapi.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
import requests
3+
import json
4+
from dotenv import load_dotenv, find_dotenv
5+
from newspaper import Article
6+
from newspaper import Config
7+
from datetime import datetime
8+
from datetime import datetime
9+
10+
news_information = dict()
11+
12+
failed_port_connection = []
13+
14+
now = datetime.now()
15+
todays_date = now.strftime("%b %d, %Y")
16+
17+
18+
def get_top_news(news_information, todays_date):
19+
load_dotenv(find_dotenv(r"path to environmental variable"))
20+
news_api_key = os.getenv("news_api")
21+
params = (
22+
('country', 'us'),
23+
('apiKey', f'{news_api_key}'),
24+
)
25+
response = requests.get(
26+
"""https://newsapi.org/v2/top-headlines""",
27+
params=params)
28+
news_articles = response.json()['articles']
29+
for i in news_articles:
30+
user_agent = """Mozilla/5.0 (Macintosh;
31+
Intel Mac OS X 10.15; rv:78.0)
32+
Gecko/20100101 Firefox/78.0"""
33+
config = Config()
34+
config.browser_user_agent = user_agent
35+
config.request_timeout = 10
36+
article = Article(i['url'], config=config)
37+
print(i["url"])
38+
article.download()
39+
article.parse()
40+
article.nlp()
41+
summary = article.summary
42+
news_information[i["source"]["name"]] = {
43+
"""title": i["title"],
44+
"summary":summary, "url":i["url"],
45+
"date":f"{todays_date}"""
46+
}
47+
48+
49+
def json_file(news_information, todays_date):
50+
json_file = json.dumps(news_information, indent=4)
51+
with open(f"news_summary/news_summary {todays_date}.txt", "w") as outfile:
52+
outfile.write(json_file)
53+
outfile.close()
54+
55+
56+

speech_recognition_news/readme.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-to execute the script, the dotenv and newspaper3 package will need to be downloaded. Documentation can be found below.
2+
newspaper3: https://newspaper.readthedocs.io/en/latest/
3+
dotenv: https://pypi.org/project/python-dotenv/
4+
From there, you will need to go to https://newsapi.org/ and create an account and get the api key". Documentation for this can be found per below.
5+
Getting Started: https://newsapi.org/docs/get-started#search
6+
Python: https://newsapi.org/docs/client-libraries/python
7+
8+
Once you have the required packages, execute the scipt and it should pull the latest news articles, summarize them and put it into a json format under the folder "news_summary".
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
adal==1.2.1
2+
aiofiles==0.6.0
3+
aiohttp==3.7.4.post0
4+
aiohttp-socks==0.6.0
5+
aioredis==2.0.0
6+
aiosqlite==0.17.0
7+
appdirs==1.4.4
8+
arrow==1.2.0
9+
async-timeout==3.0.1
10+
attrs==21.2.0
11+
Babel==2.9.1
12+
backports.entry-points-selectable==1.1.0
13+
beautifulsoup4==4.10.0
14+
bitstring==3.1.9
15+
bleach==4.1.0
16+
botbuilder-core @ https://github.com/opsdroid/wheels-for-teams-connector/releases/download/4.11.0/botbuilder_core-4.11.0-py3-none-any.whl
17+
botbuilder-schema==4.11.0
18+
botframework-connector @ https://github.com/opsdroid/wheels-for-teams-connector/releases/download/4.11.0/botframework_connector-4.11.0-py2.py3-none-any.whl
19+
cachetools==4.2.4
20+
certifi==2021.5.30
21+
cffi==1.14.6
22+
cfgv==3.3.1
23+
chardet==4.0.0
24+
charset-normalizer==2.0.6
25+
click==8.0.1
26+
colorama==0.4.4
27+
cryptography==35.0.0
28+
cssselect==1.1.0
29+
defusedxml==0.7.1
30+
dialogflow==1.1.1
31+
distlib==0.3.3
32+
docopt==0.6.2
33+
emoji==1.6.0
34+
entrypoints==0.3
35+
feedfinder2==0.0.4
36+
feedparser==6.0.8
37+
filelock==3.3.0
38+
Flask==2.0.1
39+
future==0.18.2
40+
get-video-properties==0.1.1
41+
google-api-core==1.31.3
42+
google-auth==1.35.0
43+
googleapis-common-protos==1.53.0
44+
grpcio==1.41.0
45+
h11==0.12.0
46+
h2==4.1.0
47+
hpack==4.0.0
48+
hyperframe==6.0.1
49+
ibm-cloud-sdk-core==1.7.3
50+
ibm-watson==5.0.2
51+
identify==2.3.0
52+
idna==2.10
53+
ipython-genutils==0.2.0
54+
isodate==0.6.0
55+
itsdangerous==2.0.1
56+
jieba3k==0.35.1
57+
Jinja2==3.0.1
58+
joblib==1.0.1
59+
jsonpickle==1.4.2
60+
jsonschema==3.2.0
61+
jupyter-client==7.0.6
62+
jupyter-core==4.8.1
63+
jupyterlab-pygments==0.1.2
64+
Logbook==1.5.3
65+
lxml==4.6.3
66+
MarkupSafe==2.0.1
67+
matrix-nio==0.18.7
68+
mattermostdriver==7.3.1
69+
mistune==0.8.4
70+
motor==2.5.1
71+
msal==1.2.0
72+
msrest==0.6.10
73+
multidict==5.2.0
74+
multitasking==0.0.9
75+
nbclient==0.5.4
76+
nbconvert==6.2.0
77+
nbformat==5.1.3
78+
nest-asyncio==1.5.1
79+
newsapi-python==0.2.6
80+
newspaper3k==0.2.8
81+
nltk==3.6.3
82+
nodeenv==1.6.0
83+
numpy==1.21.2
84+
oauthlib==3.1.1
85+
-e git+https://github.com/opsdroid/opsdroid.git@bce356e7dcf7c4c49038a388748eed7ff6310d7a#egg=opsdroid
86+
opsdroid-get-image-size==0.2.2
87+
packaging==21.0
88+
pandas==1.3.3
89+
pandocfilters==1.5.0
90+
parse==1.19.0
91+
Pillow==8.4.0
92+
pipreqs==0.4.10
93+
platformdirs==2.4.0
94+
pluggy==1.0.0
95+
praw==7.4.0
96+
prawcore==2.3.0
97+
pre-commit==2.15.0
98+
protobuf==3.17.3
99+
puremagic==1.11
100+
py==1.10.0
101+
pyasn1==0.4.8
102+
pyasn1-modules==0.2.8
103+
pycparser==2.20
104+
pycron==3.0.0
105+
pycryptodome==3.11.0
106+
Pygments==2.10.0
107+
PyJWT==1.7.1
108+
pymongo==3.12.0
109+
pyparsing==2.4.7
110+
pyrsistent==0.18.0
111+
python-dateutil==2.8.2
112+
python-dotenv==0.19.0
113+
python-socks==1.2.4
114+
pytz==2021.1
115+
pywin32==301
116+
PyYAML==5.4.1
117+
pyzmq==22.3.0
118+
regex==2021.9.30
119+
requests==2.25.1
120+
requests-file==1.5.1
121+
requests-oauthlib==1.3.0
122+
requests-toolbelt==0.9.1
123+
rsa==4.7.2
124+
sgmllib3k==1.0.0
125+
six==1.16.0
126+
slack-sdk==3.11.2
127+
soupsieve==2.2.1
128+
tailer==0.4.1
129+
testpath==0.5.0
130+
tinysegmenter==0.3
131+
tldextract==3.1.2
132+
toml==0.10.2
133+
tornado==6.1
134+
tox==3.24.4
135+
tqdm==4.62.3
136+
traitlets==5.1.0
137+
tweepy==4.0.0
138+
typing-extensions==3.10.0.2
139+
unpaddedbase64==2.1.0
140+
update-checker==0.18.0
141+
urllib3==1.26.7
142+
vaderSentiment==3.3.2
143+
virtualenv==20.8.1
144+
voluptuous==0.12.2
145+
watchgod==0.7
146+
webencodings==0.5.1
147+
webexteamssdk==1.6
148+
websocket-client==0.48.0
149+
websockets==10.0
150+
Werkzeug==2.0.1
151+
wrapt==1.13.1
152+
yarg==0.1.9
153+
yarl==1.7.0
154+
yfinance==0.1.63

0 commit comments

Comments
 (0)