def test_ca_tokens(self): results = API("ca").retrieve_all() for part, part_data in results.items(): for p in part_data: self.assertIsInstance(p, part_classes[part]) self.assertIsNotNone(p.brand) self.assertIsNotNone(results.to_json())
def test_api_modify_multithreading(self): api = API() self.assertTrue(api.multithreading) self.assertTrue(api._handler._multithreading) api.set_multithreading(False) self.assertFalse(api._handler._multithreading) self.assertFalse(api.multithreading) api.set_multithreading(True) self.assertTrue(api.multithreading) self.assertTrue(api._handler._multithreading)
def __init__(self): self.api = API() self.raw_data = [ self.api.retrieve("cpu"), self.api.retrieve("video-card"), self.api.retrieve("power-supply"), self.api.retrieve("memory"), self.api.retrieve("motherboard"), self.api.retrieve("internal-hard-drive"), self.api.retrieve("case") ]
def test_api_default_init(self): api = API() self.assertEqual(api.region, "us") self.assertEqual(api.supported_parts, {"cpu", "cpu-cooler", "motherboard", "memory", "internal-hard-drive", "video-card", "power-supply", "case", "case-fan", "fan-controller", "thermal-paste", "optical-drive", "sound-card", "wired-network-card", "wireless-network-card", "monitor", "external-hard-drive", "headphones", "keyboard", "mouse", "speakers", "ups"}) self.assertEqual(api.supported_regions, {"au", "be", "ca", "de", "es", "fr", "se", "in", "ie", "it", "nz", "uk", "us"}) self.assertEqual(api.region, 'us')
def test_api_multithreading_kwd(self): api = API(multithreading=False) self.assertFalse(api.multithreading) self.assertFalse(api._handler.multithreading)
def test_api_set_region_incorrect_region(self): with self.assertRaises(UnsupportedRegion) as excinfo: api = API() api.set_region('oc') assert 'Region \'oc\' is not supported for this API!' in str( excinfo.exception)
def test_api_set_region(self): api = API() self.assertEqual(api.region, 'us') api.set_region('nz') self.assertEqual(api.region, 'nz')
def test_api_init_exception(self): with self.assertRaises(UnsupportedRegion) as excinfo: _ = API('oc') assert 'Region \'oc\' is not supported for this API!' in str( excinfo.exception)
def test_api_region_init(self): api = API('de') self.assertEqual(api.region, 'de')
mode = "both" # cpu, gpu, both priceSource = "ul" # pcpp, ul cpuBlacklists = re.compile(r'i[3-9]-[2-9]|i[3-9]-\d{3}$|FX-|Xeon') gpuBlacklists = re.compile( r'Quadro|GT |HD |GTX [3-9]|R[5-9]|Titan|GTX 10|RX 4') colorMap = { 'AMD': 'rgb(255, 65, 54)', 'Intel': 'rgb(93, 164, 214)', 'Nvidia': 'rgb(44, 160, 101)' } os.chdir(os.path.dirname(os.path.realpath(__file__))) print(os.path.abspath(".")) api = API() date = datetime.today().strftime('%Y-%m-%d') if mode != "gpu": if scrapeWeb: try: os.remove('ulCPU.json') except OSError: pass os.system('scrapy crawl ulCPU -o ulCPU.json') if priceSource == "pcpp": cpu_data = api.retrieve("cpu") pcppCPUs = {} print(len(cpu_data["cpu"]), "pcpartpicker cpus") print(cpu_data["cpu"][0])
from pcpartpicker import API import pandas as pd import numpy as np api = API(multithreading=False) api.set_region('in') df = api.retrieve('cpu')['cpu'] new = [] for obj in df: new.append({'brand': obj.brand if obj.brand else np.nan, 'model': obj.model if obj.model else np.nan, 'cores': obj.cores if obj.cores else np.nan, 'base_clock': obj.base_clock.cycles if obj.base_clock else np.nan, 'boost_clock': obj.base_clock.cycles if obj.boost_clock else np.nan, 'tdp': obj.tdp if obj.tdp else np.nan, 'integrated_graphics': np.nan if obj.integrated_graphics is None else obj.integrated_graphics, 'multithreading': np.nan if obj.multithreading is None else obj.multithreading}) new_df = pd.DataFrame(new) new_df.to_csv('pcpp-cpu.csv', index=False)
def parserTest(cls): base_api = API() cls.test_data = {} for region in base_api.supported_regions: api = API(region) cls.test_data.update({region: api.retrieve_all()})
from pcpartpicker import API import json from PCDatabase import PCDatabase api = API('us') data = {} dataEntity = { 'cpu': ['brand', 'model', 'cores', 'tdp', 'integrated_graphics'], 'motherboard': ['brand', 'model', 'socket', 'form_factor', 'ram_slots', 'max_ram'], 'internal-hard-drive': ['brand', 'model', 'capacity', 'storage_type', 'form_factor'], 'video-card': ['brand', 'model', 'chipset', 'vram'], 'power-supply': ['brand', 'model', 'form_factor', 'wattage'], 'monitor': ['brand', 'model', 'size', 'resolution', 'refresh_rate', 'panel_type'], 'case': ['brand', 'model', 'form_factor', 'external_bays', 'internal_bays'], 'memory': ['brand', 'model', 'module_type', 'speed'] } tableName = { 'cpu': 'cpus', 'motherboard': 'motherboards', 'internal-hard-drive': 'internalharddrives', 'video-card': 'videocards', 'power-supply': 'powersupplies', 'monitor': 'monitors', 'case': 'casepcs', 'memory': 'memories' }
def __init__(self, database: str): self._connection = sqlite3.connect(database) self._api = API()
def __init__(self, debug=False, region='us'): self.pcpp_api = API(region) self.parts = {} self.path = './Parts_Scraper/pickle/' log.debug("PCParts object init")