-
Notifications
You must be signed in to change notification settings - Fork 52
New module, speccy.py #208
base: gonzobot
Are you sure you want to change the base?
Changes from 28 commits
7f19215
e4adf75
ef2487f
3ed293c
f46eabb
cec4812
31aae3d
f2d3c28
4245df6
07e8a30
efceb1d
42e876d
dc2480a
48d1711
bafcc32
ee495da
fb17d50
c977e3c
d49eb27
601e599
9d2d695
cadcfa4
efa4758
bf3cb84
1ca2b0b
dc5a781
60cefc9
55bcc6c
1a2d613
ec039fc
a0baf00
6ee430c
c211e9a
4725b3f
288f03d
b10c6b0
9487894
196a1b5
1b73957
241abb2
77123d9
2dcd32a
a739caa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# -*- 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extraneous comma and whitespace There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I'm referring to the comma and space after |
||
soup = BS(response.content, "lxml", from_encoding=response.encoding) | ||
|
||
body = soup.body | ||
|
||
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( | ||
"\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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is supposed to be |
||
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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid repeatedly calling a function like this. It would be better to assign it to a variable before the check. |
||
|
||
ram_spec = body.find("div", text='RAM') | ||
if ram_spec: | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
if ram_usg_spec: | ||
data.append("\x02RAM Usg:\x02" + " " + ram_usg_spec) | ||
|
||
cpu_spec = body.find("div", text='CPU') | ||
if cpu_spec: | ||
data.append( | ||
"\x02CPU:\x02" + " " + cpu_spec.next_sibling.next_sibling.text) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These three There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll compress that too. |
||
|
||
gpu_find = body.find("div", text='Graphics').next_sibling.next_sibling.text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should do a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify/correct what you mean? In this one snippet it's including code for CPU and GPU. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments apply to the line directly above them, so in this case |
||
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) | ||
|
||
pico_spec = body.find("div", text=PICO_RE) | ||
if pico_spec: | ||
data.append("\x02Badware:\x02" + " " + pico_spec.text) | ||
|
||
kms_spec = body.find("div", text=KMS_RE) | ||
if kms_spec: | ||
data.append("\x02Badware:\x02" + " " + kms_spec.text) | ||
|
||
booster_spec = body.find("div", text=BOOSTER_RE) | ||
if booster_spec: | ||
data.append("\x02Badware:\x02" + " " + booster_spec.text) | ||
|
||
reviver_spec = body.find("div", text=REVIVER_RE) | ||
if reviver_spec: | ||
data.append("\x02Badware:\x02" + " " + reviver_spec.text) | ||
|
||
killer_spec = body.find("div", text=KILLER_RE) | ||
if killer_spec: | ||
data.append("\x02Badware:\x02" + " " + killer_spec.text) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = [...] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, lots better |
||
|
||
if 'Badware' not in specout(): | ||
data.append("\x02No Badware\x02") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be easier to just set a variable like |
||
|
||
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: | ||
for item in drives: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
data.append("\x02Bad Disk:\x02 #{}".format(item)) | ||
else: | ||
data.append("\x02Disks Healthy\x02") | ||
|
||
specout = re.sub(r"\s+", " ", ' ● '.join(data)) | ||
|
||
return specout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extraneous whitespace
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.