smileyface/smileyface/scrape_latest/scrape_ut4pugs.py

66 lines
2.1 KiB
Python

import selenium
import selenium.webdriver
URL_MUTATORS = 'https://ut4pugs.us/redirect-mutators'
URL_MAPS = 'https://ut4pugs.us/redirect-mutators'
class ScrapeUt4Pugs:
def __init__(self, ctx, datalayer):
self.ctx = ctx
self.datalayer = datalayer
self._browser = None
@property
def browser(self):
if not self._browser:
self._browser = selenium.webdriver.Firefox()
return self._browser
def check_ut4pugs_for_latest(self):
self.browser.get(URL_MUTATORS)
self._check_pak_md5sums()
self.browser.get(URL_MAPS)
self._check_pak_md5sums()
def _check_pak_md5sums(self):
tbl_of_mutators = self.browser.find_element_by_id('myTable')
print(tbl_of_mutators)
mut_rows = tbl_of_mutators.find_elements_by_xpath('tbody/tr')
for r in mut_rows:
mut_cols = r.find_elements_by_xpath('td')
if len(mut_cols) != 3:
input('<breakpoint> at unexpected columns for mutator. received {}'.format(len(mut_cols)))
mut_file = mut_cols[0]
mut_md5 = mut_cols[1]
mut_ini_line = mut_cols[2]
print(mut_file.text)
print(mut_md5.text)
# print(mut_ini_line.text)
local_file = self.datalayer.query_filepak(mut_file.text)
print(local_file)
if not local_file:
self.ctx.log['ut4'].warn('pak not found locally: %s', mut_file.text)
continue
local_md5 = local_file.md5sum
remote_md5 = mut_md5.text
if local_md5 != remote_md5:
input('<breakpoint> as mismatching md5!')
print('local: ', local_md5)
print('remote: ', remote_md5)
self.datalayer.mark_filepak_validated_state(local_file.file_pak_id, 'mismatch', 'ut4pugs', remote_md5)
else:
input('<breakpoint> as matching md5! good job')
self.datalayer.mark_filepak_validated_state(local_file.file_pak_id, 'valid', 'ut4pugs', None)
# print(r)
print('xxx')
pass
pass