Monday, 11 September 2017

24 hours tracking the ISS in Minecraft and Twitter

During the last week or so I have been gradually tweaking my spin on Damien Mooney's ISS tracker. link

My bolt on is to take a screenshot record of each ISS movement and then tweet that picture from a twitter bot that I set up (@warksmessabout1).

This has worked for a while in trials, but has always fallen flat after a few hours. By trial and error I have hit upon a version which has run for 27 hours continuously updating 4 times an hour.

Here is an example screenshot of one of the recent updates from earlier today:

Here is the main twitter bot code:

Tweeting ISS current position at set intervals with Minecraft Pi.
Get current ISS position from and map it on
a raspberry pi with minecraft
Damian Mooney wrote this minecraft Tracker in 2016. I have added a few
features on top, namely:
walking random wool blocks to mark current and positions
ability to screenshot the position using Martin O'Hanlons raspi2png tutorial:
ability to tweet that using twython python library
__author__ = '@damianmooney' #additions by @ncscomputing
from mcpi import minecraft as minecraft
from mcpi import block as block
from datetime import datetime
import time
import urllib2
import json
import random
import subprocess # to run shell script to autocall raspi2png
import sys
from twython import Twython
import BuildWorldDM as BuildWorld

consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
api = Twython(consumer_key,consumer_secret,access_token,access_token_secret)

WoolList = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]

""" call where the iss at api thanks to Bill Shupp"""
def getiss():
    response = urllib2.urlopen('')
    mydata =
    return mydata

""" longitude: convert our longitude to a minecraft co-ordinate"""
def do_coord(longitude):
    mine_long = longitude * -.55
    return mine_long

#if __name__ == "__main__":

mc = minecraft.Minecraft.create()
mc.postToChat(" Minecraft ISS Tracker for @naascoderdojo")
mc.player.setting("autojump", False)
mc.player.setPos(6, 20, 50)
while True:

        iss = getiss()
        pos = json.loads(iss)
        lat = pos['latitude']
        lon = pos['longitude']
        mc.postToChat("MC ISS tracker Version 1.4.1 of @naascoderdojo's Minecraft ISS Tracker")
        mc.postToChat("Credits to @damianmooney")
        mc.postToChat(' ISS Location Lat: %.2f Long: %.2f' % (lat,lon))
        new_long = do_coord(lon)
        mc.player.setPos(int(new_long), 20, int(lat))
        mc.setBlock(int(new_long), 20-1, int(lat),35,random.choice(WoolList))
        msg = 'ISS pos '+'@SpacePiJam'+' lon %d lat %d' % (new_long, lat)
                    #print msg
                    #ory to location that you havesaved raspi2png in
        a=subprocess.check_output('./raspi2png -d 3 -p "myscreenshot.png"',shell=True)
        photo = open('myscreenshot.png', 'rb')
        api.update_status_with_media(status=msg, media=photo)
        mc.postToChat("update issue")
        a=subprocess.check_output('./raspi2png -d 3 -p "myscreenshot.png"',shell=True)
        photo = open('myscreenshot.png', 'rb')
        api.update_status_with_media(status="update issue", media=photo)

    time.sleep(450) # --only update once every 15 minutes

It reads in and renders the world text file from here:

The data file is here:

Enjoy :)

No comments:

Post a Comment