Although Steemit UI provides a feed feature which list posts from the authors you are following, Sometimes it is still too much information for you to read. Here I will show you how to write a Python script to generate a daily posts report for selected authors and send it to your email address automatically.
The library needed
In this script, we are using Steem Python. Please make sure you have installed it before trying the script.
The code
Here is the code to do the job:
import smtplib
from email.mime.text import MIMEText
from datetime import datetime
from steem.blog import Blog
from sys import argv
import traceback
if len(argv) !=3:
print ('Usage: python daily_summary.py MAX_NUMBER_OF_POSTS_TO_CHECK ACCOUNT_LIST')
exit()
max_daily_number_of_posts_to_check = int(argv[1])
users = argv[2].split(',')
steemit_url = 'https://steemit.com'
summary = ''
try:
for user in users:
summary += "User %s
" % user
summary += "------------------
"
posts = Blog(user)
for p in posts.take(max_daily_number_of_posts_to_check):
p_date = p['created']
today = datetime.today().date()
created_today = (p_date.date()==today)
if created_today == True:
summary += "%s
" % (steemit_url, p['url'], p['title'])
summary += " Category: %s
" % str(p['tags'][0])
summary += " Votes: %s
" % str(p['net_votes'])
summary += " Comments: %s
" % str(len(list(p.get_replies())))
summary += " Rewards: %s
" % str(p['pending_payout_value'])
summary += "
"
summary += "
"
username = 'YOUR_GMAIL_ADDRESS'
password = 'YOUR_GMAIL_PASSWORD'
toaddrs = 'YOUR_EMAIL'
subject = 'Daily post summary: ' + datetime.today().strftime('%Y-%m-%d')
message = MIMEText(summary.encode('utf-8'), _subtype='html', _charset='utf-8')
message['Subject'] = subject
server = smtplib.SMTP_SSL('smtp.gmail.com',465)
server.ehlo()
server.login(username,password)
server.sendmail(username, toaddrs, message.as_string())
server.close()
except:
print ('Something went wrong...')
traceback.print_exc()
Run the script
To run the script, first replace GMAIL account / password by yours. You also need to change your gmail settings to allow less secure apps, as described here:
https://support.google.com/accounts/answer/6010255
Now you can run this command:
python daily_summary.py 3 kwonn,samrg472
It will generate the report and send it to your email box.
You can modify the above command, e.g. pass your favourite author list to the command and your customized report.
Automate the report generation
Now you can specify a daily cron job to automate the report generation. Please refer to cron documentation here: https://help.ubuntu.com/community/CronHowto
Posted on Utopian.io - Rewarding Open Source Contributors