news2tw (News to Twitter) is a Python script to deliver news' feed to Twitter. It's similar to other scripts you can found on the Internet but I created for breaking news.
TODO: Create a post in medium to explain it.
- Use YAML for storing data.
- Shrink message length without trimming the last word.
- Prevention for running one instance at same time.
- Reddit: Use the link insted of the URL to subreddit post.
news2tw requires Python >= 2.7.13.
On Debian 9 you should install
apt install -y python-feedparser \
python-tweepy \
python-yaml
Also, if you want to run news2tw into a virtual enviroment you should install
pip install argparse==1.1 \
feedparser==5.1.3 \
logging==0.5.1.2 \
re==2.2.1 \
tweepy==3.5.0 \
yaml==3.12
First, create your Twitter application and generate the keys: Consumer key and Consumer secret. Do not forget to enable read and write access in the Permissions tab.
Get the required tokens for posting on Twitter
news2tw -a <your_feed_alias>
Finally, run a cron job every minute
1 * * * * news2tw <your_feed_alias>
news2tw -l
news2tw --clean <your_feed_alias>
Run cron on even minute
*/2 * * * * /usr/bin/python2.7 ${HOME}/news2tw/news2tw.py <your_feed_alias>
Run cron on odd minute
1-59/2 * * * * /usr/bin/python2.7 ${HOME}/news2tw/news2tw.py <your_feed_alias>
news2tw deals with the error codes from Twitter's API. For all error codes, news2tw stops the processing except:
- ERR 187: "Status is duplicated", news2tw will ingore it and continue saving it as last feed
- ERR 326: "Account is temporarily locked", news2tw will send an email to notify you
Error codes are detailed in Twitter's Docs.
They are unofficial accounts.