SHARE
TWEET

LXF Whatsapp Pi

a guest Jun 10th, 2015 5,287 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Listing 1: status.sh
  2. #!/bin/bash
  3.  
  4. temp=$(/opt/vc/bin/vcgencmd measure_temp | cut -c6-7)
  5.  
  6. if [$temp-gt 40 ]; then
  7.    echo Whoa! My temperature is up to $(/opt/vc/bin/vcgencmd measure_temp). Power me down for a bit! | sendxmpp -t geekybodhi@jabber.hot-chilli.net
  8. fi  
  9.  
  10.  
  11. Listing 2: pitalk.py
  12. import os, subprocess, yowsup, logging
  13.  
  14. from wasend import YowsupSendStack
  15. from wareceive import YowsupReceiveStack, MessageReceived
  16.  
  17. def credential():
  18.     return447712345678”,“jK0zdPJ9zz0BBC3CwmnLqmxuhBk=”
  19.  
  20. def Answer(risp):
  21.     try:
  22.        stack=YowsupSendStack(credential(), [([447668139981”, risp])])
  23.        stack.start()
  24.     except: pass
  25.     return
  26.  
  27. def Refresh():
  28.     Answer(“Refreshing the repos.”)
  29.     os.system(sudo apt-get -y update”)
  30.     Answer(“Repos updated.”)
  31.     return
  32.  
  33. def Restart():
  34.     Answer(“Rebooting”)
  35.     os.system(sudo reboot”)
  36.     return
  37.  
  38. def Temp():
  39.     t=float(subprocess.check_output([/opt/vc/bin/vcgencmd measure_temp | cut -c6-9], shell=True)[:-1])
  40.     ts=str(t)
  41.     Answer(“My temperature is “+ts+” C”)
  42.     return
  43.  
  44. def Disk():
  45.    result=subprocess.check_output(df -h .”, shell=True)
  46.        output=result.split()
  47.      Answer(“Disk space:\nTotal: “+output[8]+”\nUsed: “+output[9]+” (“+output[11]+”)\nFree: “+output[10])
  48.    return
  49. while True:
  50.     try:
  51.            stack=YowsupReceiveStack(credential())
  52.            stack.start()
  53.     except MessageReceived as rcvd:
  54.            received=rcvd.value.lower()
  55.            if received[:len(447668139981)]==“447668139981”:
  56.                    received=received[len(447668139981):]
  57.                    if received[:4]==“hiya”: Answer(“Hi chap!)
  58.     elif received[:7]==“restart” or received[:6]==“reboot”: Restart()
  59.        elif “disk” in received: Disk()
  60.        elif “hot” in received: Temp()
  61. elif “refresh” in received: Refresh()
  62.            else: Answer(“Eh? What was that?”)
  63.        else: #message from wrong sender
  64.                    with open(/home/pi/whatsapp.log”,”a”) as mf: mf.write(“Unauthorised access from: “+received[:len(919968139981)]+”\n”)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top