AV Updates script


/ Published in: Python
Save to your folder(s)

This is a rather nasty first attempt, while it works under Windows XP there is no real error checking.


Copy this code and paste it in your HTML
  1. #!/usr/bin/python
  2.  
  3. import urllib2
  4. import re
  5. import os
  6. from datetime import date
  7.  
  8. download = True
  9. scriptdir = os.getcwd()
  10. nsisdir = "C:\Program Files\NSIS"
  11. tempdir = os.tempnam()
  12.  
  13. os.mkdir(tempdir)
  14.  
  15. def getHomePath():
  16. if os.name == "posix":
  17. return os.getenv("HOME")
  18. elif os.name == "nt":
  19. import win32com.client
  20. objShell = win32com.client.Dispatch("WScript.Shell")
  21. return objShell.SpecialFolders("MyDocuments")
  22.  
  23. try:
  24. os.mkdir(getHomePath() + "/av_updates")
  25. except os.error:
  26. print "**** Folder exists, continuing... ****"
  27.  
  28. os.chdir(getHomePath() + "/av_updates")
  29.  
  30. if download:
  31. try:
  32. page = urllib2.urlopen("http://free.avg.com/gb-en/download-update").read()
  33. except urllib2.HTTPError, e:
  34. print '**** The server couldn\'t fulfill the request.', e.code, '****'
  35. except urllib2.URLError, e:
  36. print '**** We failed to reach a server. ', e.reason, '****'
  37. else:
  38. url1 = re.search(r"(http://download.avgfree.com/softw/90free/update/[^\"]+)\"\s+class=\"clr\"\s*>Windows[^<]+<\/a></td><td[^>]+>All\snecessary\smodules", page).group(1)
  39. url2 = re.search(r"(http://download\.avgfree\.com/softw/90free/update/[^\"]+)\"\s+class=\"clr\"\s*>IAVI", page).group(1)
  40.  
  41. if url1 is not None:
  42. print os.system("wget -S -N " + url1)
  43. else:
  44. print '**** Failed to retrieve modules url. ****'
  45.  
  46. if url2 is not None:
  47. print os.system("wget -S -N " + url2)
  48. else:
  49. print '**** Failed to retrieve database url. ****'
  50.  
  51. print os.system("wget -S -N http://www.superantispyware.com/downloads/SASDEFINITIONS.EXE")
  52. print os.system("wget -S -N http://www.malwarebytes.org/mbam/database/mbam-rules.exe")
  53. print os.system("wget -S -N http://www.spybotupdates.biz/updates/files/spybotsd_includes.exe")
  54.  
  55. # Prepare our update script.
  56. with open(os.path.join(scriptdir, 'av_updates.nsi'), 'r') as f:
  57. template = f.read()
  58.  
  59. today = date.today()
  60.  
  61. template = template.replace('{{date}}', today.isoformat())
  62. template = template.replace('{{scriptdir}}', scriptdir)
  63. template = template.replace('{{avg_update_1}}', re.search(r"/((\w|[-.])+)$", url1).group(1))
  64. template = template.replace('{{avg_update_2}}', re.search(r"/((\w|[-.])+)$", url2).group(1))
  65.  
  66. # Build our script!
  67. buildfile = os.path.join(tempdir, today.isoformat() + '.nsi')
  68.  
  69. with open(buildfile, 'w') as f:
  70. f.write(template)
  71.  
  72. os.chdir(nsisdir)
  73.  
  74. cmd = 'makensis "' + buildfile + '"'
  75. print '**** ' + cmd + ' ****'
  76. os.system(cmd)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.