LDShadowLord

Update Check

Jul 21st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. #Check Pastebin for an update, update the executable if required#
  2. #Designed to be copied/pasted into code#
  3.  
  4. #Import required modules
  5. import sys
  6. import urllib.request
  7. import logging
  8.  
  9. #Declare Variables
  10. ##Current Code Version
  11. actualVersion = "003"
  12. ##ID for version checking
  13. versionID = "S73PQGEA"
  14. ##ID for downloading source
  15. sourceID = "VxMfuSY0"
  16.  
  17. #Attempt to check if an updated version is available
  18. logging.debug("Checking for new version online")
  19. opener = urllib.request.FancyURLopener({})
  20. url = "http://pastebin.com/raw/"
  21. f = opener.open(url+versionID)
  22. content = f.read().decode("utf-8")
  23. logging.debug("Checked for new version")
  24.  
  25. #Compare version numbers, download new source if required
  26. if content != actualVersion:
  27.   logging.warn("A new version is available!")
  28.   logging.warn("Attempting to install latest version")
  29.   opener = urllib.request.FancyURLopener({})
  30.   url = "http://pastebin.com/raw/"
  31.   f = opener.open(url+sourceID)
  32.   content = f.read()
  33.   logging.debug("Downloaded new version")
  34.  
  35.   logging.debug("Attempting to overwrite file")
  36.   f_h = open(str(sys.argv[0]), "wb")
  37.   f_h.write(content)
  38.   f_h.close()
  39.   logging.warn("Installed latest version - Restart to see!")
  40. else:
  41.   logging.debug("No new version found")
Add Comment
Please, Sign In to add comment