Skip to content

Instantly share code, notes, and snippets.

@djfav
Last active Nov 16, 2017
Embed
What would you like to do?
Raspberry Pi Twitter Bot Twython Script - Tweet Current Disk Usage
#!/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 = 'df | grep rootfs'
rootline = os.popen(cmd).readline().strip()
rootsplit = rootline.split(" ")
usedkb = float(rootsplit[len(rootsplit) - 6])
totalkb = float(rootsplit[len(rootsplit) - 7])
usedgb = int(round((usedkb / 1024) / 1024))
totalgb = int(round((totalkb / 1024) / 1024))
percent = int(round((usedgb * 100) / totalgb))
tweet = 'The date and time is: ' + time + ' and my current disk usage is: ' + str(usedgb) + 'G of ' + str(totalgb) + 'G or ' + str(percent) + '%'
#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