Skip to content

Instantly share code, notes, and snippets.

@cudmore
Created October 28, 2017 01:29
Show Gist options
  • Save cudmore/7c909d2c51c3315c7b03e1485d0ad25a to your computer and use it in GitHub Desktop.
Save cudmore/7c909d2c51c3315c7b03e1485d0ad25a to your computer and use it in GitHub Desktop.
raspberry startup tweet
#!/usr/bin/env python2.7
# this code is taken from the following
# twitterwin.py by Alex Eames http://raspi.tv/?p=5281
import tweepy
import subprocess
import time, datetime
import socket
# Consumer keys and access tokens, used for OAuth
consumer_key = 'aaaaaaaaaaaaaaaaaaaaaaaaa'
consumer_secret = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
access_token = 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccc'
access_token_secret = 'ddddddddddddddddddddddddddddddddddddddddddddddd'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# Creation of the actual interface, using authentication
api = tweepy.API(auth)
ipAddress = 'none'
routerAddress = 'none'
#ip address (very raspberry specific)
arg='ip route list'
p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
data = p.communicate()
split_data = data[0].split()
ipAddress = split_data[split_data.index('src')+1]
routerAddress = split_data[split_data.index('via')+1]
hostName = socket.gethostname()
print 'routerAddress:', routerAddress
print 'ipAddress:', ipAddress
print 'hostName:', hostName
dateStr = str(datetime.date.today())
timeStr = time.strftime('%H:%M:%S')
myStatus = hostName + ' ' + ipAddress + ' ' + dateStr + ' ' + timeStr
if len(myStatus) > 140:
print 'error: tweet to long, max is 140 characters'
else:
print 'tweeting:', myStatus
api.update_status(status=myStatus)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment