Advertisement
xxmbabanexx

Midori Kiosk Reloader

Apr 13th, 2013
1,243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. """
  2. Midori Kiosk Reloader.
  3. Created by xxmbabanexx
  4.  
  5. NOTE: This program opens Midori automatically. DO NOT OPEN IT MANUALLY, SIMPLY CLICK ON THIS PROGRAM.
  6.  
  7. KEYS
  8.  
  9. 1 = Connection Complete. All is well.
  10.  
  11. 0 = Connection Incomplete. Something is wrong.
  12. """
  13.  
  14.  
  15. #Change these variables to your liking.
  16.  
  17. host = "www.google.com" #Put your desired host URL/IP between the quotes
  18.  
  19. port = 80 #Set to default port of 80. If your host uses something else, please change it.
  20.  
  21. recheck_time = 10 #The number of seconds the program will wait to ping the server. Change this at your leisure.
  22.  
  23. page_to_open_to = "www.google.com" #This is the webpage the kiosk will open to. Put the url between the quotes.
  24.  
  25.  
  26. #Excersise caution when changing these vars.
  27.  
  28. last = -1 #undefined state
  29. up = -1 #Undefined state
  30.  
  31.  
  32.  
  33. """
  34. #---------------- Main code. Do NOT touch unless you KNOW what you are doing. ------------
  35. """
  36. #Import modules
  37.  
  38. import subprocess as sub
  39. from time import sleep
  40. import socket
  41. import threading
  42.  
  43. sub.Popen(["midori", "-a", page_to_open_to]) #open midori
  44.  
  45.  
  46. #Check if internet is up
  47. addr = (host, port) #the connection addr
  48.  
  49.  
  50. while True:
  51.     last = up #reset checking var
  52.     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #create socket
  53.     try: #attempt to ping, change vars
  54.         s.connect(addr)
  55.         up = 1
  56.         print "\n"
  57.     except socket.error: #if error when pinging, change vars
  58.         up = 0
  59.         print "\n"
  60.        
  61.     print "LAST CHECK:", last
  62.     print "CURRENT CHECK:", up
  63.     if last == 0 and up == 1:
  64.         print "Reloading Midori.\n"
  65.         sub.call(["midori", "-e", "Reload"])
  66.     s.close()
  67.  
  68.    
  69.     sleep(recheck_time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement