pypartpicker2


Namepypartpicker2 JSON
Version 0.1.9 PyPI version JSON
download
home_pagehttps://github.com/giuseppe99barchetta/pypartpicker
SummaryA package that scrapes pcpartpicker.com and returns the results as objects.
upload_time2024-07-11 12:45:07
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords pcpartpicker scraper list beautifulsoup pc parts
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyPartPicker

#### PyPartPicker is a package that allows you to obtain information from PCPartPicker quickly and easily, with data being returned via objects with numerous attributes.

---
### Features:
- Obtain Part objects, estimated wattage and total cost from PCPartPicker lists.
- Obtain name, product URL, price, product type, image and more from Part objects.
- Obtain everything previously mentioned + specs, reviews and in depth pricing information from PCPartPicker product links.
- Async ready: all scraping methods have an asynchronous version


# Installation

---
Installation via pip:
```
>>> pip install pypartpicker2
```
Or clone the repo directly:
```
>>> git clone https://github.com/giuseppe99barchetta/pypartpicker2.git
```
# Example programs

---

Here is a program that searches for i7's, prints every result, then gets the first result and prints its specs:
```python
from pypartpicker2  import Scraper

# creates the scraper object
pcpp = Scraper()
# returns a list of Part objects we can iterate through
parts = pcpp.part_search("i7")

# iterates through every part object
for part in parts:
    # prints the name of the part
    print(part.name)

# gets the first product and fetches its URL
first_product_url = parts[0].url
# gets the Product object for the item
product = pcpp.fetch_product(first_product_url)
# prints the product's specs using the specs attribute
print(product.specs)
```
Here is another program that finds i3s that are cheaper than or equal to £110, prints their specs and then prints the first review:
```python
from pypartpicker2 import Scraper
from time import sleep

# returns a list of Part objects we can iterate through
# the region is set to "uk" so that we get prices in GBP
pcpp = Scraper()
parts = pcpp.part_search("i3", region="uk")

# iterates through the parts
for part in parts:
    # checks if the price is lower than 110
    if float(part.price.strip("£")) <= 110:
        print(f"I found a valid product: {part.name}")
        print(f"Here is the link: {part.url}")
        # gets the product object for the parts
        product = pcpp.fetch_product(part.url)
        print(product.specs)
        # makes sure the product has reviews
        if product.reviews != None:
            # gets the first review
            review = product.reviews[0]
            print(f"Posted by {review.author}: {review.content}")
            print(f"They rated this product {review.rating}/5.")
        else:
            print("There are no reviews on this product!")
            
    # slows down the program so as not to spam PCPartPicker and potentially get IP banned
    sleep(3)
```

# Creating the Scraper object

---

### `Scraper(headers={...}, response_retriever=...)`

### Parameters
- **headers** ( [dict](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) ) - The browser headers for the requests in a dict.

  Note: There are headers set by default. I only recommend changing them if you are encountering scraping errors.

