Neural Market Trends |||

A Simple Blog Post Tweeter

I continue on my journey to rebuild this blog’s traffic. One idea I had was to build a simple Python based blog post tweeter. I would select a blog post at random and then tweet it to my @neuralmarket Twitter account. I chose Python because of the Twython package. It made for a simple connection to my Twitter account and was easy to parse a text file.

The idea was this. I create a text file of all the blog posts I want to retweet - appended with a link - and write a catchy tweet. I would then run the Python script to select at random a pre-written tweet from the text file. When I’m ready, I can cron job this script and run it once or twice a day. Over time I can add or delete pre-written tweets or try to optimize them for SEO.

I suggest that all my readers try this, it’s not hard and is simple to follow.

##The Twitter Token

First you have to get a Twitter token. This allows you the Python script to post on your behalf and there are four bits of information you need. First visit and navigate to the application owner access token page. There you can learn on how to make a single application and generate the follow api values:

  1. Consumer Key

  2. Consumer Secret

  3. Access Token

  4. Access Token Secret

You’ll need these four items for the Python script below.

##The text file

Next, create a simple text file (TXT extension) and put a single tweet per line. Make sure to add your blog post link. I use to shorten my long URLs.

Here’s an example of my text file:

Autogenerate Blog Posts with .@Rapidminer

A simple Stock Trend Following model in .@Rapidminer

What does Value really mean? For reals!

What to expect from being a Sales Engineer at a Startup

Make sure to save this file in the same directory as your Python script. I keep all my scripts and files in a Dropbox folder so I can access it anywhere.

##The Code

Now here’s the code. I’m going to XXX out my consumer and access keys, you’ll have to add your own from the first step above.

#!/usr/bin/env python
import sys
import os
import random

from twython import Twython, TwythonError


#Use the following path structure for linux machine

#f = open('/home/path/to/tweet.txt', 'r')

#Use the following path structure for a windows machine

f = open('C:\\path\\to\\tweet.txt', 'r')

lines = f.readlines()

post = random.choice(lines)


    api.update_status(status="R2D2 says: " + post)
except TwythonError as e:
    print e

It’s as simple as that. Just remember you need to install the Twython package and I wrote this script in Python v2.7. Any questions, just drop me a comment.

Up next SEO Health Checkup I’m busy with revamping this website, trying to rebuild its traffic. I spend my free time analyzing Google Analytics and checking Google Webmaster. Hacking Tags with Blot.Im
Latest posts Phone Addiction Version 12 Launches Today! Machine Learning Making Pesto Tastier 5 Dangerous Things You Should Let Your Kids Do The Pyschology of Writing TensorFlow and High Level APIs Driving Marketing Performance with H2O Driverless AI Machine Learning and Data Munging in H2O Driverless AI with datatable Making AI Happen Without Getting Fired Latest Musings from a Traveling Sales Engineer The Night before H2O World 2019 Why Forex Trading is Frustrating Functional Programming in Python Automatic Feature Engineering with Driverless AI Ray Dalio's Pure Alpha Fund What's new in Driverless AI? Latest Writings Elsewhere - December 2018 House Buying Guide for Millennials Changing Pinboard Tags with Python Automate Feed Extraction and Posting it to Twitter Flux: A Machine Learning Framework for Julia Getting Started in Data Science Part 2 Makers vs Takers How Passive Investing Saved My Life Startups and Open Source The Process of Writing H2O AI World 2018 in London Ray Dalio's Pure Alpha Fund Isolation Forests in Living the Dream? Humility and Equanimity in Sales