def get_fight_summary(fight, metrics, report_info): summary = { 'fight': fight, 'parses': {}, 'report': { 'title': report_info['title'], 'id': report_info['id'], 'start': report_info['start'] } } for metric in metrics: url_dps = 'https://classic.warcraftlogs.com/reports/' + report_info[ 'id'] + '#fight=' + str( fight['id']) + '&view=rankings&playermetric=' + metric chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) print(defs.timestamp(), '*' + url_dps) driver = webdriver.Chrome(options=chrome_options) driver.get(url_dps) element = WebDriverWait(driver, 60).until( EC.presence_of_element_located((By.CLASS_NAME, "primary"))) fight['deaths'] = element.text element = WebDriverWait(driver, 60).until( EC.presence_of_element_located((By.CLASS_NAME, "player-table"))) row_elements = element.find_elements_by_tag_name('tr')[1:] for row_element in row_elements: row_stats = {} cell_elements = row_element.find_elements_by_tag_name('td') name = cell_elements[4].find_element_by_tag_name( 'a').get_attribute('innerHTML').lower() role = raiders.getRaiderAttribute(name, 'role') if ((metric == 'dps' and role in ['melee', 'ranged']) or (metric == 'hps' and role == 'healer')): row_stats['percentile'] = int(cell_elements[0].text) row_stats['rank'] = cell_elements[1].text row_stats['out_of'] = int(cell_elements[2].text.replace( ',', '')) row_stats['best_rank'] = cell_elements[3].text row_stats['dps'] = float(cell_elements[5].text.replace( ',', '')) row_stats['ilvl'] = int(cell_elements[6].text) row_stats['ipercentile'] = int(cell_elements[7].text) summary['parses'][name] = row_stats driver.close() driver.quit() return summary
def queryPage(url): print(timestamp(), url) fp = urllib.request.urlopen(url) mybytes = fp.read() fp.close() mystr = mybytes.decode('unicode-escape') return json.loads(mystr)
def read(self): with lock: try: with open(self.filename, encoding=self.encoding) as f: content = json.load(f) return content except (FileNotFoundError, json.JSONDecodeError) as e: print(timestamp(), 'tried to load file:', self.filename, 'raised error', e) self.write({}) return {}
def get_attendance(update_attendance=True, days=None, months=None): global last_update, earliest_next_update reports_file = attendance_file.read() if update_attendance and last_update + earliest_next_update < time_now(): last_update = time_now() reports = get_raids(days=days, months=months) for report_info in reports: report_info['exclude'] = report_info['title'].startswith('_') report_info['title'] = report_info['title'].lower() if '[mc]' in report_info['title']: report_info.setdefault('raids', []).append('MC') if '[bwl]' in report_info['title']: report_info.setdefault('raids', []).append('BWL') if '[ony]' in report_info['title']: report_info.setdefault('raids', []).append('ONY') if '[r]' in report_info['title']: report_info['team'] = 'team red' elif '[b]' in report_info['title']: report_info['team'] = 'team blue' if not 'raids' in report_info or not 'team' in report_info: report_info['exclude'] = True reports = [ report_info for report_info in reports if not report_info['exclude'] ] for raid in list(reports_file.keys()): if not raid in [report_info['id'] for report_info in reports]: del reports_file[raid] for report_info in reports: if report_info['id'] not in reports_file: print( defs.timestamp(), 'Adding raid (' + report_info['id'] + ') to the attendance file.') report = getReportFightCode(report_info['id']) participants = [ participant['name'].strip().lower() for participant in report['exportedCharacters'] ] raid_entry = { 'start': report_info['start'], 'title': report['title'], 'participants': participants, 'team': report_info['team'], 'raids': report_info['raids'] } reports_file[report_info['id']] = raid_entry attendance_file.write(reports_file) if days != None or months != None: last_update = 0 start = get_query_start(days, months) filtered_attendance = [ reports_file[raid_id] for raid_id in reports_file if reports_file[raid_id]['start'] > start ] return filtered_attendance
def _queryPage(url): print(timestamp(), url) r = requests.get(url) return r.json()
async def on_ready(): tempia = defs.get_tempia(client) message = 'Bot rebooted.\n **PID**: {}\n **Hostname**: {}\n **Local IP**: {}\n **External IP**: {}'.format( str(pid), host_name, host_ip, ext_ip) await tempia.send(message) print(defs.timestamp(), 'connected')
import defs print(defs.timestamp(), 'dir_path: ' + defs.dir_path) import os import asyncio import socket from urllib.request import urlopen, Request import discord pid = 0 process_name = '' ext_ip = '' host_name = '' host_ip = '' try: r = Request('https://ipapi.co/ip/', headers={'User-Agent': 'Mozilla/5.0'}) ext_ip = str(urlopen(r).read())[2:-1] print(defs.timestamp(), 'external ip:', ext_ip) except: print(defs.timestamp(), 'External IP could not be determinated.') try: host_name = socket.gethostname() print(defs.timestamp(), 'hostname:', host_name) host_ip = socket.gethostbyname(host_name) print(defs.timestamp(), 'local ip:', host_ip) except: print(defs.timestamp(), 'Local network information could not be found.') try:
def append_entry(entry): print(defs.timestamp(), list(entry.values())) log = log_file.get('log', on_error=[]) log.append(entry) log_file.set('log', log)
async def on_member_join(self, member): await member.send(admin_file.get('welcome_message', on_error='')) print(defs.timestamp(), member, 'joined server.')