Advertisement
randombod

cam4 auto

Mar 2nd, 2012
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys
  3. import urllib
  4. import urllib2
  5. import httplib
  6. import re
  7. import os
  8. import time
  9. import datetime
  10. import commands
  11.  
  12. def main ():
  13.  
  14.     #Firstly make sure there are no offline sessions running which could mess with our logic checking
  15.     for name in names:
  16.         if not getStatus(name):
  17.             print 'offline' + name
  18.             status, pid = commands.getstatusoutput("ps -ef | grep -v grep | grep -i "+ name + " | grep -i chrom | head -n 1 | awk '{print $2}'")
  19.             if pid :
  20.                 print "killing " + pid
  21.                 os.system("kill -9 " + pid)
  22.  
  23.  
  24.     #Secondly check who is online and if there are any recording conflicts
  25.     for name in names:
  26.         #check person is online of not
  27.         if getStatus(name):
  28.             #create url variable
  29.             url = "www.cam4.com/" + name
  30.             #sucess user is online
  31.             print "Online: " + name
  32.             #check if we are already recording for this user, if so then exit the script
  33.             status, pid = commands.getstatusoutput("ps -ef | grep -i "+ name + " | grep -v grep | grep chrom |  head -n 1 | wc -l")
  34.             if "1" in pid:
  35.                 print "We are already recodring for this user"
  36.                 continue
  37.             #Check if we are recording for another user, if so send an email saying the user is online but we are currently recording another user
  38.             status, pid = commands.getstatusoutput("ps -ef | grep -v grep | grep -i cam4 | head -n 1 | wc -l")
  39.             if "1" in pid:
  40.                 print "Recodring conflict for user " + name        
  41.                 os.system('(echo "Subject: Recodring Conflict" ; echo We are recording another stream and the following user has came online "' + url + '" ) | /usr/sbin/sendmail  ' + email)
  42.                 continue
  43.             #Looks like this is a new stream, start recording and email
  44.             os.system('(echo "Subject: User Online" ; echo "' + url + '" ) | /usr/sbin/sendmail ' + email)
  45.             os.system('su - ' + disp_user + ' -c "export DISPLAY=:2; chromium-browser  ' + url + ' &">/dev/null 2>&1')
  46.  
  47.  
  48. def getStatus(name):
  49.     url = 'http://www.cam4.com/' + name
  50.     req = urllib2.Request(url)
  51.     response = urllib2.urlopen(req)
  52.     the_page = response.read()
  53.     if '<div id="camPaneBig">' in the_page:
  54.             return True
  55.     else:
  56.             return False
  57.  
  58. if __name__ == "__main__":
  59.     #user who owns the unix display
  60.     disp_user = "bob"
  61.     #email to receive the alerts
  62.     email = "bob@bob.com"
  63.     #profiles you want to monitor
  64.     names =['sally','sam']
  65.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement