So I finally made my content aggregator on my bucket list with python and it was a fun project, I must say.
So what does it do anyway?
Well for starters it fetches me the
- News around my country
- Medium articles on programming
- Articles on python
- ......and finally some developer news
- oh oh oh and stock exchange news of my favourite stocks
I finally get it emailed to my myself with mutt.
Here's how it looks!
The Python News
The Daily Fresh News
Getting Started on how did I do it?
Well there are a bit of pip packages that are needed to be installed first hand
astroid==2.3.3 | |
certifi==2019.9.11 | |
chardet==3.0.4 | |
dateutils==0.6.7 | |
feedparser==5.2.1 | |
idna==2.8 | |
isort==4.3.21 | |
lazy-object-proxy==1.4.3 | |
mccabe==0.6.1 | |
newsapi==0.1.1 | |
nsetools==1.0.10 | |
praw==6.4.0 | |
prawcore==1.0.1 | |
pylint==2.4.4 | |
python-dateutil==2.8.1 | |
pytz==2019.3 | |
requests==2.22.0 | |
six==1.13.0 | |
typed-ast==1.4.0 | |
update-checker==0.16 | |
urllib3==1.25.7 | |
websocket-client==0.56.0 | |
wrapt==1.11.2 |
Then you finally code a bit.
The explanation stands in the comments, give it go!
import urllib, os, requests, datetime, subprocess | |
# reddit imports | |
import praw, pprint | |
# pip install feedparser | |
import feedparser | |
# stockexchange | |
from nsetools import Nse | |
# Place your CLIENT_ID & CLIENT_SECRET below | |
reddit = praw.Reddit(client_id='XXXXXXX', | |
client_secret='XXXXXXXXXXX', | |
grant_type_access='client_credentials', | |
user_agent='script/1.0') | |
# class Reddit: | |
# def TopNews(self): | |
# # Add your favorite NEWS subreddits in the argument as many as you'd like. | |
# for submission in reddit.subreddit('News+WorldNews+UpliftingNews+').top(limit=10): | |
# top_news = reddit.domain(submission).top('month') | |
# print(top_news) | |
""" | |
Each class contains functions which further calls | |
APIs from the neccesary packages and the rest is | |
self explanatory I suppose | |
""" | |
class News: | |
def Indian_News(self): | |
newsfeed = feedparser.parse( | |
"http://feeds.feedburner.com/ndtvnews-india-news" | |
) | |
print("Today's News: ") | |
for i in range(0, 20): | |
entry = newsfeed.entries[i] | |
print(entry.title) | |
print(entry.summary) | |
print("------News Link--------") | |
print(entry.link) | |
print("###########################################") | |
print('-------------------------------------------------------------------------------------------------------') | |
class Medium: | |
# https://github.com/thepracticaldev/dev.to/issues/28#issuecomment-325544385 | |
def medium_programming(self): | |
feed = feedparser.parse( | |
"https://medium.com/feed/tag/programming" | |
) | |
print("Programming Today: ") | |
for i in range(10): | |
entry = feed.entries[i] | |
print(entry.title) | |
print("URL: " + entry.link) | |
print("###########################################") | |
print('-------------------------------------------------------------------------------------------------------') | |
def medium_python(self): | |
feed_python = feedparser.parse( | |
"https://medium.com/feed/tag/python" | |
) | |
print("Python Today: ") | |
for i in range(10): | |
entry = feed_python.entries[i] | |
print(entry.title) | |
print("URL: " + entry.link) | |
print("###########################################") | |
print('-------------------------------------------------------------------------------------------------------') | |
def medium_developer(self): | |
feed_developer = feedparser.parse( | |
"https://medium.com/feed/tag/developer" | |
) | |
print("Developer News Today: ") | |
for i in range(5): | |
entry = feed_developer.entries[i] | |
print(entry.title) | |
print("URL: " + entry.link) | |
print("###########################################") | |
print('-------------------------------------------------------------------------------------------------------') | |
class StockExchange: | |
def nse_stock(self): | |
nse = Nse() | |
print("TOP GAINERS OF YESTERDAY") | |
pprint.pprint(nse.get_top_gainers()) | |
print("###########################################") | |
print("TOP LOSERS OF YESTERDAY") | |
pprint.pprint(nse.get_top_losers()) | |
print("###########################################") | |
print('-------------------------------------------------------------------------------------------------------') | |
# objects inititalization | |
# reddit_object = Reddit() | |
News_object = News() | |
Medium_object = Medium() | |
StockExchange_object = StockExchange() | |
if __name__ == "__main__": | |
# Functions call of each class | |
# reddit_object.TopNews() | |
News_object.Indian_News() | |
Medium_object.medium_python() | |
Medium_object.medium_programming() | |
Medium_object.medium_developer() | |
StockExchange_object.nse_stock() | |
Now how do you export the output our little script to the text file which in fact we would need for the body of our email
We write a shell script, AHA!!
Oh no wait please install mutt or any other cli email sender
`sudo apt-get install mutt`
Setting up mutt would make you wanna kill yourself, here you go
please don't die, we love you article, a very easy tutorial to setup mutt
cool and we're good to go
#!/usr/bin/env python3 | |
import subprocess, os | |
with open("/tmp/output.txt", "w+") as output: | |
subprocess.call(["python", "./script.py"], stdout=output); | |
os.system("mutt -s 'Surprise Motherf***er' you@email.com < /tmp/output.txt") |
yup that's it. the script's that small. oh.
Now just run setup this script at your cloud and send it to yourself before you wake up.
Top comments (5)
Looks great! A bit of formatting to spruce up the emails couldn't hurt, though.
Why, yes! I'm thinking of adding,
yet I am learning templating and sure would prettify the basic template of the email body.
thanks for the discuss!
And umm...the script can be written as its shown? Or should i alter it a bit?(win user)
Hey what if i dont use linux what would be the proper email client sender for windows?
raymond.cc/blog/sending-email-usin...
these are what I found on a quick search apparently.