Guest User

Untitled

a guest
Sep 8th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import re
  4.  
  5.  
  6. URL = 'http://www.catalog.update.microsoft.com/ScopedViewInline.aspx?updateid='
  7. UPDATES = {}
  8.  
  9.  
  10. def gen(updateid):
  11.     if updateid not in UPDATES:
  12.         kb = KB(updateid)
  13.         kb.get_updates()
  14.         tmp = {updateid: kb}
  15.         UPDATES.update(tmp)
  16.         for updateid in kb.replaced_to:
  17.             new_kb = KB(updateid)
  18.             print('{} replaced to {}'.format(kb, new_kb))
  19.             gen(new_kb.updateid)
  20.  
  21.  
  22. class KB:  
  23.     def __init__(self, updateid):
  24.         r = requests.get(URL + updateid)
  25.         soup = BeautifulSoup(r.text, 'html.parser')
  26.         self.description = soup.find('div', {'id': 'titleDiv'}).find('span', {'id': 'ScopedViewHandler_titleText'}).text
  27.         self.name = re.findall(r'KB\d+', self.description)[-1]
  28.         self.url = URL + updateid
  29.         self.updateid = updateid
  30.         self.replaced_to = []
  31.  
  32.  
  33.     def get_updates(self):
  34.         l = []
  35.         r = requests.get(self.url)
  36.         soup = BeautifulSoup(r.text, 'html.parser')
  37.         for a in soup.find('div', {'id': 'supersededbyInfo'}).find_all('a'):
  38.             l.append(re.findall(r'[\d,\w,\-]+$', a['href'])[-1])
  39.         self.replaced_to = l
  40.         if len(l) == 0:
  41.             self.not_replaced = True
  42.         else:
  43.             self.not_replaced = False
  44.  
  45.  
  46.     def __str__(self):
  47.         return self.name
  48.  
  49.  
  50. # Обновление для системы безопасности Windows Server 2012 R2 (KB3067505)
  51. # https://www.catalog.update.microsoft.com/ScopedViewInline.aspx?updateid=33cd6b5a-f5a8-4d2d-b163-96e155eed7b9
  52. updateid = '33cd6b5a-f5a8-4d2d-b163-96e155eed7b9'
  53. gen(updateid)
  54. print('\n\nNot replaced updates:')
  55. for kb in UPDATES:
  56.     if UPDATES[kb].not_replaced == True:
  57.         print('{}: {}'.format(UPDATES[kb].name, UPDATES[kb].description))
  58.         print('URL: {}\n'.format(UPDATES[kb].url))
Advertisement
Add Comment
Please, Sign In to add comment