I am definitely an amateur as far as Python goes. Not a coder but I do like to learn new stuff. There very well may be an easier way to do this so mess around and see what you can create. I’ve been playing around trying to add an interface between the BBS and Twitter. Finally figured out how to get it to send tweets out. Here’s the initial steps to take

First off, with Mystic, you need to make sure that Python version 2.7 is installed, not 3. Assuming you have installed Python to C:\python27. If you are running the 32 bit version of Mystic you need to have the 32 bit version of Python installed. Add these lines to your environmental variables:

SET PYTHONHOME=C:\PYTHON27
SET PYTHONPATH=C:\PYTHON27\LIB
SET PATH=%PYTHONHOME%;%PATH%

It’s important that Mystic be able to find the Python libraries and obviously the executable.

You’re going to need the Python module Tweepy in order to get this going as well. From the commandline run “pip install tweepy”. If for some reason you have libraries missing or it errors out you can download the package from Pypi here.

Then you need to set up a Twitter app to connect to whatever account you are going to use. I gleamed a lot of useful information from this post over at Raspi.tv. Although the article is specifically written for the RaspberryPi the same steps are taken to create a Twitter app.

Once you have your app created you are going to copy your consumer key, consumer secret, access token and access token secret. You’ll need them for your python script. You can also copy over the example script that Raspi.tv has given to test it out from the commandline and fix any errors.

Mystic python scripts use the .mpy extension and they go in your /scripts directory. Copy the body of the script below. Make sure to use an editor like Notepad++ so that you can remove any weird linefeeds and whitespace that may get copied from the web page. Replace the keys with your own. Make sure to leave the quotation marks. Also, update your BBS name to your own as well. I added in the writeln because there is a brief pause and I wanted people to know what it was doing in the background.

##############################################################
## INITIALIZE BBS FUNCTIONS AND DEFINE ANY GLOBAL VARIABLES ##
##############################################################
import tweepy
import sys
from mystic_bbs import *

consumer_key = ‘CONSUMERKEY’
consumer_secret = ‘CONSUMERSECRET’
access_token = ‘ACCESSTOKEN’
access_token_secret = ‘ACCESSTOKENSECRET’
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
thisuser = getuser(0); # read the currently logged in user into thisuser

writeln(“|CR|14Please Hold On….Updating Shadowscope Twitter Status! |CR|PA”);
api = tweepy.API(auth)
tweet_text = thisuser[“handle”] + ” has logged into Shadowscope BBS!”
api.update_status(status=tweet_text)

Save this script in your C:\Mystic\scripts directory.

OK. The hard work is finished. Now go into the Mystic Menu editor. I run this script from my prelogin menu so that it’s an automatic thing right after you log in. In the existing FIRSTCMD in the prelogin menu (add one if it’s not there) insert a command.  For the command choose GY for Execute Python Module. For the “Data” just insert the name of your script. In my case it’s simply called logintweet. No extension is needed, Mystic will automatically look for logintweet.mpy in the scripts directory. That’s it! Now go check your Twitter page and see if there isn’t a new tweet from the BBS.

You can access my BBS Twitter page at twitter.com/ShadowscopeBBS and my personal Twitter is twitter.com/rmiles7721, they are both linked all over the place here and widgets for both are on the main page sidebar.

Next project I am going to tackle is a simple interface for twitter that displays the current feed and allows users to send tweets as well. I am almost hesitant about the second part due to the abuse that could happen but I’ll do it just because I can. You can always restrict access to that option to trusted users.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.