From 7f19215afe4ae4008a97ebe7fb7eec41f7085f9c Mon Sep 17 00:00:00 2001 From: MuffinMedic Date: Mon, 12 Feb 2018 01:07:47 -0500 Subject: [PATCH 01/33] Add speccy module --- plugins/speccy.py | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 plugins/speccy.py diff --git a/plugins/speccy.py b/plugins/speccy.py new file mode 100644 index 000000000..a9b9e3614 --- /dev/null +++ b/plugins/speccy.py @@ -0,0 +1,99 @@ +from cloudbot import hook +from cloudbot.event import EventType + +import asyncio +import re +import requests + +from bs4 import BeautifulSoup as BS + +@asyncio.coroutine +@hook.event([EventType.message, EventType.action], singlethread=True) +def get_speccy_url(conn, message, chan, content, nick): + re_content = re.search(r"https?:\/\/speccy.piriform.com\/results\/[A-z0-9]+", content) + if re_content: + message("({}) Analyzing Speccy URL...".format(nick)) + return parse_speccy(message, nick, str(re_content.group(0))) + +def parse_speccy(message, nick, url): + + response = requests.get(url) + if not response: + return "Error retrieving speccy URL" + + soup = BS(response.content, "lxml-xml") + + try: + osspec = soup.body.find("div", text='Operating System').next_sibling.next_sibling.text + except AttributeError: + return "Invalid Speccy URL" + + try: + ramspec = soup.body.find("div", text='RAM').next_sibling.next_sibling.text + except AttributeError: + ramspec = None + + try: + cpuspec = soup.body.find("div", text='CPU').next_sibling.next_sibling.text + except AttributeError: + cpuspec = None + + try: + gpuspec = soup.body.find("div", text='Graphics').next_sibling.next_sibling.stripped_strings + graphics_list = [] + for item in gpuspec: + graphics_list.append(item) + length = len(graphics_list) + gpuspec = graphics_list[length-2] + " " + graphics_list[length-1] + except Exception: + gpuspec = None + + try: + picospec = soup.body.find("div", text=re.compile('.*pico', re.IGNORECASE)).text + except AttributeError: + picospec = None + + try: + kmsspec = soup.body.find("div", text=re.compile('.*kms', re.IGNORECASE)).text + except AttributeError: + kmsspec = None + + try: + boosterspec = soup.body.find("div", text=re.compile('.*booster', re.IGNORECASE)).text + except AttributeError: + boosterspec = None + + def smartcheck(): + drivespec = soup.body.find_all("div", text="05") + number_of_drives = len(drivespec) + + values = [] + for i in range(0,number_of_drives): + z = drivespec[i].next_sibling.next_sibling.stripped_strings + saucy = list(z) + rv_index = saucy.index("Raw Value:") + raw_value = saucy[rv_index+1] + if raw_value != "0000000000": + values.append(str(i+1)) + return values + + try: + z = smartcheck() + if len(z) != 0: + smartstr = "" + for item in z: + smartstr += " #" + item + " " + smartspec = "Bad " + smartstr + else: + smartspec = "Good" + except Exception: + smartspec = None + + specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02AutoPico:\x02 {} ● \x02KMS:\x02 {} ● \x02Booster:\x02 {} ● \x02Drive(s):\x02 {}".format(osspec, ramspec, cpuspec, gpuspec, picospec, kmsspec, boosterspec, smartspec) + + specout = re.sub("\s{2,}|\r\n|\n", " ", specin) + + if picospec or kmsspec: + message("({}) WARNING: Pirated sofware found (AutoPico: {}, KMS: {}). Please be advised we do not support users running software that violates the Terms of Service.".format(nick, picospec, kmsspec)) + + return specout From e4adf75da4743817cd87e2909de4784b263316d9 Mon Sep 17 00:00:00 2001 From: MuffinMedic Date: Mon, 12 Feb 2018 12:07:05 -0500 Subject: [PATCH 02/33] Add XTU and Reviver --- plugins/speccy.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index a9b9e3614..bf78a2eea 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -12,14 +12,15 @@ def get_speccy_url(conn, message, chan, content, nick): re_content = re.search(r"https?:\/\/speccy.piriform.com\/results\/[A-z0-9]+", content) if re_content: - message("({}) Analyzing Speccy URL...".format(nick)) + # message("({}) Analyzing Speccy URL...".format(nick)) return parse_speccy(message, nick, str(re_content.group(0))) def parse_speccy(message, nick, url): response = requests.get(url) if not response: - return "Error retrieving speccy URL" + #return "Error retrieving speccy URL" + return None soup = BS(response.content, "lxml-xml") @@ -63,12 +64,22 @@ def parse_speccy(message, nick, url): except AttributeError: boosterspec = None + try: + xtuspec = soup.body.find("div", text=re.compile('.*xtu', re.IGNORECASE)).text + except AttributeError: + xtuspec = None + + try: + reviverspec = soup.body.find("div", text=re.compile('.*reviver', re.IGNORECASE)).text + except AttributeError: + reviverspec = None + def smartcheck(): drivespec = soup.body.find_all("div", text="05") number_of_drives = len(drivespec) values = [] - for i in range(0,number_of_drives): + for i in range(0, number_of_drives): z = drivespec[i].next_sibling.next_sibling.stripped_strings saucy = list(z) rv_index = saucy.index("Raw Value:") @@ -83,17 +94,27 @@ def smartcheck(): smartstr = "" for item in z: smartstr += " #" + item + " " - smartspec = "Bad " + smartstr + smartspec = "Failing " + smartstr else: smartspec = "Good" except Exception: smartspec = None - specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02AutoPico:\x02 {} ● \x02KMS:\x02 {} ● \x02Booster:\x02 {} ● \x02Drive(s):\x02 {}".format(osspec, ramspec, cpuspec, gpuspec, picospec, kmsspec, boosterspec, smartspec) + piracy_list = [picospec, kmsspec] + piracy = ', '.join(filter(None, piracy_list)) + if not piracy: + piracy = None + + badware_list = [boosterspec, xtuspec, reviverspec] + badware = ', '.join(filter(None, badware_list)) + if not badware: + badware = None + + specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02Piracy:\x02 {} ● \x02Badware:\x02 {} ● \x02Drive(s):\x02 {}".format(osspec, ramspec, cpuspec, gpuspec, piracy, badware, smartspec) specout = re.sub("\s{2,}|\r\n|\n", " ", specin) - if picospec or kmsspec: - message("({}) WARNING: Pirated sofware found (AutoPico: {}, KMS: {}). Please be advised we do not support users running software that violates the Terms of Service.".format(nick, picospec, kmsspec)) + if piracy: + message("({}) WARNING: Piracy sofware found ({}). Please be advised we do not support users running software that violates the Terms of Service.".format(nick, piracy)) return specout From ef2487fbba2604e3fd071312f9d47786c171ace1 Mon Sep 17 00:00:00 2001 From: MuffinMedic Date: Mon, 12 Feb 2018 12:13:53 -0500 Subject: [PATCH 03/33] Fixed SMART formatting --- plugins/speccy.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index bf78a2eea..87df8089f 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -91,12 +91,11 @@ def smartcheck(): try: z = smartcheck() if len(z) != 0: - smartstr = "" + smartspec = "" for item in z: - smartstr += " #" + item + " " - smartspec = "Failing " + smartstr + smartspec += " #" + item + " " else: - smartspec = "Good" + smartspec = None except Exception: smartspec = None @@ -110,7 +109,7 @@ def smartcheck(): if not badware: badware = None - specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02Piracy:\x02 {} ● \x02Badware:\x02 {} ● \x02Drive(s):\x02 {}".format(osspec, ramspec, cpuspec, gpuspec, piracy, badware, smartspec) + specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02Piracy:\x02 {} ● \x02Badware:\x02 {} ● \x02Failing Drive(s):\x02 {}".format(osspec, ramspec, cpuspec, gpuspec, piracy, badware, smartspec) specout = re.sub("\s{2,}|\r\n|\n", " ", specin) From 3ed293c34f5e482685ed548d38fb3147ab525fdd Mon Sep 17 00:00:00 2001 From: Jessexd Date: Tue, 13 Feb 2018 00:04:27 -0500 Subject: [PATCH 04/33] tons of shit --- plugins/speccy.py | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 87df8089f..9cbd2ef68 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -12,14 +12,12 @@ def get_speccy_url(conn, message, chan, content, nick): re_content = re.search(r"https?:\/\/speccy.piriform.com\/results\/[A-z0-9]+", content) if re_content: - # message("({}) Analyzing Speccy URL...".format(nick)) return parse_speccy(message, nick, str(re_content.group(0))) def parse_speccy(message, nick, url): response = requests.get(url) if not response: - #return "Error retrieving speccy URL" return None soup = BS(response.content, "lxml-xml") @@ -40,37 +38,34 @@ def parse_speccy(message, nick, url): cpuspec = None try: - gpuspec = soup.body.find("div", text='Graphics').next_sibling.next_sibling.stripped_strings - graphics_list = [] - for item in gpuspec: - graphics_list.append(item) - length = len(graphics_list) - gpuspec = graphics_list[length-2] + " " + graphics_list[length-1] - except Exception: + gpufind = soup.body.find("div", text='Graphics').next_sibling.next_sibling.text + for gpuspec in re.finditer(r".*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*", gpufind, re.I): + print(gpuspec.group(0)) # <--------- this is proof it works, but I can't make the bot output it right + except AttributeError: gpuspec = None try: - picospec = soup.body.find("div", text=re.compile('.*pico', re.IGNORECASE)).text + picospec = soup.body.find("div", text=re.compile('.*pico', re.I)).text except AttributeError: picospec = None try: - kmsspec = soup.body.find("div", text=re.compile('.*kms', re.IGNORECASE)).text + kmsspec = soup.body.find("div", text=re.compile('.*kms', re.I)).text except AttributeError: kmsspec = None try: - boosterspec = soup.body.find("div", text=re.compile('.*booster', re.IGNORECASE)).text + boosterspec = soup.body.find("div", text=re.compile('.*booster', re.I)).text except AttributeError: boosterspec = None try: - xtuspec = soup.body.find("div", text=re.compile('.*xtu', re.IGNORECASE)).text + xtuspec = soup.body.find("div", text=re.compile('.*xtu', re.I)).text except AttributeError: xtuspec = None try: - reviverspec = soup.body.find("div", text=re.compile('.*reviver', re.IGNORECASE)).text + reviverspec = soup.body.find("div", text=re.compile('.*reviver', re.I)).text except AttributeError: reviverspec = None @@ -91,7 +86,7 @@ def smartcheck(): try: z = smartcheck() if len(z) != 0: - smartspec = "" + smartspec = " Disk:" for item in z: smartspec += " #" + item + " " else: @@ -99,21 +94,13 @@ def smartcheck(): except Exception: smartspec = None - piracy_list = [picospec, kmsspec] - piracy = ', '.join(filter(None, piracy_list)) - if not piracy: - piracy = None - - badware_list = [boosterspec, xtuspec, reviverspec] + badware_list = [picospec, kmsspec, boosterspec, xtuspec, reviverspec] badware = ', '.join(filter(None, badware_list)) if not badware: badware = None - specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02Piracy:\x02 {} ● \x02Badware:\x02 {} ● \x02Failing Drive(s):\x02 {}".format(osspec, ramspec, cpuspec, gpuspec, piracy, badware, smartspec) + specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02Badware:\x02 {} ● \x02Failing Drive(s):\x02 {}".format(osspec, ramspec, cpuspec, gpuspec, badware, smartspec) specout = re.sub("\s{2,}|\r\n|\n", " ", specin) - if piracy: - message("({}) WARNING: Piracy sofware found ({}). Please be advised we do not support users running software that violates the Terms of Service.".format(nick, piracy)) - return specout From f46eabb7599bd74f3d5cbb9039ce03a4d5199003 Mon Sep 17 00:00:00 2001 From: MuffinMedic Date: Tue, 13 Feb 2018 00:08:27 -0500 Subject: [PATCH 05/33] Formatting fixes --- plugins/speccy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 87df8089f..b978205f0 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -93,7 +93,7 @@ def smartcheck(): if len(z) != 0: smartspec = "" for item in z: - smartspec += " #" + item + " " + smartspec += item + " " else: smartspec = None except Exception: @@ -114,6 +114,6 @@ def smartcheck(): specout = re.sub("\s{2,}|\r\n|\n", " ", specin) if piracy: - message("({}) WARNING: Piracy sofware found ({}). Please be advised we do not support users running software that violates the Terms of Service.".format(nick, piracy)) + message("({}) WARNING: Piracy sofware found ({}). Please note this violates Terms of Service and is not recommended.".format(nick, piracy)) return specout From 31aae3d572ea28ec82a7ee66daa3e73699a8e54e Mon Sep 17 00:00:00 2001 From: Jessexd Date: Thu, 15 Feb 2018 17:42:09 -0500 Subject: [PATCH 06/33] An actual commit --- plugins/speccy.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 243d74f94..32718fa1e 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -38,9 +38,10 @@ def parse_speccy(message, nick, url): cpuspec = None try: - gpufind = soup.body.find("div", text='Graphics').next_sibling.next_sibling.text - for gpuspec in re.finditer(r".*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*", gpufind, re.I): - print(gpuspec.group(0)) # <--------- this is proof it works, but I can't make the bot output it right + gpufind = soup.body.find("div", text='Graphics').next_sibling.next_sibling.text + gpuspec = "" + for gpustring in re.finditer(r".*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*", gpufind, re.IGNORECASE): + gpuspec += gpustring.group() except AttributeError: gpuspec = None @@ -58,12 +59,7 @@ def parse_speccy(message, nick, url): boosterspec = soup.body.find("div", text=re.compile('.*booster', re.I)).text except AttributeError: boosterspec = None - - try: - xtuspec = soup.body.find("div", text=re.compile('.*xtu', re.I)).text - except AttributeError: - xtuspec = None - + try: reviverspec = soup.body.find("div", text=re.compile('.*reviver', re.I)).text except AttributeError: @@ -88,13 +84,13 @@ def smartcheck(): if len(z) != 0: smartspec = " Disk:" for item in z: - smartspec += item + " " + smartspec += " #" + item + " " else: smartspec = None except Exception: smartspec = None - badware_list = [picospec, kmsspec, boosterspec, xtuspec, reviverspec] + badware_list = [picospec, kmsspec, boosterspec, reviverspec] badware = ', '.join(filter(None, badware_list)) if not badware: badware = None From f2d3c28be95f60f661d0056fd46f63e09a90d9e3 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Thu, 15 Feb 2018 17:44:13 -0500 Subject: [PATCH 07/33] Fixed --- plugins/speccy.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 243d74f94..32718fa1e 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -38,9 +38,10 @@ def parse_speccy(message, nick, url): cpuspec = None try: - gpufind = soup.body.find("div", text='Graphics').next_sibling.next_sibling.text - for gpuspec in re.finditer(r".*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*", gpufind, re.I): - print(gpuspec.group(0)) # <--------- this is proof it works, but I can't make the bot output it right + gpufind = soup.body.find("div", text='Graphics').next_sibling.next_sibling.text + gpuspec = "" + for gpustring in re.finditer(r".*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*", gpufind, re.IGNORECASE): + gpuspec += gpustring.group() except AttributeError: gpuspec = None @@ -58,12 +59,7 @@ def parse_speccy(message, nick, url): boosterspec = soup.body.find("div", text=re.compile('.*booster', re.I)).text except AttributeError: boosterspec = None - - try: - xtuspec = soup.body.find("div", text=re.compile('.*xtu', re.I)).text - except AttributeError: - xtuspec = None - + try: reviverspec = soup.body.find("div", text=re.compile('.*reviver', re.I)).text except AttributeError: @@ -88,13 +84,13 @@ def smartcheck(): if len(z) != 0: smartspec = " Disk:" for item in z: - smartspec += item + " " + smartspec += " #" + item + " " else: smartspec = None except Exception: smartspec = None - badware_list = [picospec, kmsspec, boosterspec, xtuspec, reviverspec] + badware_list = [picospec, kmsspec, boosterspec, reviverspec] badware = ', '.join(filter(None, badware_list)) if not badware: badware = None From efceb1d4a91d3f978ca13e26314a531019cbbc24 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Fri, 16 Feb 2018 18:40:49 -0500 Subject: [PATCH 08/33] greatly optmized, much less CPU ussage, reformatted as per PEP8 requirments --- plugins/speccy.py | 58 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 32718fa1e..3898ff918 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -4,44 +4,60 @@ import asyncio import re import requests +import tempfile from bs4 import BeautifulSoup as BS + @asyncio.coroutine @hook.event([EventType.message, EventType.action], singlethread=True) def get_speccy_url(conn, message, chan, content, nick): - re_content = re.search(r"https?:\/\/speccy.piriform.com\/results\/[A-z0-9]+", content) + re_content = re.search( + r"https?:\/\/speccy.piriform.com\/results\/[A-z0-9]+", content) if re_content: return parse_speccy(message, nick, str(re_content.group(0))) + def parse_speccy(message, nick, url): response = requests.get(url) if not response: return None - soup = BS(response.content, "lxml-xml") + respHtml = response.content + speccy = tempfile.NamedTemporaryFile() + + with open(speccy.name, 'wb') as f: + f.write(respHtml) + + soup = BS(open(speccy.name), "lxml-xml") try: - osspec = soup.body.find("div", text='Operating System').next_sibling.next_sibling.text + osspec = soup.body.find( + "div", text='Operating System').next_sibling.next_sibling.text except AttributeError: return "Invalid Speccy URL" try: - ramspec = soup.body.find("div", text='RAM').next_sibling.next_sibling.text + ramspec = soup.body.find( + "div", text='RAM').next_sibling.next_sibling.text except AttributeError: ramspec = None try: - cpuspec = soup.body.find("div", text='CPU').next_sibling.next_sibling.text + cpuspec = soup.body.find( + "div", text='CPU').next_sibling.next_sibling.text except AttributeError: cpuspec = None try: - gpufind = soup.body.find("div", text='Graphics').next_sibling.next_sibling.text - gpuspec = "" - for gpustring in re.finditer(r".*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*", gpufind, re.IGNORECASE): - gpuspec += gpustring.group() + gpufind = soup.body.find( + "div", text='Graphics').next_sibling.next_sibling.text + gpuspec = "" + for gpustring in re.finditer( + r".*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*", + gpufind, re.IGNORECASE): + gpuspec += gpustring.group() except AttributeError: gpuspec = None @@ -56,15 +72,23 @@ def parse_speccy(message, nick, url): kmsspec = None try: - boosterspec = soup.body.find("div", text=re.compile('.*booster', re.I)).text + boosterspec = soup.body.find( + "div", text=re.compile('.*booster', re.I)).text except AttributeError: boosterspec = None - + try: - reviverspec = soup.body.find("div", text=re.compile('.*reviver', re.I)).text + reviverspec = soup.body.find( + "div", text=re.compile('.*reviver', re.I)).text except AttributeError: reviverspec = None + try: + killerspec = soup.body.find( + "div", text=re.compile('.*Killer.+Service', re.I)).text + except AttributeError: + killerspec = None + def smartcheck(): drivespec = soup.body.find_all("div", text="05") number_of_drives = len(drivespec) @@ -74,9 +98,9 @@ def smartcheck(): z = drivespec[i].next_sibling.next_sibling.stripped_strings saucy = list(z) rv_index = saucy.index("Raw Value:") - raw_value = saucy[rv_index+1] + raw_value = saucy[rv_index + 1] if raw_value != "0000000000": - values.append(str(i+1)) + values.append(str(i + 1)) return values try: @@ -90,13 +114,15 @@ def smartcheck(): except Exception: smartspec = None - badware_list = [picospec, kmsspec, boosterspec, reviverspec] + badware_list = [picospec, kmsspec, boosterspec, reviverspec, killerspec] badware = ', '.join(filter(None, badware_list)) if not badware: badware = None - specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02Badware:\x02 {} ● \x02Failing Drive(s):\x02 {}".format(osspec, ramspec, cpuspec, gpuspec, badware, smartspec) + specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02Badware:\x02 {} ● \x02Failing Drive(s):\x02 {}".format( + osspec, ramspec, cpuspec, gpuspec, badware, smartspec) specout = re.sub("\s{2,}|\r\n|\n", " ", specin) return specout + From dc2480a6623bbda7afeb157869c4cf1e8217008c Mon Sep 17 00:00:00 2001 From: Jessexd Date: Fri, 16 Feb 2018 20:30:34 -0500 Subject: [PATCH 09/33] code readability --- plugins/speccy.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 3898ff918..171b31561 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from cloudbot import hook from cloudbot.event import EventType @@ -119,7 +120,13 @@ def smartcheck(): if not badware: badware = None - specin = "\x02OS:\x02 {} ● \x02RAM:\x02 {} ● \x02CPU:\x02 {} ● \x02GPU:\x02 {} ● \x02Badware:\x02 {} ● \x02Failing Drive(s):\x02 {}".format( + specin = "\x02OS:\x02 {}\ + ● \x02RAM:\x02 {}\ + ● \x02CPU:\x02 {}\ + ● \x02GPU:\x02 {}\ + ● \x02Badware:\x02 {}\ + ● \x02Failing Drive(s):\x02 {}\ + ".format( osspec, ramspec, cpuspec, gpuspec, badware, smartspec) specout = re.sub("\s{2,}|\r\n|\n", " ", specin) From 48d171121e9354d6a0138f9d76eb55f3490bf0a7 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sat, 17 Feb 2018 20:04:32 -0500 Subject: [PATCH 10/33] :O --- plugins/speccy.py | 136 +++++++++++++++++----------------------------- 1 file changed, 49 insertions(+), 87 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 171b31561..37cfeb0fc 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -1,97 +1,72 @@ # -*- coding: utf-8 -*- from cloudbot import hook -from cloudbot.event import EventType -import asyncio import re import requests -import tempfile from bs4 import BeautifulSoup as BS +from contextlib import closing +url_re = re.compile('https?:\/\/speccy.piriform.com\/results\/[A-z0-9]+', re.I) -@asyncio.coroutine -@hook.event([EventType.message, EventType.action], singlethread=True) -def get_speccy_url(conn, message, chan, content, nick): - re_content = re.search( - r"https?:\/\/speccy.piriform.com\/results\/[A-z0-9]+", content) - if re_content: - return parse_speccy(message, nick, str(re_content.group(0))) +@hook.regex(url_re) +def get_speccy_url(message, match, chan, nick): -def parse_speccy(message, nick, url): + with closing(requests.get(match.group(), stream=True, + timeout=3)) as response: + soup = BS(response.content, "lxml", from_encoding=response.encoding) - response = requests.get(url) - if not response: - return None + body = soup.body - respHtml = response.content - speccy = tempfile.NamedTemporaryFile() + data = [] - with open(speccy.name, 'wb') as f: - f.write(respHtml) + osspec = body.find("div", text='Operating System') + if osspec: + data.append( + "\x02OS:\x02" + " " + osspec.next_sibling.next_sibling.text) - soup = BS(open(speccy.name), "lxml-xml") + ramspec = body.find("div", text='RAM') + if ramspec: + data.append( + "\x02RAM:\x02" + " " + ramspec.next_sibling.next_sibling.text) - try: - osspec = soup.body.find( - "div", text='Operating System').next_sibling.next_sibling.text - except AttributeError: - return "Invalid Speccy URL" + cpuspec = body.find("div", text='CPU') + if cpuspec: + data.append( + "\x02CPU:\x02" + " " + cpuspec.next_sibling.next_sibling.text) - try: - ramspec = soup.body.find( - "div", text='RAM').next_sibling.next_sibling.text - except AttributeError: - ramspec = None + gpufind = body.find("div", text='Graphics').next_sibling.next_sibling.text + gpuspec = "" + for gpustring in re.finditer( + r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', + gpufind, re.IGNORECASE): + gpuspec += gpustring.group() + if gpuspec: + data.append("\x02GPU:\x02" + " " + gpuspec) - try: - cpuspec = soup.body.find( - "div", text='CPU').next_sibling.next_sibling.text - except AttributeError: - cpuspec = None + picospec = body.find("div", text=re.compile('.*pico', re.I)) + if picospec: + data.append("\x02Badware:\x02" + " " + picospec.text) - try: - gpufind = soup.body.find( - "div", text='Graphics').next_sibling.next_sibling.text - gpuspec = "" - for gpustring in re.finditer( - r".*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*", - gpufind, re.IGNORECASE): - gpuspec += gpustring.group() - except AttributeError: - gpuspec = None + kmsspec = body.find("div", text=re.compile('.*kms', re.I)) + if kmsspec: + data.append("\x02Badware:\x02" + " " + kmsspec.text) - try: - picospec = soup.body.find("div", text=re.compile('.*pico', re.I)).text - except AttributeError: - picospec = None + boosterspec = body.find("div", text=re.compile('.*booster', re.I)) + if boosterspec: + data.append("\x02Badware:\x02" + " " + boosterspec.text) - try: - kmsspec = soup.body.find("div", text=re.compile('.*kms', re.I)).text - except AttributeError: - kmsspec = None + reviverspec = body.find("div", text=re.compile('.*reviver', re.I)) + if reviverspec: + data.append("\x02Badware:\x02" + " " + reviverspec.text) - try: - boosterspec = soup.body.find( - "div", text=re.compile('.*booster', re.I)).text - except AttributeError: - boosterspec = None - - try: - reviverspec = soup.body.find( - "div", text=re.compile('.*reviver', re.I)).text - except AttributeError: - reviverspec = None - - try: - killerspec = soup.body.find( - "div", text=re.compile('.*Killer.+Service', re.I)).text - except AttributeError: - killerspec = None + killerspec = body.find("div", text=re.compile('.*Killer.+Service', re.I)) + if killerspec: + data.append("\x02Badware:\x02" + " " + killerspec.text) def smartcheck(): - drivespec = soup.body.find_all("div", text="05") + drivespec = body.find_all("div", text="05") number_of_drives = len(drivespec) values = [] @@ -107,29 +82,16 @@ def smartcheck(): try: z = smartcheck() if len(z) != 0: - smartspec = " Disk:" + smartspec = "" for item in z: - smartspec += " #" + item + " " + smartspec += data.append("\x02Bad Disk:\x02" + + (smartspec) + " #" + item + " ") else: smartspec = None except Exception: smartspec = None - badware_list = [picospec, kmsspec, boosterspec, reviverspec, killerspec] - badware = ', '.join(filter(None, badware_list)) - if not badware: - badware = None - - specin = "\x02OS:\x02 {}\ - ● \x02RAM:\x02 {}\ - ● \x02CPU:\x02 {}\ - ● \x02GPU:\x02 {}\ - ● \x02Badware:\x02 {}\ - ● \x02Failing Drive(s):\x02 {}\ - ".format( - osspec, ramspec, cpuspec, gpuspec, badware, smartspec) - - specout = re.sub("\s{2,}|\r\n|\n", " ", specin) + specout = re.sub("\s{2,}|\r\n|\n", " ", str(' + '.join(data))) return specout From bafcc32ef1d8cfa0524e46f0596be49788a84270 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sun, 18 Feb 2018 20:16:42 -0500 Subject: [PATCH 11/33] fixed due to reviewers requested changes --- plugins/speccy.py | 59 +++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 37cfeb0fc..84db4784b 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -7,14 +7,20 @@ from bs4 import BeautifulSoup as BS from contextlib import closing -url_re = re.compile('https?:\/\/speccy.piriform.com\/results\/[A-z0-9]+', re.I) +url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', + re.I) + +PICO_RE = re.compile('.*pico', re.I) +KMS_RE = re.compile('.*kms', re.I) +BOOSTER_RE = re.compile('.*booster', re.I) +REVIVER_RE = re.compile('.*reviver', re.I) +KILLER_RE = re.compile('.*Killer.+Service', re.I) @hook.regex(url_re) -def get_speccy_url(message, match, chan, nick): +def get_speccy_url(match): - with closing(requests.get(match.group(), stream=True, - timeout=3)) as response: + with closing(requests.get(match.group(), )) as response: soup = BS(response.content, "lxml", from_encoding=response.encoding) body = soup.body @@ -37,33 +43,34 @@ def get_speccy_url(message, match, chan, nick): "\x02CPU:\x02" + " " + cpuspec.next_sibling.next_sibling.text) gpufind = body.find("div", text='Graphics').next_sibling.next_sibling.text + GPU_RE = re.finditer( + r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', gpufind, + re.IGNORECASE) gpuspec = "" - for gpustring in re.finditer( - r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', - gpufind, re.IGNORECASE): + for gpustring in GPU_RE: gpuspec += gpustring.group() if gpuspec: data.append("\x02GPU:\x02" + " " + gpuspec) - picospec = body.find("div", text=re.compile('.*pico', re.I)) + picospec = body.find("div", text=PICO_RE) if picospec: - data.append("\x02Badware:\x02" + " " + picospec.text) + data.append("\x02Bad:\x02" + " " + picospec.text) - kmsspec = body.find("div", text=re.compile('.*kms', re.I)) + kmsspec = body.find("div", text=KMS_RE) if kmsspec: - data.append("\x02Badware:\x02" + " " + kmsspec.text) + data.append("\x02Bad:\x02" + " " + kmsspec.text) - boosterspec = body.find("div", text=re.compile('.*booster', re.I)) + boosterspec = body.find("div", text=BOOSTER_RE) if boosterspec: - data.append("\x02Badware:\x02" + " " + boosterspec.text) + data.append("\x02Bad:\x02" + " " + boosterspec.text) - reviverspec = body.find("div", text=re.compile('.*reviver', re.I)) + reviverspec = body.find("div", text=REVIVER_RE) if reviverspec: - data.append("\x02Badware:\x02" + " " + reviverspec.text) + data.append("\x02Bad:\x02" + " " + reviverspec.text) - killerspec = body.find("div", text=re.compile('.*Killer.+Service', re.I)) + killerspec = body.find("div", text=KILLER_RE) if killerspec: - data.append("\x02Badware:\x02" + " " + killerspec.text) + data.append("\x02Bad:\x02" + " " + killerspec.text) def smartcheck(): drivespec = body.find_all("div", text="05") @@ -79,19 +86,11 @@ def smartcheck(): values.append(str(i + 1)) return values - try: - z = smartcheck() - if len(z) != 0: - smartspec = "" - for item in z: - smartspec += data.append("\x02Bad Disk:\x02" + - (smartspec) + " #" + item + " ") - else: - smartspec = None - except Exception: - smartspec = None + z = smartcheck() + if z: + for item in z: + data.append("\x02Bad Disk:\x02 #{}".format(item)) - specout = re.sub("\s{2,}|\r\n|\n", " ", str(' + '.join(data))) + specout = re.sub(r"\s+", " ", ' ● '.join(data)) return specout - From ee495da05b72faf47fef6ba0a8712d6c3585505c Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sun, 18 Feb 2018 23:53:37 -0500 Subject: [PATCH 12/33] added GPU_RE to the be with the other globally defined regex --- plugins/speccy.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 84db4784b..6595a9de4 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- + from cloudbot import hook import re @@ -10,6 +11,8 @@ url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) +GPU_RE = re.compile( + r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) PICO_RE = re.compile('.*pico', re.I) KMS_RE = re.compile('.*kms', re.I) BOOSTER_RE = re.compile('.*booster', re.I) @@ -43,11 +46,8 @@ def get_speccy_url(match): "\x02CPU:\x02" + " " + cpuspec.next_sibling.next_sibling.text) gpufind = body.find("div", text='Graphics').next_sibling.next_sibling.text - GPU_RE = re.finditer( - r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', gpufind, - re.IGNORECASE) gpuspec = "" - for gpustring in GPU_RE: + for gpustring in GPU_RE.finditer(gpufind): gpuspec += gpustring.group() if gpuspec: data.append("\x02GPU:\x02" + " " + gpuspec) From fb17d5074ec8976c1433feee04b23d96db2dd040 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Mon, 19 Feb 2018 14:20:56 -0500 Subject: [PATCH 13/33] made variable names less vague and generic, disregardded pep8 line length warning because it was honestly less easy to read before. No actual functionality or change to the code otherwise. --- plugins/speccy.py | 20 +++++----- plugins/speccy.py~ | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 plugins/speccy.py~ diff --git a/plugins/speccy.py b/plugins/speccy.py index 6595a9de4..f6eec075c 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -8,11 +8,9 @@ from bs4 import BeautifulSoup as BS from contextlib import closing -url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', - re.I) +url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) -GPU_RE = re.compile( - r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) +GPU_RE = re.compile(r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) PICO_RE = re.compile('.*pico', re.I) KMS_RE = re.compile('.*kms', re.I) BOOSTER_RE = re.compile('.*booster', re.I) @@ -78,17 +76,17 @@ def smartcheck(): values = [] for i in range(0, number_of_drives): - z = drivespec[i].next_sibling.next_sibling.stripped_strings - saucy = list(z) - rv_index = saucy.index("Raw Value:") - raw_value = saucy[rv_index + 1] + drives = drivespec[i].next_sibling.next_sibling.stripped_strings + SMART = list(drives) + rv_index = SMART.index("Raw Value:") + raw_value = SMART[rv_index + 1] if raw_value != "0000000000": values.append(str(i + 1)) return values - z = smartcheck() - if z: - for item in z: + drives = smartcheck() + if drives: + for item in drives: data.append("\x02Bad Disk:\x02 #{}".format(item)) specout = re.sub(r"\s+", " ", ' ● '.join(data)) diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ new file mode 100644 index 000000000..2f6e0bc41 --- /dev/null +++ b/plugins/speccy.py~ @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- + +from cloudbot import hook + +import re +import requests + +from bs4 import BeautifulSoup as BS +from contextlib import closing + +url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) + +GPU_RE = re.compile(r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) +PICO_RE = re.compile('.*pico', re.I) +KMS_RE = re.compile('.*kms', re.I) +BOOSTER_RE = re.compile('.*booster', re.I) +REVIVER_RE = re.compile('.*reviver', re.I) +KILLER_RE = re.compile('.*Killer.+Service', re.I) + + +@hook.regex(url_re) +def get_speccy_url(match): + + with closing(requests.get(match.group(), )) as response: + soup = BS(response.content, "lxml", from_encoding=response.encoding) + + body = soup.body + + data = [] + + osspec = body.find("div", text='Operating System') + if osspec: + data.append( + "\x02OS:\x02" + " " + osspec.next_sibling.next_sibling.text) + + ramspec = body.find("div", text='RAM') + if ramspec: + data.append( + "\x02RAM:\x02" + " " + ramspec.next_sibling.next_sibling.text) + + cpuspec = body.find("div", text='CPU') + if cpuspec: + data.append( + "\x02CPU:\x02" + " " + cpuspec.next_sibling.next_sibling.text) + + gpufind = body.find("div", text='Graphics').next_sibling.next_sibling.text + gpuspec = "" + for gpustring in GPU_RE.finditer(gpufind): + gpuspec += gpustring.group() + if gpuspec: + data.append("\x02GPU:\x02" + " " + gpuspec) + + picospec = body.find("div", text=PICO_RE) + if picospec: + data.append("\x02Bad:\x02" + " " + picospec.text) + + kmsspec = body.find("div", text=KMS_RE) + if kmsspec: + data.append("\x02Bad:\x02" + " " + kmsspec.text) + + boosterspec = body.find("div", text=BOOSTER_RE) + if boosterspec: + data.append("\x02Bad:\x02" + " " + boosterspec.text) + + reviverspec = body.find("div", text=REVIVER_RE) + if reviverspec: + data.append("\x02Bad:\x02" + " " + reviverspec.text) + + killerspec = body.find("div", text=KILLER_RE) + if killerspec: + data.append("\x02Bad:\x02" + " " + killerspec.text) + + def smartcheck(): + drivespec = body.find_all("div", text="05") + number_of_drives = len(drivespec) + + values = [] + for i in range(0, number_of_drives): + check = drivespec[i].next_sibling.next_sibling.stripped_strings + SMART = list(check) + rv_index = SMART.index("Raw Value:") + raw_value = SMART[rv_index + 1] + if raw_value != "0000000000": + values.append(str(i + 1)) + return values + + check = smartcheck() + if check: + for item in check: + data.append("\x02Bad Disk:\x02 #{}".format(item)) + + specout = re.sub(r"\s+", " ", ' ● '.join(data)) + + return specout From c977e3c973cdc68e254f4d07bcd15d75b285ccfb Mon Sep 17 00:00:00 2001 From: Jessexd Date: Mon, 19 Feb 2018 14:47:06 -0500 Subject: [PATCH 14/33] removed useless r in GPU_RE regex since others weren't like that. --- plugins/speccy.py | 2 +- plugins/speccy.py~ | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index f6eec075c..13dbf5e6e 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -10,7 +10,7 @@ url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) -GPU_RE = re.compile(r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) +GPU_RE = re.compile('.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) PICO_RE = re.compile('.*pico', re.I) KMS_RE = re.compile('.*kms', re.I) BOOSTER_RE = re.compile('.*booster', re.I) diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ index 2f6e0bc41..f6eec075c 100644 --- a/plugins/speccy.py~ +++ b/plugins/speccy.py~ @@ -76,17 +76,17 @@ def get_speccy_url(match): values = [] for i in range(0, number_of_drives): - check = drivespec[i].next_sibling.next_sibling.stripped_strings - SMART = list(check) + drives = drivespec[i].next_sibling.next_sibling.stripped_strings + SMART = list(drives) rv_index = SMART.index("Raw Value:") raw_value = SMART[rv_index + 1] if raw_value != "0000000000": values.append(str(i + 1)) return values - check = smartcheck() - if check: - for item in check: + drives = smartcheck() + if drives: + for item in drives: data.append("\x02Bad Disk:\x02 #{}".format(item)) specout = re.sub(r"\s+", " ", ' ● '.join(data)) From d49eb278da290a9df95a72b05fb5ab7004209785 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Mon, 19 Feb 2018 14:51:06 -0500 Subject: [PATCH 15/33] Changed Bad: to Badware: (makes it less generic of what "bad" is) --- plugins/speccy.py | 10 +++++----- plugins/speccy.py~ | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 13dbf5e6e..bbd2b45d6 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -52,23 +52,23 @@ def get_speccy_url(match): picospec = body.find("div", text=PICO_RE) if picospec: - data.append("\x02Bad:\x02" + " " + picospec.text) + data.append("\x02Badware:\x02" + " " + picospec.text) kmsspec = body.find("div", text=KMS_RE) if kmsspec: - data.append("\x02Bad:\x02" + " " + kmsspec.text) + data.append("\x02Badware:\x02" + " " + kmsspec.text) boosterspec = body.find("div", text=BOOSTER_RE) if boosterspec: - data.append("\x02Bad:\x02" + " " + boosterspec.text) + data.append("\x02Badware:\x02" + " " + boosterspec.text) reviverspec = body.find("div", text=REVIVER_RE) if reviverspec: - data.append("\x02Bad:\x02" + " " + reviverspec.text) + data.append("\x02Badware:\x02" + " " + reviverspec.text) killerspec = body.find("div", text=KILLER_RE) if killerspec: - data.append("\x02Bad:\x02" + " " + killerspec.text) + data.append("\x02Badware:\x02" + " " + killerspec.text) def smartcheck(): drivespec = body.find_all("div", text="05") diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ index f6eec075c..13dbf5e6e 100644 --- a/plugins/speccy.py~ +++ b/plugins/speccy.py~ @@ -10,7 +10,7 @@ from contextlib import closing url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) -GPU_RE = re.compile(r'.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) +GPU_RE = re.compile('.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) PICO_RE = re.compile('.*pico', re.I) KMS_RE = re.compile('.*kms', re.I) BOOSTER_RE = re.compile('.*booster', re.I) From 601e599b03a50420b8671fb39ef5efa9e5ce7761 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Mon, 19 Feb 2018 21:49:28 -0500 Subject: [PATCH 16/33] removed "# -*- coding: utf-8 -*-" --- plugins/speccy.py | 2 -- plugins/speccy.py~ | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index bbd2b45d6..67c80d649 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from cloudbot import hook import re diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ index 13dbf5e6e..bbd2b45d6 100644 --- a/plugins/speccy.py~ +++ b/plugins/speccy.py~ @@ -52,23 +52,23 @@ def get_speccy_url(match): picospec = body.find("div", text=PICO_RE) if picospec: - data.append("\x02Bad:\x02" + " " + picospec.text) + data.append("\x02Badware:\x02" + " " + picospec.text) kmsspec = body.find("div", text=KMS_RE) if kmsspec: - data.append("\x02Bad:\x02" + " " + kmsspec.text) + data.append("\x02Badware:\x02" + " " + kmsspec.text) boosterspec = body.find("div", text=BOOSTER_RE) if boosterspec: - data.append("\x02Bad:\x02" + " " + boosterspec.text) + data.append("\x02Badware:\x02" + " " + boosterspec.text) reviverspec = body.find("div", text=REVIVER_RE) if reviverspec: - data.append("\x02Bad:\x02" + " " + reviverspec.text) + data.append("\x02Badware:\x02" + " " + reviverspec.text) killerspec = body.find("div", text=KILLER_RE) if killerspec: - data.append("\x02Bad:\x02" + " " + killerspec.text) + data.append("\x02Badware:\x02" + " " + killerspec.text) def smartcheck(): drivespec = body.find_all("div", text="05") From 9d2d695a551a3deed73910b1a7cb0d6379215010 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Mon, 19 Feb 2018 21:56:46 -0500 Subject: [PATCH 17/33] removed repeatedly calling __getitem__ on the list. (for drivespec) --- plugins/speccy.py | 5 ++--- plugins/speccy.py~ | 7 ++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 67c80d649..26b3185f7 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -70,11 +70,10 @@ def get_speccy_url(match): def smartcheck(): drivespec = body.find_all("div", text="05") - number_of_drives = len(drivespec) values = [] - for i in range(0, number_of_drives): - drives = drivespec[i].next_sibling.next_sibling.stripped_strings + for i, spec in enumerate(drivespec): + drives = spec.next_sibling.next_sibling.stripped_strings SMART = list(drives) rv_index = SMART.index("Raw Value:") raw_value = SMART[rv_index + 1] diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ index bbd2b45d6..26b3185f7 100644 --- a/plugins/speccy.py~ +++ b/plugins/speccy.py~ @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from cloudbot import hook import re @@ -72,11 +70,10 @@ def get_speccy_url(match): def smartcheck(): drivespec = body.find_all("div", text="05") - number_of_drives = len(drivespec) values = [] - for i in range(0, number_of_drives): - drives = drivespec[i].next_sibling.next_sibling.stripped_strings + for i, spec in enumerate(drivespec): + drives = spec.next_sibling.next_sibling.stripped_strings SMART = list(drives) rv_index = SMART.index("Raw Value:") raw_value = SMART[rv_index + 1] From cadcfa4e2e09817f27049a838d991769f466463e Mon Sep 17 00:00:00 2001 From: Jessexd Date: Mon, 19 Feb 2018 22:01:09 -0500 Subject: [PATCH 18/33] added back "# -*- coding: utf-8 -*-" because I'm a moron --- plugins/speccy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 26b3185f7..8b67d7555 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -1,4 +1,4 @@ -from cloudbot import hook +# -*- coding: utf-8 -*- import re import requests From efa475841d8f70b96adf1f3232a73246c220c675 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Mon, 19 Feb 2018 22:05:37 -0500 Subject: [PATCH 19/33] Ooops, removed the cloudbot hook on accident, WOW --- plugins/speccy.py | 2 ++ plugins/speccy.py~ | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugins/speccy.py b/plugins/speccy.py index 8b67d7555..08dd03fe0 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from cloudbot import hook + import re import requests diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ index 26b3185f7..08dd03fe0 100644 --- a/plugins/speccy.py~ +++ b/plugins/speccy.py~ @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from cloudbot import hook import re From bf3cb8485cad87aca15b7e57b011662a4851e5e7 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Mon, 19 Feb 2018 22:09:52 -0500 Subject: [PATCH 20/33] removal of cached speccy.py file --- plugins/speccy.py~ | 93 ---------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 plugins/speccy.py~ diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ deleted file mode 100644 index 08dd03fe0..000000000 --- a/plugins/speccy.py~ +++ /dev/null @@ -1,93 +0,0 @@ -# -*- coding: utf-8 -*- - -from cloudbot import hook - -import re -import requests - -from bs4 import BeautifulSoup as BS -from contextlib import closing - -url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) - -GPU_RE = re.compile('.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) -PICO_RE = re.compile('.*pico', re.I) -KMS_RE = re.compile('.*kms', re.I) -BOOSTER_RE = re.compile('.*booster', re.I) -REVIVER_RE = re.compile('.*reviver', re.I) -KILLER_RE = re.compile('.*Killer.+Service', re.I) - - -@hook.regex(url_re) -def get_speccy_url(match): - - with closing(requests.get(match.group(), )) as response: - soup = BS(response.content, "lxml", from_encoding=response.encoding) - - body = soup.body - - data = [] - - osspec = body.find("div", text='Operating System') - if osspec: - data.append( - "\x02OS:\x02" + " " + osspec.next_sibling.next_sibling.text) - - ramspec = body.find("div", text='RAM') - if ramspec: - data.append( - "\x02RAM:\x02" + " " + ramspec.next_sibling.next_sibling.text) - - cpuspec = body.find("div", text='CPU') - if cpuspec: - data.append( - "\x02CPU:\x02" + " " + cpuspec.next_sibling.next_sibling.text) - - gpufind = body.find("div", text='Graphics').next_sibling.next_sibling.text - gpuspec = "" - for gpustring in GPU_RE.finditer(gpufind): - gpuspec += gpustring.group() - if gpuspec: - data.append("\x02GPU:\x02" + " " + gpuspec) - - picospec = body.find("div", text=PICO_RE) - if picospec: - data.append("\x02Badware:\x02" + " " + picospec.text) - - kmsspec = body.find("div", text=KMS_RE) - if kmsspec: - data.append("\x02Badware:\x02" + " " + kmsspec.text) - - boosterspec = body.find("div", text=BOOSTER_RE) - if boosterspec: - data.append("\x02Badware:\x02" + " " + boosterspec.text) - - reviverspec = body.find("div", text=REVIVER_RE) - if reviverspec: - data.append("\x02Badware:\x02" + " " + reviverspec.text) - - killerspec = body.find("div", text=KILLER_RE) - if killerspec: - data.append("\x02Badware:\x02" + " " + killerspec.text) - - def smartcheck(): - drivespec = body.find_all("div", text="05") - - values = [] - for i, spec in enumerate(drivespec): - drives = spec.next_sibling.next_sibling.stripped_strings - SMART = list(drives) - rv_index = SMART.index("Raw Value:") - raw_value = SMART[rv_index + 1] - if raw_value != "0000000000": - values.append(str(i + 1)) - return values - - drives = smartcheck() - if drives: - for item in drives: - data.append("\x02Bad Disk:\x02 #{}".format(item)) - - specout = re.sub(r"\s+", " ", ' ● '.join(data)) - - return specout From dc5a78128d546a6fe47e950bb8c86dd15c8e3029 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Thu, 22 Feb 2018 00:36:58 -0500 Subject: [PATCH 21/33] Update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 1fb06211f..9df910c63 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,3 +18,4 @@ pythonwhois imgurpython isodate yarl +speccy_parser From 60cefc9a1b8133f4cfd910c36b8596e75868b17f Mon Sep 17 00:00:00 2001 From: Jessexd Date: Wed, 28 Feb 2018 14:43:51 -0500 Subject: [PATCH 22/33] Implemented checks so it doesn't error out the plugin, added underscores for variable names for readability. --- plugins/speccy.py | 108 ++++++++++++++++++++++++++++------------------ requirements.txt | 1 - 2 files changed, 65 insertions(+), 44 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 08dd03fe0..1733c1786 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -10,12 +10,13 @@ url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) +RAMUSG_RE = re.compile('.*memory.+usage', re.I) GPU_RE = re.compile('.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) PICO_RE = re.compile('.*pico', re.I) KMS_RE = re.compile('.*kms', re.I) BOOSTER_RE = re.compile('.*booster', re.I) REVIVER_RE = re.compile('.*reviver', re.I) -KILLER_RE = re.compile('.*Killer.+Service', re.I) +KILLER_RE = re.compile('.*killer.+service', re.I) @hook.regex(url_re) @@ -28,60 +29,81 @@ def get_speccy_url(match): data = [] - osspec = body.find("div", text='Operating System') - if osspec: + os_spec = body.find("div", text='Operating System') + if os_spec: data.append( - "\x02OS:\x02" + " " + osspec.next_sibling.next_sibling.text) + "\x02OS:\x02" + " " + os_spec.next_sibling.next_sibling.text) - ramspec = body.find("div", text='RAM') - if ramspec: - data.append( - "\x02RAM:\x02" + " " + ramspec.next_sibling.next_sibling.text) + def cspace(): + c_drive = body.find("div", class_="datavalue", text='C:') + if c_drive is not None: + c_drive = body.parent.parent + c_free_space_data = c_drive.find( + "div", text='Free Space:\xA0', class_="datakey").parent + return c_free_space_data.find(class_="datavalue").text + + if cspace(): + data.append("\x02Space Left (C:\):\x02" + " " + cspace()) - cpuspec = body.find("div", text='CPU') - if cpuspec: + ram_spec = body.find("div", text='RAM') + if ram_spec: + data.append( + "\x02RAM:\x02" + " " + ram_spec.next_sibling.next_sibling.text) + + memusg_spec = body.find( + "div", class_="blue clear", + text='Physical Memory').next_sibling.next_sibling.find( + "div", text='Memory Usage:\xA0', + class_="datakey").parent.find(class_="datavalue").text + if memusg_spec: + data.append("\x02MEM Usage:\x02" + " " + memusg_spec) + + cpu_spec = body.find("div", text='CPU') + if cpu_spec: data.append( - "\x02CPU:\x02" + " " + cpuspec.next_sibling.next_sibling.text) + "\x02CPU:\x02" + " " + cpu_spec.next_sibling.next_sibling.text) - gpufind = body.find("div", text='Graphics').next_sibling.next_sibling.text - gpuspec = "" - for gpustring in GPU_RE.finditer(gpufind): - gpuspec += gpustring.group() - if gpuspec: - data.append("\x02GPU:\x02" + " " + gpuspec) + gpu_find = body.find("div", text='Graphics').next_sibling.next_sibling.text + gpu_spec = "" + for gpu_string in GPU_RE.finditer(gpu_find): + gpu_spec += gpu_string.group() + if gpu_spec: + data.append("\x02GPU:\x02" + " " + gpu_spec) - picospec = body.find("div", text=PICO_RE) - if picospec: - data.append("\x02Badware:\x02" + " " + picospec.text) + pico_spec = body.find("div", text=PICO_RE) + if pico_spec: + data.append("\x02Badware:\x02" + " " + pico_spec.text) - kmsspec = body.find("div", text=KMS_RE) - if kmsspec: - data.append("\x02Badware:\x02" + " " + kmsspec.text) + kms_spec = body.find("div", text=KMS_RE) + if kms_spec: + data.append("\x02Badware:\x02" + " " + kms_spec.text) - boosterspec = body.find("div", text=BOOSTER_RE) - if boosterspec: - data.append("\x02Badware:\x02" + " " + boosterspec.text) + booster_spec = body.find("div", text=BOOSTER_RE) + if booster_spec: + data.append("\x02Badware:\x02" + " " + booster_spec.text) - reviverspec = body.find("div", text=REVIVER_RE) - if reviverspec: - data.append("\x02Badware:\x02" + " " + reviverspec.text) + reviver_spec = body.find("div", text=REVIVER_RE) + if reviver_spec: + data.append("\x02Badware:\x02" + " " + reviver_spec.text) - killerspec = body.find("div", text=KILLER_RE) - if killerspec: - data.append("\x02Badware:\x02" + " " + killerspec.text) + killer_spec = body.find("div", text=KILLER_RE) + if killer_spec: + data.append("\x02Badware:\x02" + " " + killer_spec.text) def smartcheck(): - drivespec = body.find_all("div", text="05") - - values = [] - for i, spec in enumerate(drivespec): - drives = spec.next_sibling.next_sibling.stripped_strings - SMART = list(drives) - rv_index = SMART.index("Raw Value:") - raw_value = SMART[rv_index + 1] - if raw_value != "0000000000": - values.append(str(i + 1)) - return values + drive__spec = body.find_all("div", class_="blue clear", text="05") + drive_spec_SMART_checked = body.find( + "div", class_="blue clear", text="05") + if drive_spec_SMART_checked is not None: + values = [] + for i, found in enumerate(drive__spec): + drives = found.next_sibling.next_sibling.stripped_strings + SMART = list(drives) + rv_index = SMART.index("Raw Value:") + raw_value = SMART[rv_index + 1] + if raw_value != "0000000000": + values.append(str(i + 1)) + return values drives = smartcheck() if drives: diff --git a/requirements.txt b/requirements.txt index 9df910c63..1fb06211f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,4 +18,3 @@ pythonwhois imgurpython isodate yarl -speccy_parser From 55bcc6c2a613f753c0555df2cb3d30802fdf9a4c Mon Sep 17 00:00:00 2001 From: Jessexd Date: Thu, 1 Mar 2018 00:37:17 -0500 Subject: [PATCH 23/33] Added checking ability, shouldn't return nothing in the chat upon error anymore, new features: Memory usage C:\ Space left --- plugins/speccy.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 1733c1786..b2380968a 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -10,7 +10,6 @@ url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) -RAMUSG_RE = re.compile('.*memory.+usage', re.I) GPU_RE = re.compile('.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) PICO_RE = re.compile('.*pico', re.I) KMS_RE = re.compile('.*kms', re.I) @@ -50,13 +49,13 @@ def cspace(): data.append( "\x02RAM:\x02" + " " + ram_spec.next_sibling.next_sibling.text) - memusg_spec = body.find( + mem_usg_spec = body.find( "div", class_="blue clear", text='Physical Memory').next_sibling.next_sibling.find( "div", text='Memory Usage:\xA0', class_="datakey").parent.find(class_="datavalue").text - if memusg_spec: - data.append("\x02MEM Usage:\x02" + " " + memusg_spec) + if mem_usg_spec: + data.append("\x02RAM Usg:\x02" + " " + mem_usg_spec) cpu_spec = body.find("div", text='CPU') if cpu_spec: @@ -90,6 +89,9 @@ def cspace(): if killer_spec: data.append("\x02Badware:\x02" + " " + killer_spec.text) + if 'Badware' not in data: + data.append("\x02No Badware\x02") + def smartcheck(): drive__spec = body.find_all("div", class_="blue clear", text="05") drive_spec_SMART_checked = body.find( @@ -109,6 +111,8 @@ def smartcheck(): if drives: for item in drives: data.append("\x02Bad Disk:\x02 #{}".format(item)) + else: + data.append("\x02Disks Healthy\x02") specout = re.sub(r"\s+", " ", ' ● '.join(data)) From 1a2d613bc127ba9ab38a07730aa82f3859c9dd37 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Thu, 1 Mar 2018 00:44:13 -0500 Subject: [PATCH 24/33] small confusing naming I had going --- plugins/speccy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index b2380968a..7581694bd 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -49,13 +49,13 @@ def cspace(): data.append( "\x02RAM:\x02" + " " + ram_spec.next_sibling.next_sibling.text) - mem_usg_spec = body.find( + ram_usg_spec = body.find( "div", class_="blue clear", text='Physical Memory').next_sibling.next_sibling.find( "div", text='Memory Usage:\xA0', class_="datakey").parent.find(class_="datavalue").text - if mem_usg_spec: - data.append("\x02RAM Usg:\x02" + " " + mem_usg_spec) + if ram_usg_spec: + data.append("\x02RAM Usg:\x02" + " " + ram_usg_spec) cpu_spec = body.find("div", text='CPU') if cpu_spec: From a0baf000dcc97c01789a741fbcf4edb6d0f36e3e Mon Sep 17 00:00:00 2001 From: Jessexd Date: Thu, 1 Mar 2018 14:23:58 -0500 Subject: [PATCH 25/33] Badware checking was broken, fixed --- plugins/speccy.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 7581694bd..7135bc323 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -28,6 +28,10 @@ def get_speccy_url(match): data = [] + def specout(): + spec_out = re.sub(r"\s+", " ", ' ● '.join(data)) + return spec_out + os_spec = body.find("div", text='Operating System') if os_spec: data.append( @@ -89,7 +93,7 @@ def cspace(): if killer_spec: data.append("\x02Badware:\x02" + " " + killer_spec.text) - if 'Badware' not in data: + if 'Badware' not in specout(): data.append("\x02No Badware\x02") def smartcheck(): @@ -116,4 +120,4 @@ def smartcheck(): specout = re.sub(r"\s+", " ", ' ● '.join(data)) - return specout + return specout() From 6ee430c9eb57e222235c866f2fc51f9b0273180c Mon Sep 17 00:00:00 2001 From: Jessexd Date: Thu, 1 Mar 2018 14:32:41 -0500 Subject: [PATCH 26/33] oops --- plugins/speccy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 7135bc323..ca8ef3cc2 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -120,4 +120,4 @@ def smartcheck(): specout = re.sub(r"\s+", " ", ' ● '.join(data)) - return specout() + return specout From c211e9a93b85f27fd177a7e5f9b953b2169a925e Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sat, 3 Mar 2018 19:26:33 -0500 Subject: [PATCH 27/33] issue with when badware not found, blabla --- plugins/speccy.py | 89 ++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index ca8ef3cc2..9fcac3b63 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -28,78 +28,89 @@ def get_speccy_url(match): data = [] - def specout(): - spec_out = re.sub(r"\s+", " ", ' ● '.join(data)) - return spec_out - os_spec = body.find("div", text='Operating System') - if os_spec: + if os_spec is not None: data.append( "\x02OS:\x02" + " " + os_spec.next_sibling.next_sibling.text) def cspace(): - c_drive = body.find("div", class_="datavalue", text='C:') - if c_drive is not None: - c_drive = body.parent.parent - c_free_space_data = c_drive.find( - "div", text='Free Space:\xA0', class_="datakey").parent - return c_free_space_data.find(class_="datavalue").text + c_space_spec = body.find("div", class_="datavalue", text='C:') + if c_space_spec is not None: + c_space_spec_found = c_space_spec.parent.parent + c_space_data = c_space_spec_found.find("div", text='Free Space:\xA0', class_="datakey").parent + return c_space_data.find(class_="datavalue").text - if cspace(): - data.append("\x02Space Left (C:\):\x02" + " " + cspace()) + c_space_spec = cspace() + if c_space_spec is not None: + data.append("\x02Space Left (C:\):\x02" + " " + c_space_spec) ram_spec = body.find("div", text='RAM') - if ram_spec: + if ram_spec is not None: data.append( "\x02RAM:\x02" + " " + ram_spec.next_sibling.next_sibling.text) - ram_usg_spec = body.find( - "div", class_="blue clear", - text='Physical Memory').next_sibling.next_sibling.find( - "div", text='Memory Usage:\xA0', - class_="datakey").parent.find(class_="datavalue").text - if ram_usg_spec: - data.append("\x02RAM Usg:\x02" + " " + ram_usg_spec) + def ramusg(): + ram_usg_spec = body.find("div", class_="blue clear", text='Physical ramory') + if ram_usg_spec is not None: + ram_usg_spec_found = ram_usg_spec.next_sibling.next_sibling + ram_usg_data = ram_usg_spec_found.find("div", text='Memory Usage:\xA0', class_="datakey").parent + return ram_usg_data.find(class_="datavalue").text + + ram_usg_spec = ramusg() + if ram_usg_spec is not None: + data.append("\x02RAM USG:\x02" + " " + ram_usg_spec) cpu_spec = body.find("div", text='CPU') - if cpu_spec: + if cpu_spec is not None: data.append( "\x02CPU:\x02" + " " + cpu_spec.next_sibling.next_sibling.text) - gpu_find = body.find("div", text='Graphics').next_sibling.next_sibling.text - gpu_spec = "" - for gpu_string in GPU_RE.finditer(gpu_find): - gpu_spec += gpu_string.group() - if gpu_spec: + def gpuspec(): + gpu_find = body.find("div", text='Graphics') + if gpu_find is not None: + gpu_find = gpu_find.next_sibling.next_sibling.text + gpu_spec = "" + for gpu_string in GPU_RE.finditer(gpu_find): + gpu_spec += gpu_string.group() + return gpu_spec + + gpu_spec = gpuspec() + if gpu_spec is not None: data.append("\x02GPU:\x02" + " " + gpu_spec) + has_badware = False + pico_spec = body.find("div", text=PICO_RE) - if pico_spec: + if pico_spec is not None: + has_badware = True data.append("\x02Badware:\x02" + " " + pico_spec.text) kms_spec = body.find("div", text=KMS_RE) - if kms_spec: + if kms_spec is not None: + has_badware = True data.append("\x02Badware:\x02" + " " + kms_spec.text) booster_spec = body.find("div", text=BOOSTER_RE) - if booster_spec: + if booster_spec is not None: + has_badware = True data.append("\x02Badware:\x02" + " " + booster_spec.text) reviver_spec = body.find("div", text=REVIVER_RE) - if reviver_spec: + if reviver_spec is not None: + has_badware = True data.append("\x02Badware:\x02" + " " + reviver_spec.text) killer_spec = body.find("div", text=KILLER_RE) - if killer_spec: + if killer_spec is not None: + has_badware = True data.append("\x02Badware:\x02" + " " + killer_spec.text) - if 'Badware' not in specout(): + if not has_badware: data.append("\x02No Badware\x02") def smartcheck(): drive__spec = body.find_all("div", class_="blue clear", text="05") - drive_spec_SMART_checked = body.find( - "div", class_="blue clear", text="05") + drive_spec_SMART_checked = body.find("div", class_="blue clear", text="05") if drive_spec_SMART_checked is not None: values = [] for i, found in enumerate(drive__spec): @@ -109,15 +120,15 @@ def smartcheck(): raw_value = SMART[rv_index + 1] if raw_value != "0000000000": values.append(str(i + 1)) - return values + return values drives = smartcheck() - if drives: + if drives is not None: for item in drives: data.append("\x02Bad Disk:\x02 #{}".format(item)) else: data.append("\x02Disks Healthy\x02") - specout = re.sub(r"\s+", " ", ' ● '.join(data)) + spec_out = re.sub(r"\s+", " ", ' ● '.join(data)) - return specout + return spec_out From 4725b3f8f5e1b9b150e6dfce7dbb927bfbc4f354 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sat, 3 Mar 2018 22:07:10 -0500 Subject: [PATCH 28/33] smalll wooopsy from the drivespec code (duplicated 2 variables with 1 being actualy mangled), condensed badware code --- plugins/speccy.py | 41 ++++------------- plugins/speccy.py~ | 112 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 32 deletions(-) create mode 100644 plugins/speccy.py~ diff --git a/plugins/speccy.py b/plugins/speccy.py index 9fcac3b63..f32043989 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -78,42 +78,19 @@ def gpuspec(): if gpu_spec is not None: data.append("\x02GPU:\x02" + " " + gpu_spec) - has_badware = False - - pico_spec = body.find("div", text=PICO_RE) - if pico_spec is not None: - has_badware = True - data.append("\x02Badware:\x02" + " " + pico_spec.text) - - kms_spec = body.find("div", text=KMS_RE) - if kms_spec is not None: - has_badware = True - data.append("\x02Badware:\x02" + " " + kms_spec.text) - - booster_spec = body.find("div", text=BOOSTER_RE) - if booster_spec is not None: - has_badware = True - data.append("\x02Badware:\x02" + " " + booster_spec.text) - - reviver_spec = body.find("div", text=REVIVER_RE) - if reviver_spec is not None: - has_badware = True - data.append("\x02Badware:\x02" + " " + reviver_spec.text) - - killer_spec = body.find("div", text=KILLER_RE) - if killer_spec is not None: - has_badware = True - data.append("\x02Badware:\x02" + " " + killer_spec.text) - - if not has_badware: + badware_patterns = [KILLER_RE, REVIVER_RE, BOOSTER_RE, KMS_RE, PICO_RE] + badware = body.find_all("div", text=badware_patterns) + if badware: + for tag in badware: + data.append("\x02Badware:\x02" + " " + tag.text) + else: data.append("\x02No Badware\x02") def smartcheck(): - drive__spec = body.find_all("div", class_="blue clear", text="05") - drive_spec_SMART_checked = body.find("div", class_="blue clear", text="05") - if drive_spec_SMART_checked is not None: + drive_spec = body.find_all("div", class_="blue clear", text="05") + if drive_spec is not None: values = [] - for i, found in enumerate(drive__spec): + for i, found in enumerate(drive_spec): drives = found.next_sibling.next_sibling.stripped_strings SMART = list(drives) rv_index = SMART.index("Raw Value:") diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ new file mode 100644 index 000000000..b6c3eef07 --- /dev/null +++ b/plugins/speccy.py~ @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- + +from cloudbot import hook + +import re +import requests + +from bs4 import BeautifulSoup as BS +from contextlib import closing + +url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) + +GPU_RE = re.compile('.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) +PICO_RE = re.compile('.*pico', re.I) +KMS_RE = re.compile('.*kms', re.I) +BOOSTER_RE = re.compile('.*booster', re.I) +REVIVER_RE = re.compile('.*reviver', re.I) +KILLER_RE = re.compile('.*killer.+service', re.I) + + +@hook.regex(url_re) +def get_speccy_url(match): + + with closing(requests.get(match.group(), )) as response: + soup = BS(response.content, "lxml", from_encoding=response.encoding) + + body = soup.body + + data = [] + + os_spec = body.find("div", text='Operating System') + if os_spec is not None: + data.append( + "\x02OS:\x02" + " " + os_spec.next_sibling.next_sibling.text) + + def cspace(): + c_space_spec = body.find("div", class_="datavalue", text='C:') + if c_space_spec is not None: + c_space_spec_found = c_space_spec.parent.parent + c_space_data = c_space_spec_found.find("div", text='Free Space:\xA0', class_="datakey").parent + return c_space_data.find(class_="datavalue").text + + c_space_spec = cspace() + if c_space_spec is not None: + data.append("\x02Space Left (C:\):\x02" + " " + c_space_spec) + + ram_spec = body.find("div", text='RAM') + if ram_spec is not None: + data.append( + "\x02RAM:\x02" + " " + ram_spec.next_sibling.next_sibling.text) + + def ramusg(): + ram_usg_spec = body.find("div", class_="blue clear", text='Physical ramory') + if ram_usg_spec is not None: + ram_usg_spec_found = ram_usg_spec.next_sibling.next_sibling + ram_usg_data = ram_usg_spec_found.find("div", text='Memory Usage:\xA0', class_="datakey").parent + return ram_usg_data.find(class_="datavalue").text + + ram_usg_spec = ramusg() + if ram_usg_spec is not None: + data.append("\x02RAM USG:\x02" + " " + ram_usg_spec) + + cpu_spec = body.find("div", text='CPU') + if cpu_spec is not None: + data.append( + "\x02CPU:\x02" + " " + cpu_spec.next_sibling.next_sibling.text) + + def gpuspec(): + gpu_find = body.find("div", text='Graphics') + if gpu_find is not None: + gpu_find = gpu_find.next_sibling.next_sibling.text + gpu_spec = "" + for gpu_string in GPU_RE.finditer(gpu_find): + gpu_spec += gpu_string.group() + return gpu_spec + + gpu_spec = gpuspec() + if gpu_spec is not None: + data.append("\x02GPU:\x02" + " " + gpu_spec) + + badware_patterns = [KILLER_RE, REVIVER_RE, BOOSTER_RE, KMS_RE, PICO_RE] + badware = body.find_all("div", text=badware_patterns) + if badware: + for tag in badware: + data.append("\x02Badware:\x02" + " " + tag.text) + else: + data.append("\x02No Badware\x02") + + def smartcheck(): + drive_spec = body.find_all("div", class_="blue clear", text="05") + drive_spec_SMART_checked = body.find("div", class_="blue clear", text="05") + if drive_spec_SMART_checked is not None: + values = [] + for i, found in enumerate(drive_spec): + drives = found.next_sibling.next_sibling.stripped_strings + SMART = list(drives) + rv_index = SMART.index("Raw Value:") + raw_value = SMART[rv_index + 1] + if raw_value != "0000000000": + values.append(str(i + 1)) + return values + + drives = smartcheck() + if drives is not None: + for item in drives: + data.append("\x02Bad Disk:\x02 #{}".format(item)) + else: + data.append("\x02Disks Healthy\x02") + + spec_out = re.sub(r"\s+", " ", ' ● '.join(data)) + + return spec_out From 288f03db91730906a0dc88a89e68a16fd6535471 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sat, 3 Mar 2018 22:21:38 -0500 Subject: [PATCH 29/33] hmm, didn't sync --- plugins/speccy.py~ | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ index b6c3eef07..f32043989 100644 --- a/plugins/speccy.py~ +++ b/plugins/speccy.py~ @@ -88,8 +88,7 @@ def get_speccy_url(match): def smartcheck(): drive_spec = body.find_all("div", class_="blue clear", text="05") - drive_spec_SMART_checked = body.find("div", class_="blue clear", text="05") - if drive_spec_SMART_checked is not None: + if drive_spec is not None: values = [] for i, found in enumerate(drive_spec): drives = found.next_sibling.next_sibling.stripped_strings From b10c6b02595a24ecc9b9fafe00c20045192a5207 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sat, 3 Mar 2018 22:23:51 -0500 Subject: [PATCH 30/33] stupid gedit auto-backup --- plugins/speccy.py~ | 111 --------------------------------------------- 1 file changed, 111 deletions(-) delete mode 100644 plugins/speccy.py~ diff --git a/plugins/speccy.py~ b/plugins/speccy.py~ deleted file mode 100644 index f32043989..000000000 --- a/plugins/speccy.py~ +++ /dev/null @@ -1,111 +0,0 @@ -# -*- coding: utf-8 -*- - -from cloudbot import hook - -import re -import requests - -from bs4 import BeautifulSoup as BS -from contextlib import closing - -url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) - -GPU_RE = re.compile('.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) -PICO_RE = re.compile('.*pico', re.I) -KMS_RE = re.compile('.*kms', re.I) -BOOSTER_RE = re.compile('.*booster', re.I) -REVIVER_RE = re.compile('.*reviver', re.I) -KILLER_RE = re.compile('.*killer.+service', re.I) - - -@hook.regex(url_re) -def get_speccy_url(match): - - with closing(requests.get(match.group(), )) as response: - soup = BS(response.content, "lxml", from_encoding=response.encoding) - - body = soup.body - - data = [] - - os_spec = body.find("div", text='Operating System') - if os_spec is not None: - data.append( - "\x02OS:\x02" + " " + os_spec.next_sibling.next_sibling.text) - - def cspace(): - c_space_spec = body.find("div", class_="datavalue", text='C:') - if c_space_spec is not None: - c_space_spec_found = c_space_spec.parent.parent - c_space_data = c_space_spec_found.find("div", text='Free Space:\xA0', class_="datakey").parent - return c_space_data.find(class_="datavalue").text - - c_space_spec = cspace() - if c_space_spec is not None: - data.append("\x02Space Left (C:\):\x02" + " " + c_space_spec) - - ram_spec = body.find("div", text='RAM') - if ram_spec is not None: - data.append( - "\x02RAM:\x02" + " " + ram_spec.next_sibling.next_sibling.text) - - def ramusg(): - ram_usg_spec = body.find("div", class_="blue clear", text='Physical ramory') - if ram_usg_spec is not None: - ram_usg_spec_found = ram_usg_spec.next_sibling.next_sibling - ram_usg_data = ram_usg_spec_found.find("div", text='Memory Usage:\xA0', class_="datakey").parent - return ram_usg_data.find(class_="datavalue").text - - ram_usg_spec = ramusg() - if ram_usg_spec is not None: - data.append("\x02RAM USG:\x02" + " " + ram_usg_spec) - - cpu_spec = body.find("div", text='CPU') - if cpu_spec is not None: - data.append( - "\x02CPU:\x02" + " " + cpu_spec.next_sibling.next_sibling.text) - - def gpuspec(): - gpu_find = body.find("div", text='Graphics') - if gpu_find is not None: - gpu_find = gpu_find.next_sibling.next_sibling.text - gpu_spec = "" - for gpu_string in GPU_RE.finditer(gpu_find): - gpu_spec += gpu_string.group() - return gpu_spec - - gpu_spec = gpuspec() - if gpu_spec is not None: - data.append("\x02GPU:\x02" + " " + gpu_spec) - - badware_patterns = [KILLER_RE, REVIVER_RE, BOOSTER_RE, KMS_RE, PICO_RE] - badware = body.find_all("div", text=badware_patterns) - if badware: - for tag in badware: - data.append("\x02Badware:\x02" + " " + tag.text) - else: - data.append("\x02No Badware\x02") - - def smartcheck(): - drive_spec = body.find_all("div", class_="blue clear", text="05") - if drive_spec is not None: - values = [] - for i, found in enumerate(drive_spec): - drives = found.next_sibling.next_sibling.stripped_strings - SMART = list(drives) - rv_index = SMART.index("Raw Value:") - raw_value = SMART[rv_index + 1] - if raw_value != "0000000000": - values.append(str(i + 1)) - return values - - drives = smartcheck() - if drives is not None: - for item in drives: - data.append("\x02Bad Disk:\x02 #{}".format(item)) - else: - data.append("\x02Disks Healthy\x02") - - spec_out = re.sub(r"\s+", " ", ' ● '.join(data)) - - return spec_out From 948789483c31ca276de29b3b07e883309e444cf5 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sat, 3 Mar 2018 22:58:15 -0500 Subject: [PATCH 31/33] small change to smartcheck --- plugins/speccy.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index f32043989..31958766a 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -89,15 +89,14 @@ def gpuspec(): def smartcheck(): drive_spec = body.find_all("div", class_="blue clear", text="05") if drive_spec is not None: - values = [] for i, found in enumerate(drive_spec): drives = found.next_sibling.next_sibling.stripped_strings SMART = list(drives) rv_index = SMART.index("Raw Value:") raw_value = SMART[rv_index + 1] if raw_value != "0000000000": - values.append(str(i + 1)) - return values + raw_value = (str(i + 1)) + return raw_value drives = smartcheck() if drives is not None: From 196a1b5c55fd780a436ac47007e0d73f19487631 Mon Sep 17 00:00:00 2001 From: Jessexd Date: Sun, 4 Mar 2018 12:37:50 -0500 Subject: [PATCH 32/33] Typo --- plugins/speccy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 31958766a..580addddd 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -50,7 +50,7 @@ def cspace(): "\x02RAM:\x02" + " " + ram_spec.next_sibling.next_sibling.text) def ramusg(): - ram_usg_spec = body.find("div", class_="blue clear", text='Physical ramory') + ram_usg_spec = body.find("div", class_="blue clear", text='Physical Memory') if ram_usg_spec is not None: ram_usg_spec_found = ram_usg_spec.next_sibling.next_sibling ram_usg_data = ram_usg_spec_found.find("div", text='Memory Usage:\xA0', class_="datakey").parent From 1b73957fe2da5d61bda475ed84840244e9d45d0a Mon Sep 17 00:00:00 2001 From: Jessexd Date: Wed, 7 Mar 2018 11:04:07 -0500 Subject: [PATCH 33/33] Overhauled smartcheck, re-ordered output format, little bit more redable. --- plugins/speccy.py | 118 ++++++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 47 deletions(-) diff --git a/plugins/speccy.py b/plugins/speccy.py index 580addddd..d5ec04c76 100644 --- a/plugins/speccy.py +++ b/plugins/speccy.py @@ -8,14 +8,27 @@ from bs4 import BeautifulSoup as BS from contextlib import closing -url_re = re.compile('https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) - -GPU_RE = re.compile('.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) -PICO_RE = re.compile('.*pico', re.I) -KMS_RE = re.compile('.*kms', re.I) -BOOSTER_RE = re.compile('.*booster', re.I) -REVIVER_RE = re.compile('.*reviver', re.I) -KILLER_RE = re.compile('.*killer.+service', re.I) +url_re = \ + re.compile( + 'https?:\/\/speccy\.piriform\.com\/results\/[a-zA-Z0-9]+', re.I) +GPU_RE = \ + re.compile( + '.*(amd|radeon|intel|integrated|nvidia|geforce|gtx).*\n.*', re.I) +PICO_RE = \ + re.compile( + '.*pico', re.I) +KMS_RE = \ + re.compile( + '.*kms', re.I) +BOOSTER_RE = \ + re.compile( + '.*booster', re.I) +REVIVER_RE = \ + re.compile( + '.*reviver', re.I) +KILLER_RE = \ + re.compile( + '.*killer.+service', re.I) @hook.regex(url_re) @@ -33,33 +46,11 @@ def get_speccy_url(match): data.append( "\x02OS:\x02" + " " + os_spec.next_sibling.next_sibling.text) - def cspace(): - c_space_spec = body.find("div", class_="datavalue", text='C:') - if c_space_spec is not None: - c_space_spec_found = c_space_spec.parent.parent - c_space_data = c_space_spec_found.find("div", text='Free Space:\xA0', class_="datakey").parent - return c_space_data.find(class_="datavalue").text - - c_space_spec = cspace() - if c_space_spec is not None: - data.append("\x02Space Left (C:\):\x02" + " " + c_space_spec) - ram_spec = body.find("div", text='RAM') if ram_spec is not None: data.append( "\x02RAM:\x02" + " " + ram_spec.next_sibling.next_sibling.text) - def ramusg(): - ram_usg_spec = body.find("div", class_="blue clear", text='Physical Memory') - if ram_usg_spec is not None: - ram_usg_spec_found = ram_usg_spec.next_sibling.next_sibling - ram_usg_data = ram_usg_spec_found.find("div", text='Memory Usage:\xA0', class_="datakey").parent - return ram_usg_data.find(class_="datavalue").text - - ram_usg_spec = ramusg() - if ram_usg_spec is not None: - data.append("\x02RAM USG:\x02" + " " + ram_usg_spec) - cpu_spec = body.find("div", text='CPU') if cpu_spec is not None: data.append( @@ -78,6 +69,31 @@ def gpuspec(): if gpu_spec is not None: data.append("\x02GPU:\x02" + " " + gpu_spec) + def cspace(): + c_space_spec = body.find("div", class_="datavalue", text='C:') + if c_space_spec is not None: + c_space_spec_found = c_space_spec.parent.parent + c_space_data = c_space_spec_found.find( + "div", text='Free Space:\xA0', class_="datakey").parent + return c_space_data.find(class_="datavalue").text + + c_space_spec = cspace() + if c_space_spec is not None: + data.append("\x02Space Left (C:\):\x02" + " " + c_space_spec) + + def ramusg(): + ram_usg_spec = body.find( + "div", class_="blue clear", text='Physical Memory') + if ram_usg_spec is not None: + ram_usg_spec_found = ram_usg_spec.next_sibling.next_sibling + ram_usg_data = ram_usg_spec_found.find( + "div", text='Memory Usage:\xA0', class_="datakey").parent + return ram_usg_data.find(class_="datavalue").text + + ram_usg_spec = ramusg() + if ram_usg_spec is not None: + data.append("\x02RAM USG:\x02" + " " + ram_usg_spec) + badware_patterns = [KILLER_RE, REVIVER_RE, BOOSTER_RE, KMS_RE, PICO_RE] badware = body.find_all("div", text=badware_patterns) if badware: @@ -86,23 +102,31 @@ def gpuspec(): else: data.append("\x02No Badware\x02") - def smartcheck(): - drive_spec = body.find_all("div", class_="blue clear", text="05") - if drive_spec is not None: - for i, found in enumerate(drive_spec): - drives = found.next_sibling.next_sibling.stripped_strings - SMART = list(drives) - rv_index = SMART.index("Raw Value:") - raw_value = SMART[rv_index + 1] - if raw_value != "0000000000": - raw_value = (str(i + 1)) - return raw_value - - drives = smartcheck() - if drives is not None: - for item in drives: - data.append("\x02Bad Disk:\x02 #{}".format(item)) - else: + drive_spec_bad = False + for drive_spec_smart in body.find_all( + "div", class_="blue clear", text="05"): + drive_spec_smart_find = \ + drive_spec_smart.next_sibling.next_sibling + for drive_spec_smart_found in drive_spec_smart_find.find_all( + "div", class_="datakey", text="Raw Value:\xA0"): + drives = drive_spec_smart_found.next_sibling.next_sibling + if "0000000000" in drives != 0: + str.strip('0') + else: + drive_spec_sn_find = drive_spec_smart.parent.parent \ + .previous_sibling.previous_sibling.previous_sibling \ + .previous_sibling.previous_element.previous_element \ + .previous_sibling.previous_sibling + for drive_spec_sn_check in drive_spec_sn_find.find_all( + "div", class_="datakey", text="Serial Number:\xA0"): + drive_spec_sn = \ + drive_spec_sn_check.next_sibling.next_sibling.text + drive_spec_bad = True + if drive_spec_bad is True: + data.append( + "\x02Bad Disk:\x02 S/N: {}".format(drive_spec_sn)) + + if drive_spec_bad is False: data.append("\x02Disks Healthy\x02") spec_out = re.sub(r"\s+", " ", ' ● '.join(data))