Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

New module, speccy.py #208

Open
wants to merge 43 commits into
base: gonzobot
Choose a base branch
from
Open
Changes from 29 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7f19215
Add speccy module
Feb 12, 2018
e4adf75
Add XTU and Reviver
Feb 12, 2018
ef2487f
Fixed SMART formatting
Feb 12, 2018
3ed293c
tons of shit
Jessexd Feb 13, 2018
f46eabb
Formatting fixes
Feb 13, 2018
cec4812
Merge branch 'speccy' into speccy
Jessexd Feb 13, 2018
31aae3d
An actual commit
Jessexd Feb 15, 2018
f2d3c28
Fixed
Jessexd Feb 15, 2018
4245df6
Merge branch 'speccy' of https://github.com/Jessexd/CloudBot into speccy
Jessexd Feb 15, 2018
07e8a30
Merge pull request #2 from Jessexd/speccy
Feb 15, 2018
efceb1d
greatly optmized, much less CPU ussage, reformatted as per PEP8 requi…
Jessexd Feb 16, 2018
42e876d
Merge pull request #3 from Jessexd/speccy
Feb 17, 2018
dc2480a
code readability
Jessexd Feb 17, 2018
48d1711
:O
Jessexd Feb 18, 2018
bafcc32
fixed due to reviewers requested changes
Jessexd Feb 19, 2018
ee495da
added GPU_RE to the be with the other globally defined regex
Jessexd Feb 19, 2018
fb17d50
made variable names less vague and generic, disregardded pep8 line le…
Jessexd Feb 19, 2018
c977e3c
removed useless r in GPU_RE regex since others weren't like that.
Jessexd Feb 19, 2018
d49eb27
Changed Bad: to Badware: (makes it less generic of what "bad" is)
Jessexd Feb 19, 2018
601e599
removed "# -*- coding: utf-8 -*-"
Jessexd Feb 20, 2018
9d2d695
removed repeatedly calling __getitem__ on the list. (for drivespec)
Jessexd Feb 20, 2018
cadcfa4
added back "# -*- coding: utf-8 -*-" because I'm a moron
Jessexd Feb 20, 2018
efa4758
Ooops, removed the cloudbot hook on accident, WOW
Jessexd Feb 20, 2018
bf3cb84
removal of cached speccy.py file
Jessexd Feb 20, 2018
1ca2b0b
Merge pull request #5 from Jessexd/speccy
Feb 20, 2018
dc5a781
Update requirements.txt
Jessexd Feb 22, 2018
60cefc9
Implemented checks so it doesn't error out the plugin, added undersco…
Jessexd Feb 28, 2018
55bcc6c
Added checking ability, shouldn't return nothing in the chat upon err…
Jessexd Mar 1, 2018
1a2d613
small confusing naming I had going
Jessexd Mar 1, 2018
ec039fc
Merge pull request #6 from Jessexd/speccy
Mar 1, 2018
a0baf00
Badware checking was broken, fixed
Jessexd Mar 1, 2018
6ee430c
oops
Jessexd Mar 1, 2018
c211e9a
issue with when badware not found, blabla
Jessexd Mar 4, 2018
4725b3f
smalll wooopsy from the drivespec code (duplicated 2 variables with 1…
Jessexd Mar 4, 2018
288f03d
hmm, didn't sync
Jessexd Mar 4, 2018
b10c6b0
stupid gedit auto-backup
Jessexd Mar 4, 2018
9487894
small change to smartcheck
Jessexd Mar 4, 2018
196a1b5
Typo
Jessexd Mar 4, 2018
1b73957
Overhauled smartcheck, re-ordered output format, little bit more reda…
Jessexd Mar 7, 2018
241abb2
Merge remote-tracking branch 'upstream/speccy' into speccy
Jessexd Mar 7, 2018
77123d9
Merge branch 'gonzobot' into speccy
linuxdaemon Mar 12, 2018
2dcd32a
Merge branch 'gonzobot' into speccy
linuxdaemon Mar 24, 2018
a739caa
Merge branch 'gonzobot' into speccy
linuxdaemon Jun 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions plugins/speccy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# -*- 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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous whitespace

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't pinpoint what you see, as again, it's since been the same many revisions ago.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the extra line after the def line. I just didn't catch it in earlier reviews.

with closing(requests.get(match.group(), )) as response:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous comma and whitespace

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you're referring to, these 4 lines have been the same since many reviewed (by you) revisions ago.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'm referring to the comma and space after match.group()

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three if block could most likely be generalized to a function call since they are almost exactly the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll compress that too.


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 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the badware logic could probably be collapsed to something like

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")

Rather than duplicating the code. Then any new Badware patterns just need to be added to that list, and that list could even be defined with the rest of the regexs like:

BADWARE_PATTERNS = [...]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, lots better


if not has_badware:
data.append("\x02No Badware\x02")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be easier to just set a variable like has_badware = False and set that to True whenever you find something that's considered badware.


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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this .find() duplicated?

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why even use values here if you just return the first thing you find?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


drives = smartcheck()
if drives is not None:
for item in drives:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drives will always be a string or None here, as you changed how smartcheck() works. If you want to get info for multiple drives, you'll need to change the logic in smartcheck()

data.append("\x02Bad Disk:\x02 #{}".format(item))
else:
data.append("\x02Disks Healthy\x02")

spec_out = re.sub(r"\s+", " ", ' ● '.join(data))

return spec_out