- **response_retriever** ( [Callable](https://docs.python.org/3/library/typing.html#typing.Callable) ) - A function accepting arguments (`url, **kwargs`) that is called to retrieve the response from PCPartPicker

  Note: A default retriever is configured that calls pcpartpicker.com directly. I only recommend changing this if you need to configure how the request is made (e.g. via a proxy)

# Scraper Methods

---

### `Scraper.part_search(search_term, limit=20, region=None)`
#### Returns Part objects using PCPartPicker's search function.
### **Parameters**
- **search_term** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The term you want to search for.
  
    Example: `"i5"`
  

- **limit** (Optional[ [int](https://docs.python.org/3/library/functions.html#int) ]) - The amount of results that you want to be returned.
    
    Example: `limit=5`
  

- **region** (Optional[ [str](https://docs.python.org/3/library/stdtypes.html#str) ]) - The country code of which you want the pricing for the Part objects to be in. 
    
    Example: `region="uk"`
  
### Returns
A list of Part objects corresponding to the results on PCPartPicker.


---

### `Scraper.fetch_product(product_url)`
#### Returns a Product object from a PCPartPicker product URL.
### **Parameters**
- **product_url** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The product URL for the product you want to search for.
  
    Example: `"https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box"`

### Returns
A Product object for the part.

---
### `Scraper.fetch_list(list_url)`
#### Returns a PCPPLIst object from a PCPartPicker list URL.
### **Parameters**
- **list_url** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The URL for the parts list.
  
    Example: `"https://pcpartpicker.com/list/Tzx22V"`

### Returns
A PCPPList object for the list.

# Other methods

---

### `get_list_links(string)`
#### Returns a list of PCPartPicker list links from the given string.
### **Parameters**
- **string** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The string containing the parts list URL.
  
    Example: `"this function can extract the link from this string https://pcpartpicker.com/list/Tzx22V"`

### Returns
A list of URLs.

---
### `get_product_links(string)`
#### Returns a list of PCPartPicker product links from the given string.
### **Parameters**
- **string** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The string containing the product URL.
  
    Example: `"this function can extract the link from this string https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box"`

### Returns
A list of URLs.


# Async Methods
___
#### Same syntax as sync functions, but add aio_ to the beginning of the method name and add await before the function call.
#### For example:
```python
pcpp = Scraper()
results = pcpp.part_search("i5")
```

becomes

```python
pcpp = Scraper()
results = await pcpp.aio_part_search("i5")
```

Remember: you can only call async functions within other async functions. If you are not writing async code, do not use these methods. Use the sync methods, which don't have aio_ before their name.

Only the blocking functions (the ones that involve active scraping) have async equivalents.

# Objects

---
## Part
### Attributes
- `name` - The name of the part
- `url` - The product URL for the part
- `type` - The type of the part (e.g. CPU, Motherboard, Memory)
- `price` - The cheapest price for the part
- `image` - The image link for the part

---

## Product
### Attributes

- All attributes from Part
- `specs` - The specs for the product, arranged in a dictionary with the values being lists
- `price_list` - A list of Price objects containing all the merchants, prices and stock values
- `rating` - The total user ratings and average score for the product
- `reviews` - A list of Review objects for the product
- `compatible_parts` - A list of tuples containing the compatible parts links for the product

___

## Price
### Attributes

- `value` - The final price value
- `base_value` - The price value before shipping and other discounts
- `seller` - The name of the company selling the part
- `seller_icon` - The icon URL for the company selling the part
- `url` - The URL which links to the seller's product listing
- `in_stock` - A boolean of whether the product is in stock

---

## Review
### Attributes

- `author` - The name of the person who posted the review
- `author_url` - The URL which points to the author's profile
- `author_icon` - The icon URL of the person who posted the review
- `points` - The amount of upvotes on the review
- `created_at` - How long ago the review was sent
- `rating` - The star rating out of 5 of the product that the review gives
- `content` - The text content of the review

---

## PCPPList
### Attributes

- `parts` - List of Part objects corresponding to every part in the list
- `wattage` - The estimated wattage for the parts in the list
- `total` - The total price of the PCPartPicker list
- `url` - The URL of the PCPartPicker list
- `compatibility` - A list containing the compatibility notes for the parts list

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/giuseppe99barchetta/pypartpicker",
    "name": "pypartpicker2",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "pcpartpicker, scraper, list, beautifulsoup, pc, parts",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/88/89/63d0865994fe8639415efd9b96e1f4f5b74df9355208f4fc57c12727a0d0/pypartpicker2-0.1.9.tar.gz",
    "platform": null,
    "description": "# PyPartPicker\n\n#### PyPartPicker is a package that allows you to obtain information from PCPartPicker quickly and easily, with data being returned via objects with numerous attributes.\n\n---\n### Features:\n- Obtain Part objects, estimated wattage and total cost from PCPartPicker lists.\n- Obtain name, product URL, price, product type, image and more from Part objects.\n- Obtain everything previously mentioned + specs, reviews and in depth pricing information from PCPartPicker product links.\n- Async ready: all scraping methods have an asynchronous version\n\n\n# Installation\n\n---\nInstallation via pip:\n```\n>>> pip install pypartpicker2\n```\nOr clone the repo directly:\n```\n>>> git clone https://github.com/giuseppe99barchetta/pypartpicker2.git\n```\n# Example programs\n\n---\n\nHere is a program that searches for i7's, prints every result, then gets the first result and prints its specs:\n```python\nfrom pypartpicker2  import Scraper\n\n# creates the scraper object\npcpp = Scraper()\n# returns a list of Part objects we can iterate through\nparts = pcpp.part_search(\"i7\")\n\n# iterates through every part object\nfor part in parts:\n    # prints the name of the part\n    print(part.name)\n\n# gets the first product and fetches its URL\nfirst_product_url = parts[0].url\n# gets the Product object for the item\nproduct = pcpp.fetch_product(first_product_url)\n# prints the product's specs using the specs attribute\nprint(product.specs)\n```\nHere is another program that finds i3s that are cheaper than or equal to \u00a3110, prints their specs and then prints the first review:\n```python\nfrom pypartpicker2 import Scraper\nfrom time import sleep\n\n# returns a list of Part objects we can iterate through\n# the region is set to \"uk\" so that we get prices in GBP\npcpp = Scraper()\nparts = pcpp.part_search(\"i3\", region=\"uk\")\n\n# iterates through the parts\nfor part in parts:\n    # checks if the price is lower than 110\n    if float(part.price.strip(\"\u00a3\")) <= 110:\n        print(f\"I found a valid product: {part.name}\")\n        print(f\"Here is the link: {part.url}\")\n        # gets the product object for the parts\n        product = pcpp.fetch_product(part.url)\n        print(product.specs)\n        # makes sure the product has reviews\n        if product.reviews != None:\n            # gets the first review\n            review = product.reviews[0]\n            print(f\"Posted by {review.author}: {review.content}\")\n            print(f\"They rated this product {review.rating}/5.\")\n        else:\n            print(\"There are no reviews on this product!\")\n            \n    # slows down the program so as not to spam PCPartPicker and potentially get IP banned\n    sleep(3)\n```\n\n# Creating the Scraper object\n\n---\n\n### `Scraper(headers={...}, response_retriever=...)`\n\n### Parameters\n- **headers** ( [dict](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) ) - The browser headers for the requests in a dict.\n\n  Note: There are headers set by default. I only recommend changing them if you are encountering scraping errors.\n\n- **response_retriever** ( [Callable](https://docs.python.org/3/library/typing.html#typing.Callable) ) - A function accepting arguments (`url, **kwargs`) that is called to retrieve the response from PCPartPicker\n\n  Note: A default retriever is configured that calls pcpartpicker.com directly. I only recommend changing this if you need to configure how the request is made (e.g. via a proxy)\n\n# Scraper Methods\n\n---\n\n### `Scraper.part_search(search_term, limit=20, region=None)`\n#### Returns Part objects using PCPartPicker's search function.\n### **Parameters**\n- **search_term** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The term you want to search for.\n  \n    Example: `\"i5\"`\n  \n\n- **limit** (Optional[ [int](https://docs.python.org/3/library/functions.html#int) ]) - The amount of results that you want to be returned.\n    \n    Example: `limit=5`\n  \n\n- **region** (Optional[ [str](https://docs.python.org/3/library/stdtypes.html#str) ]) - The country code of which you want the pricing for the Part objects to be in. \n    \n    Example: `region=\"uk\"`\n  \n### Returns\nA list of Part objects corresponding to the results on PCPartPicker.\n\n\n---\n\n### `Scraper.fetch_product(product_url)`\n#### Returns a Product object from a PCPartPicker product URL.\n### **Parameters**\n- **product_url** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The product URL for the product you want to search for.\n  \n    Example: `\"https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box\"`\n\n### Returns\nA Product object for the part.\n\n---\n### `Scraper.fetch_list(list_url)`\n#### Returns a PCPPLIst object from a PCPartPicker list URL.\n### **Parameters**\n- **list_url** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The URL for the parts list.\n  \n    Example: `\"https://pcpartpicker.com/list/Tzx22V\"`\n\n### Returns\nA PCPPList object for the list.\n\n# Other methods\n\n---\n\n### `get_list_links(string)`\n#### Returns a list of PCPartPicker list links from the given string.\n### **Parameters**\n- **string** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The string containing the parts list URL.\n  \n    Example: `\"this function can extract the link from this string https://pcpartpicker.com/list/Tzx22V\"`\n\n### Returns\nA list of URLs.\n\n---\n### `get_product_links(string)`\n#### Returns a list of PCPartPicker product links from the given string.\n### **Parameters**\n- **string** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The string containing the product URL.\n  \n    Example: `\"this function can extract the link from this string https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box\"`\n\n### Returns\nA list of URLs.\n\n\n# Async Methods\n___\n#### Same syntax as sync functions, but add aio_ to the beginning of the method name and add await before the function call.\n#### For example:\n```python\npcpp = Scraper()\nresults = pcpp.part_search(\"i5\")\n```\n\nbecomes\n\n```python\npcpp = Scraper()\nresults = await pcpp.aio_part_search(\"i5\")\n```\n\nRemember: you can only call async functions within other async functions. If you are not writing async code, do not use these methods. Use the sync methods, which don't have aio_ before their name.\n\nOnly the blocking functions (the ones that involve active scraping) have async equivalents.\n\n# Objects\n\n---\n## Part\n### Attributes\n- `name` - The name of the part\n- `url` - The product URL for the part\n- `type` - The type of the part (e.g. CPU, Motherboard, Memory)\n- `price` - The cheapest price for the part\n- `image` - The image link for the part\n\n---\n\n## Product\n### Attributes\n\n- All attributes from Part\n- `specs` - The specs for the product, arranged in a dictionary with the values being lists\n- `price_list` - A list of Price objects containing all the merchants, prices and stock values\n- `rating` - The total user ratings and average score for the product\n- `reviews` - A list of Review objects for the product\n- `compatible_parts` - A list of tuples containing the compatible parts links for the product\n\n___\n\n## Price\n### Attributes\n\n- `value` - The final price value\n- `base_value` - The price value before shipping and other discounts\n- `seller` - The name of the company selling the part\n- `seller_icon` - The icon URL for the company selling the part\n- `url` - The URL which links to the seller's product listing\n- `in_stock` - A boolean of whether the product is in stock\n\n---\n\n## Review\n### Attributes\n\n- `author` - The name of the person who posted the review\n- `author_url` - The URL which points to the author's profile\n- `author_icon` - The icon URL of the person who posted the review\n- `points` - The amount of upvotes on the review\n- `created_at` - How long ago the review was sent\n- `rating` - The star rating out of 5 of the product that the review gives\n- `content` - The text content of the review\n\n---\n\n## PCPPList\n### Attributes\n\n- `parts` - List of Part objects corresponding to every part in the list\n- `wattage` - The estimated wattage for the parts in the list\n- `total` - The total price of the PCPartPicker list\n- `url` - The URL of the PCPartPicker list\n- `compatibility` - A list containing the compatibility notes for the parts list\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A package that scrapes pcpartpicker.com and returns the results as objects.",
    "version": "0.1.9",
    "project_urls": {
        "Download": "https://github.com/giuseppe99barchetta/pypartpicker/archive/refs/tags/0.1.6.tar.gz",
        "Homepage": "https://github.com/giuseppe99barchetta/pypartpicker"
    },
    "split_keywords": [
        "pcpartpicker",
        " scraper",
        " list",
        " beautifulsoup",
        " pc",
        " parts"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "edfd92c3c228d09542ae88954f8235c6f2cd9b235954ed5ee30234919309519e",
                "md5": "5f01eb1447f453313379c7ad92f63886",
                "sha256": "56240b4b0d797a6a130e6f96f1ddc7fd085d40938920781ddafa1a34ad3ae5f9"
            },
            "downloads": -1,
            "filename": "pypartpicker2-0.1.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f01eb1447f453313379c7ad92f63886",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10516,
            "upload_time": "2024-07-11T12:45:06",
            "upload_time_iso_8601": "2024-07-11T12:45:06.249877Z",
            "url": "https://files.pythonhosted.org/packages/ed/fd/92c3c228d09542ae88954f8235c6f2cd9b235954ed5ee30234919309519e/pypartpicker2-0.1.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "888963d0865994fe8639415efd9b96e1f4f5b74df9355208f4fc57c12727a0d0",
                "md5": "0dde850da62cffa8e49231cfff50a985",
                "sha256": "406929ecc65f9cce3a9456130029cd84e7ab515036e9c969bc226b04b659ba14"
            },
            "downloads": -1,
            "filename": "pypartpicker2-0.1.9.tar.gz",
            "has_sig": false,
            "md5_digest": "0dde850da62cffa8e49231cfff50a985",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12770,
            "upload_time": "2024-07-11T12:45:07",
            "upload_time_iso_8601": "2024-07-11T12:45:07.876131Z",
            "url": "https://files.pythonhosted.org/packages/88/89/63d0865994fe8639415efd9b96e1f4f5b74df9355208f4fc57c12727a0d0/pypartpicker2-0.1.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-11 12:45:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "giuseppe99barchetta",
    "github_project": "pypartpicker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pypartpicker2"
}
        
Elapsed time: 0.33942s