Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part search by type for "cpu" returns results for "cpu_cooler" #29

Open
CoderStylus opened this issue Dec 28, 2024 · 1 comment
Open

Comments

@CoderStylus
Copy link
Contributor

When getting a part with type cpu, the resulting product that is returned is a CPU Cooler. As you can see, with the following test program:

**PYTHON**

import pypartpicker
import time

# Supported Product Types (from the documentation)
# PRODUCT_TYPES = [
#     "keyboard", "speakers", "monitor", "thermal-paste", "video-card",
#     "case-fan", "os", "cpu-cooler", "fan-controller", "ups",
#     "wired-network-card", "memory", "headphones", "sound-card",
#     "internal-hard-drive", "mouse", "wireless-network-card", "power-supply",
#     "webcam", "motherboard", "external-hard-drive", "optical-drive", "case", "CPU"
# ]

PRODUCT_TYPES = [
    "cpu", "cpu-cooler"
]

# Initialize PyPartPicker Client
pcpp = pypartpicker.Client()

# Iterate through each product type and fetch top result
def fetch_top_parts():
    for product in PRODUCT_TYPES:
        try:
            result = pcpp.get_part_search(product, page=1, region="au")  # Region can be changed
            
            if result.parts:
                part_summary = result.parts[0]  # Get the top result (first part summary)
                part = pcpp.get_part(part_summary.url)  # Fetch full part details using URL
                
                # Print part details
                print("-" * 40)
                print(f"Part Type: {product}")
                print(f"Name: {part.name}")
                if part.cheapest_price:
                    print(f"Price: {part.cheapest_price.total} {part.cheapest_price.currency}")
                if part.vendors:
                    vendor = part.vendors[0]
                    print(f"Store: {vendor.name}")
                    print(f"Store URL: {vendor.buy_url}")
                print(f"Product URL: {part.url}")
                
                if part.image_urls:
                    print("Image URLs:")
                    for img_url in part.image_urls:
                        print(f"  {img_url}")
                
                if part.specs:
                    print("Specs:")
                    for spec, value in part.specs.items():
                        print(f"  {spec}: {value}")
                else:
                    print("No specs available.")

                print("-" * 40)  # Separator between products
            else:
                print("-" * 40)
                print(f"No results for {product}")
                print("-" * 40)
        except Exception as e:
            print(f"Error: {e}")
        
        # time.sleep(2)  # Delay to prevent being blocked by the server

if __name__ == "__main__":
    fetch_top_parts()

The results for "cpu" and "cpu-cooler" are the exact same in the output:

**COMMAND LINE**

py index.py

----------------------------------------
Part Type: cpu
Name: Thermalright Peerless Assassin 120 SE 66.17 CFM CPU Cooler
Price: 59.0 $
Store: Scorptec
Store URL: https://www.scorptec.com.au/product/cooling/cpu-coolers/104893-peerless-assassin-120-se
Product URL: https://au.pcpartpicker.com/product/hYxRsY
Image URLs:
  https:https://m.media-amazon.com/images/I/41hFTmi5aUL.jpg
Specs:
  Manufacturer: Thermalright
  Model: Peerless Assassin 120 SE
  Part #: PA120 SE-D3
PA120 SE
PA120 SE D6-CAD
PA120 SE 1700
PA120 SE 1700-d6
419043
  Fan RPM: 1550 RPM
  Noise Level: 25.6 dB
  Color: Black / Silver
  Height: 155 mm
  CPU Socket: AM4
AM5
LGA1150
LGA1151
LGA1155
LGA1156
LGA1200
LGA1700
LGA1851
  Water Cooled: No
  Fanless: No
----------------------------------------
----------------------------------------
Part Type: cpu-cooler
Name: Thermalright Peerless Assassin 120 SE 66.17 CFM CPU Cooler
Price: 59.0 $
Store: Scorptec
Store URL: https://www.scorptec.com.au/product/cooling/cpu-coolers/104893-peerless-assassin-120-se
Product URL: https://au.pcpartpicker.com/product/hYxRsY
Image URLs:
  https:https://m.media-amazon.com/images/I/41hFTmi5aUL.jpg
Specs:
  Manufacturer: Thermalright
  Model: Peerless Assassin 120 SE
  Part #: PA120 SE-D3
PA120 SE
PA120 SE D6-CAD
PA120 SE 1700
PA120 SE 1700-d6
419043
  Fan RPM: 1550 RPM
  Noise Level: 25.6 dB
  Color: Black / Silver
  Height: 155 mm
  CPU Socket: AM4
AM5
LGA1150
LGA1151
LGA1155
LGA1156
LGA1200
LGA1700
LGA1851
  Water Cooled: No
  Fanless: No
----------------------------------------
@thefakequake
Copy link
Owner

thefakequake commented Dec 28, 2024

The get_part_search method uses PCPP's search functionality which simply does a text search. This means that parts with "cpu cooler" in the title come up when searching for "cpu". PCPP appends "processor" to CPU names, so try searching for "processor" instead.

I am working on a dedicated method to search directly for part types, this will use the constants defined in the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants