:a python application, for twitter automation with Cloud Foundry on IBM Bluemix
- language: Python 2.7.10
- libraries: tweepy, time, multiprocessing
- web framework: web.py
- style: PEP 8: https://www.python.org/dev/peps/pep-0008/
- infrastructure: IBM Bluemix, https://www.ibm.com/cloud-computing/bluemix/
- platform: Cloud Foundry, https://www.cloudfoundry.org/
- Cloud Foundry command line interface (CLI): https://github.com/cloudfoundry/cli
- CF python template app: https://github.com/IBM-Bluemix/get-started-python
- code on github: https://github.com/johncoleman83/mini-tweet-bot
- working app: https://mtb.mybluemix.net/
- blog: http://www.davidjohncoleman.com/2017/mini-tweet-bot/
- twitter dev tools: https://dev.twitter.com/
- tweet deck: https://tweetdeck.twitter.com/
- twitter (bot) account: https://twitter.com/are_no_one
- api limits: https://support.twitter.com/articles/160385
- best practices: https://dev.twitter.com/basics
This has my integrations of the tweepy python library to auto generate tweets, retweets, and to follow users. There is a custom integration with twitter to allow multiple users or anyone from the public to post tweets to one specified twitter account. The current specified twitter account is specified above; however, any account can be substituted such as a tourist destination twitter account or company account. The app is designed to run on cloudfoundry applications with IBM Bluemix.
For integration with IBM Bluemix, cloudfoundry apps, see the README.md from the below referenced repository. Or read the blog post referenced above.
-
./Procfile
this file contains the initiation script for run the app in IBM Bluemix CF
-
./app.py
The main application, used to render web user interface and call all functions of all the features.
-
./censorship.py
Module with functions for censoring input text.
-
./daffodils.txt
Example directory to show how to input text to automate texting from a file.
-
./manifest.yml
Supports cloud foundry command line interface.
-
./mycredentials.py
Example of how to use twitter API to integrate with tweepy. If you attempt to make your own twitter bot, you should rename this file
credentials.py
so that it is imported intoapp.py
with the line:from credentials import *
-
./profanity.py
,./suppprt/profanity.txt
dictionary of profaine words; contains 700+ words. the
.py
file contains a a set and is imported into thecensorship.py
module, the.txt
file is used simply for testing and to more easily share the dictionary. -
./requirements.txt
contains information on the modules necessary to run this app
-
./static/
This directory contains all website support files such as
.css
,.js
, and fontasesome.io integrations -
./support/
This directory contains old files from Cloud Foundry template, that I did not use, and some other support files explained below.
-
./support/retweet_follow.py
,./singletweet.py/
,./tweet_textfile.py
These are example files that contain only one function for the event that someone wants to make a twitter bot without integration into the cloud.
-
./templates/
This contains all the HTML content as rendered with python. I used one file as a base layout which contains the same head, header, sidebar, and footer. The main content in the article section changes per GET and POST call.
$ python app.py
- fork or clone the github repository.
- get your own twitter app from twitter dev tools linked above.
- change the mycredentials.py file name to credentials.py
- change the strings from the credentials file to contain your personal twitter information.
- change the twitter feed link in the HTML tag to instead link to your witter feed.
- change the link of the twitter handle in the nav HTML tag to link instead to your linked twitter account.
- change the icon/ logos to be how you prefer
- find the cloud to host the app. It's all setup with Cloud Foundry for IBM Bluemix, but other cloud services will work as well.
NOTE: The mini tweet bot functions most successfully when hosted on a
cloud. However, if you would like to run the app on your own machine, you can
run it, and it will be loaded on a local host port IP address such as:
http://0.0.0.0:8080/. If you do not want the user interface, you should then
use only the tweet functions, and run them on an as needed basis. Here is an
example of how to run a single function from the singletweet.py
file:
$ cat singletweet.py
import tweepy
from credentials import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
def tweet_text(tweetvar):
""" tweets text from input variable """
try:
api.update_status(tweetvar)
except:
print("error")
pass
tweet_text("this tweet is an example of running a tweet function in python")
$ python singletweet.py
David John Coleman II. Check out my website davidjohncoleman.com
Public Domain, no copyright protection