Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Raspberry Pi Twitter Bot Twython Script - Tweet Packets Received and Transmitted
#!/usr/bin/env python
import sys
import os
from twython import Twython
CONSUMER_KEY = 'redacted'
CONSUMER_SECRET = 'redacted'
ACCESS_KEY = 'redacted'
ACCESS_SECRET = 'redacted'
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
cmd = 'date'
time = os.popen(cmd).readline().strip()
cmd = '/sbin/ifconfig wlan0 | grep -oP \'RX packets:\K\d+\''
rx = os.popen(cmd).readline().strip()
cmd = '/sbin/ifconfig wlan0 | grep -oP \'TX packets:\K\d+\''
tx = os.popen(cmd).readline().strip()
tweet = 'The date and time is: ' + time + ' and I have received ' + rx + ' packets and transmitted ' + tx + ' packets.'
#print tweet
api.update_status(status = tweet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment