From 05625fba7ffd9b08800a608726c6a084b4a04a39 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:30:25 +0100 Subject: [PATCH 01/22] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index aae362b..3e9d701 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ ![TechSpecs Logo](https://i.imgur.com/JwSpZO8.jpg) ![TechSpecs Logo](https://i.imgur.com/JZ3GqAU.jpg) +![TechSpecs Logo](https://techspecs.io/big-logo-light.svg) + # Introducing TechSpecs Python From 0619927e48aa0302cdd56e8ff9e4b62b69c29c48 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:32:48 +0100 Subject: [PATCH 02/22] Update README.md --- README.md | 290 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 209 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index 3e9d701..19611e0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -![TechSpecs Logo](https://i.imgur.com/JwSpZO8.jpg) -![TechSpecs Logo](https://i.imgur.com/JZ3GqAU.jpg) ![TechSpecs Logo](https://techspecs.io/big-logo-light.svg) @@ -7,6 +5,17 @@ This python library provides automatic access to the standardized technical specifications of the world's consumer electronics, including the latest smartphones, tablets, smartwatches, laptops, and more. +# Database Stats + +At TechSpecs, we are committed to providing the most comprehensive and up-to-date database of technical specifications for consumer electronics products. Here are some statistics on our current database: + +Total number of products: 100,000+ +Brands: 400+ +Categories: 6 (Smartphones, Tablets, Smartwatches, Monitors, TVs, and Laptops) +Technical specifications: Over 300 for each product, including dimensions, weight, display features, connectivity options, and more. +Daily updates: We update our database on a daily basis to ensure that our API provides the most accurate and up-to-date technical specifications for the products you're interested in. +We take pride in providing a database that is comprehensive and reliable, and we are constantly working to expand and improve it. If you have any questions or issues, please don't hesitate to reach out to our support team for assistance. + ## API Key - Get an API key [here](https://developer.dashboard.techspecs.io/) @@ -26,12 +35,12 @@ pip install techspecs ## Usage -The library needs to be configured with your account's api key and base which is -available in your [TechSpecs Dashboard](https://developer.dashboard.techspecs.io/). +The library needs to be configured with your TechSpecs api key and base URL which is +available in your [TechSpecs Dashboard](https://techspecs.io/dashboard). -Set `techspecs_key` to your key value and `techspecs_base` to your base value. +Set `techspecs_api_key` to your key value and `techspecs_base_url` to your base value. -### Basic Search +### Product Search #### Search for a device by specifying it's model name, version number or features ```python @@ -39,137 +48,256 @@ Set `techspecs_key` to your key value and `techspecs_base` to your base value. import techspecs import json -# TechSpecs API Key -techspecs_key = "techspecs_api_key" +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = 'a8TD3mkN49fhg2y' +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" query = { 'keyword': 'iPhone 13', # product name or version number to search - 'category': 'all', # product category to search + 'category': '', # product category to search (e.g. 'Smartphones', 'Tablets', or leave empty to search all categories) + 'page': 0 # page number to fetch results from } -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.search(base, query, key, mode='pretty') +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Search for a product by name, version, or features +try: + response = techspecs.product_search(techspecs_base_url, query, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") -# print the search results -print(response) ``` -### Advanced Search -#### List all products by brand, category and release date + +### Product Details + ```python -# List all products by brand, category and release date +# Get the detailed specifications of a product import techspecs -# TechSpecs API Key -techspecs_key = "techspecs_api_key" +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" -# enter the page number to fetch results from -page = 1 +# TechSpecs product ID +techspecs_product_id = "63e96260ff7af4b68a304e40" -# type in the name of the brand you're looking for or leave this field empty to see results from all brands -brand = ["Apple"] +# Query dictionary +query = { + "productId": techspecs_product_id +} -# type in the name of the category you're looking for or leave this field empty to see results from all categories -category = ["smartphone"] +# Output mode ('raw' or 'pretty') +mode = 'pretty' -# please provide a date range to narrow your search. Leave this field empty to fetch all results from all dates -date = { - "from": "2010-01-01", # YYYY-MM-DD - "to": "2022-03-15" # YYYY-MM-DD -} +try: + # Validate techspecs_product_id + if not isinstance(techspecs_product_id, str): + raise ValueError('TechSpecs Product ID should be a string.') + + # Validate mode + if mode not in ['raw', 'pretty']: + raise ValueError('Invalid mode. Mode should be "raw" or "pretty".') + + # Call TechSpecs API to get product details + response = techspecs.product_detail(techspecs_base_url, techspecs_product_id, techspecs_api_key, mode=mode) + + # Print the product details + print(response) +except Exception as e: + print(f"An error occurred: {e}") -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.products(techspecs_base, brand, category, date, page, techspecs_key, mode='pretty') -# print the search results -print(response) ``` -### Apple Machine ID Search -#### Search for Apple products by machine id + +### List all categories ```python -# Search for an Apple product by machine id import techspecs -# TechSpecs API Key -techspecs_key = "techspecs_api_key" +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" +# Output mode ('raw' or 'pretty') +mode = 'pretty' -# machine id to search -machine_id = "iphone8,3" +# Define constants +DEFAULT_MODE = 'pretty' +VALID_MODES = ['pretty', 'raw'] + +# Validate parameters +def validate_parameters(mode=DEFAULT_MODE): + if mode not in VALID_MODES: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.') + +# Validate search parameters +try: + validate_parameters(mode=mode) +except ValueError as e: + print(f"Invalid search parameters: {e}") + exit() + +# Call TechSpecs API to get all categories +try: + response = techspecs.get_all_categories(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.apple_machine_id(techspecs_base, machine_id, techspecs_key, mode='pretty') -# print the specifications of the product -print(response) ``` -### Product Details +### List all brands ```python -# Get the standardized specifications of a specified product import techspecs -# TechSpecs API Key -techspecs_key = "techspecs_api_key" +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" +# Output mode ('raw' or 'pretty') +mode = 'pretty' -# TechSpecs product id -techspecs_id = "6186b047987cda5f88311983" +# Define function to validate parameters +def validate_parameters(mode): + if mode not in ['raw', 'pretty']: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of ["raw", "pretty"].') -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.detail(techspecs_base, techspecs_id, techspecs_key, mode='pretty') +# Validate parameters +try: + validate_parameters(mode) +except ValueError as e: + print(f"Invalid parameters: {e}") + exit() + +# Call TechSpecs API to get all brands +try: + response = techspecs.get_all_brands(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") -# print the specifications of the product -print(response) ``` -### List all brands + +### Advanced Search +#### List all products by brand, category and release date ```python +# List all products by brand, category and release date import techspecs +import datetime + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Set constants +DEFAULT_PAGE = 0 +DEFAULT_MODE = 'pretty' +VALID_MODES = ['pretty', 'raw'] + +# Define function to validate date format +def is_valid_date(date_str): + try: + datetime.datetime.strptime(date_str, '%Y-%m-%d') + return True + except ValueError: + return False + +# Define function to validate parameters +def validate_parameters(brand, category, date=None, page=DEFAULT_PAGE, mode=DEFAULT_MODE): + if not isinstance(brand, list): + raise ValueError('Brand should be a list.') + + if not isinstance(category, list): + raise ValueError('Category should be a list.') + + if date is not None: + if not isinstance(date, dict): + raise ValueError('Invalid date format. Date should be a dictionary with keys "from" and "to".') + elif 'from' not in date or 'to' not in date: + raise ValueError('Invalid date format. Date dictionary should have keys "from" and "to".') + elif not is_valid_date(date['from']) or not is_valid_date(date['to']): + raise ValueError('Invalid date format. Date should be in the format YYYY-MM-DD.') + + if not isinstance(page, int) or page < 0: + raise ValueError('Page should be a non-negative integer.') + + if mode not in VALID_MODES: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.') + +# Define search parameters +brand = ["Apple"] +category = ["Smartphones"] +date = { + "from": "2010-01-01", + "to": "2022-03-15" +} +page = 0 -# TechSpecs API Key -techspecs_key = "techspecs_api_key" - -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" +# Validate search parameters +try: + validate_parameters(brand, category, date=date, page=page, mode=mode) +except ValueError as e: + print(f"Invalid search parameters: {e}") + exit() -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.brands(techspecs_base, techspecs_key, mode='pretty') -# print the list of all brands -print(response) +# Call TechSpecs API to get all products +try: + response = techspecs.get_all_products(techspecs_base_url, techspecs_api_key, brand, category, date, page, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") ``` -### List all categories + + +### Machine ID Search +#### Search for Apple products by machine id ```python +# Search for an Apple product by machine id import techspecs -# TechSpecs API Key -techspecs_key = "techspecs_api_key" +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Serial number of the Apple machine to look up machineid_or_codename ex iphone 11,6 +machine_id = "iphone 11,6" -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" +# Output mode ('raw' or 'pretty') +mode = 'pretty' -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.categories(techspecs_base, techspecs_key, mode='pretty') +# Look up the Apple machine by its serial number +try: + response = techspecs.machine_id_search(techspecs_base_url, techspecs_api_key, machine_id, mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") -# print the list of all categories -print(response) ``` From da0f1daca56c14ec767cd7bf5d9177553872f64a Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:35:52 +0100 Subject: [PATCH 03/22] Update README.md --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 19611e0..c538cca 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,11 @@ This python library provides automatic access to the standardized technical spec At TechSpecs, we are committed to providing the most comprehensive and up-to-date database of technical specifications for consumer electronics products. Here are some statistics on our current database: Total number of products: 100,000+ -Brands: 400+ -Categories: 6 (Smartphones, Tablets, Smartwatches, Monitors, TVs, and Laptops) -Technical specifications: Over 300 for each product, including dimensions, weight, display features, connectivity options, and more. -Daily updates: We update our database on a daily basis to ensure that our API provides the most accurate and up-to-date technical specifications for the products you're interested in. +- Brands: 400+ +- Categories: 6 (Smartphones, Tablets, Smartwatches, Monitors, TVs, and Laptops) +- Technical specifications: Over 300 for each product, including dimensions, weight, display features, connectivity options, and more. +- Daily updates: We update our database on a daily basis to ensure that our API provides the most accurate and up-to-date technical specifications for the products you're interested in. + We take pride in providing a database that is comprehensive and reliable, and we are constantly working to expand and improve it. If you have any questions or issues, please don't hesitate to reach out to our support team for assistance. ## API Key @@ -41,7 +42,6 @@ available in your [TechSpecs Dashboard](https://techspecs.io/dashboard). Set `techspecs_api_key` to your key value and `techspecs_base_url` to your base value. ### Product Search -#### Search for a device by specifying it's model name, version number or features ```python # Search for a product by name, version or features @@ -195,7 +195,6 @@ except Exception as e: ### Advanced Search -#### List all products by brand, category and release date ```python # List all products by brand, category and release date import techspecs From fd897bce7d07cf3b4c86f7ff2f56c09caf31081a Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:36:35 +0100 Subject: [PATCH 04/22] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c538cca..3bbfbd0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -![TechSpecs Logo](https://techspecs.io/big-logo-light.svg) +

+ TechSpecs Logo +

+ # Introducing TechSpecs Python @@ -28,7 +31,6 @@ We take pride in providing a database that is comprehensive and reliable, and we ## Installation -![How to install TechSpecs](https://i.imgur.com/m9yxeWW.png) ```sh pip install techspecs From 9043a5440bae3fb4eba85c4c9856c9801fa9ccd1 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:37:55 +0100 Subject: [PATCH 05/22] Update README.md --- README.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3bbfbd0..703d375 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,7 @@ TechSpecs Logo

- - -# Introducing TechSpecs Python - -This python library provides automatic access to the standardized technical specifications of the world's consumer electronics, including the latest smartphones, tablets, smartwatches, laptops, and more. +TechSpecs Python provides automatic access to the standardized technical specifications of the world's consumer electronics, including the latest smartphones, tablets, smartwatches, laptops, and more. # Database Stats @@ -22,8 +18,7 @@ We take pride in providing a database that is comprehensive and reliable, and we ## API Key -- Get an API key [here](https://developer.dashboard.techspecs.io/) - +- [Signup](https://techspecs.io/) to get your TechSpecs API Key ## Requirements From 74fa127eef4557fb8b4a020c0b1795e9ea164102 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:39:27 +0100 Subject: [PATCH 06/22] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 703d375..69d8cb7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ TechSpecs Logo

-TechSpecs Python provides automatic access to the standardized technical specifications of the world's consumer electronics, including the latest smartphones, tablets, smartwatches, laptops, and more. +# introduction + +TechSpecs Python provides easy access to the standardized technical specifications of the world's consumer electronics, including the latest smartphones, tablets, smartwatches, laptops, monitors, TVs and more. # Database Stats From 8bf3b8906ab075a9fcb380431c57f58db25158cb Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:40:00 +0100 Subject: [PATCH 07/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69d8cb7..388ea19 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ TechSpecs Logo

-# introduction +# Introduction TechSpecs Python provides easy access to the standardized technical specifications of the world's consumer electronics, including the latest smartphones, tablets, smartwatches, laptops, monitors, TVs and more. From f387017f9b1486020192722ede53010b6db4c9de Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:47:09 +0100 Subject: [PATCH 08/22] Delete all_brands.py --- tests/all_brands.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 tests/all_brands.py diff --git a/tests/all_brands.py b/tests/all_brands.py deleted file mode 100644 index b03714c..0000000 --- a/tests/all_brands.py +++ /dev/null @@ -1,7 +0,0 @@ -import techspecs -# All brands - -techspecs_key = "" -techspecs_base = "" -brands = techspecs.brands(techspecs_base, techspecs_key, mode='pretty') -print(brands) From 70f68ce3d592560b6ca98b156e4db8a352828fc1 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:47:18 +0100 Subject: [PATCH 09/22] Delete all_categories.py --- tests/all_categories.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 tests/all_categories.py diff --git a/tests/all_categories.py b/tests/all_categories.py deleted file mode 100644 index 7d9b268..0000000 --- a/tests/all_categories.py +++ /dev/null @@ -1,7 +0,0 @@ -import techspecs -# All Categories - -techspecs_key = "" -techspecs_base = "" -categories = techspecs.categories(techspecs_base, techspecs_key, mode='pretty') -print(categories) From 8bd6a9035140827b138e61710d2eaa598b7d927f Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:47:25 +0100 Subject: [PATCH 10/22] Delete all_products.py --- tests/all_products.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 tests/all_products.py diff --git a/tests/all_products.py b/tests/all_products.py deleted file mode 100644 index 2f40869..0000000 --- a/tests/all_products.py +++ /dev/null @@ -1,14 +0,0 @@ -import techspecs -# All Products By Brand And Category - -techspecs_key = "" -techspecs_base = "" -page = 1 -brand = [""] -category = [""] -time = { - "from": "2010-01-01", # YYYY-MM-DD - "to": "2022-03-15" # YYYY-MM-DD -} -all_products = techspecs.products(techspecs_base, brand, category, time, page, techspecs_key, mode='pretty') -print(all_products) From 474be0f1ae9afe69bc8b5720e5dd9e3c4c6a2cf4 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:47:31 +0100 Subject: [PATCH 11/22] Delete details.py --- tests/details.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 tests/details.py diff --git a/tests/details.py b/tests/details.py deleted file mode 100644 index 9364642..0000000 --- a/tests/details.py +++ /dev/null @@ -1,9 +0,0 @@ -import techspecs -# Product Details - -techspecs_key = "" -techspecs_base = "" -techspecs_id = "" - -details = techspecs.detail(techspecs_base, techspecs_id, techspecs_key, mode='pretty') -print(details) From 233f826f65d2327c98b209072a18a97fc043b6ea Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:47:37 +0100 Subject: [PATCH 12/22] Delete search.py --- tests/search.py | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 tests/search.py diff --git a/tests/search.py b/tests/search.py deleted file mode 100644 index 1aa43aa..0000000 --- a/tests/search.py +++ /dev/null @@ -1,11 +0,0 @@ -import techspecs -# Search Product - -techspecs_key = "" -techspecs_base = "" -query = { - 'keyword': '', - 'category': '', -} -search = techspecs.search(techspecs_base, query, techspecs_key, mode='pretty') -print(search) From 90626d0e4dc2e404d915df560226cec8cc90bbaf Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:48:23 +0100 Subject: [PATCH 13/22] Add files via upload --- tests/test_get_all_brandlogos.py | 17 ++++++ tests/test_get_all_brands.py | 29 ++++++++++ tests/test_get_all_categories.py | 33 ++++++++++++ tests/test_machine_id_search.py | 20 +++++++ tests/test_product_detail.py | 35 +++++++++++++ tests/test_product_search.py | 24 +++++++++ tests/test_techspecs_advanced_search.py | 70 +++++++++++++++++++++++++ 7 files changed, 228 insertions(+) create mode 100644 tests/test_get_all_brandlogos.py create mode 100644 tests/test_get_all_brands.py create mode 100644 tests/test_get_all_categories.py create mode 100644 tests/test_machine_id_search.py create mode 100644 tests/test_product_detail.py create mode 100644 tests/test_product_search.py create mode 100644 tests/test_techspecs_advanced_search.py diff --git a/tests/test_get_all_brandlogos.py b/tests/test_get_all_brandlogos.py new file mode 100644 index 0000000..bc438b7 --- /dev/null +++ b/tests/test_get_all_brandlogos.py @@ -0,0 +1,17 @@ +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Call TechSpecs API to get all brand logos +try: + response = techspecs.get_all_brand_logos(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") diff --git a/tests/test_get_all_brands.py b/tests/test_get_all_brands.py new file mode 100644 index 0000000..f335b77 --- /dev/null +++ b/tests/test_get_all_brands.py @@ -0,0 +1,29 @@ +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Define function to validate parameters +def validate_parameters(mode): + if mode not in ['raw', 'pretty']: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of ["raw", "pretty"].') + +# Validate parameters +try: + validate_parameters(mode) +except ValueError as e: + print(f"Invalid parameters: {e}") + exit() + +# Call TechSpecs API to get all brands +try: + response = techspecs.get_all_brands(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") diff --git a/tests/test_get_all_categories.py b/tests/test_get_all_categories.py new file mode 100644 index 0000000..940c5f2 --- /dev/null +++ b/tests/test_get_all_categories.py @@ -0,0 +1,33 @@ +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Define constants +DEFAULT_MODE = 'pretty' +VALID_MODES = ['pretty', 'raw'] + +# Validate parameters +def validate_parameters(mode=DEFAULT_MODE): + if mode not in VALID_MODES: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.') + +# Validate search parameters +try: + validate_parameters(mode=mode) +except ValueError as e: + print(f"Invalid search parameters: {e}") + exit() + +# Call TechSpecs API to get all categories +try: + response = techspecs.get_all_categories(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") diff --git a/tests/test_machine_id_search.py b/tests/test_machine_id_search.py new file mode 100644 index 0000000..19665b7 --- /dev/null +++ b/tests/test_machine_id_search.py @@ -0,0 +1,20 @@ +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Serial number of the Apple machine to look up machineid_or_codename ex iphone 11,6 +machine_id = "iphone 11,6" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Look up the Apple machine by its serial number +try: + response = techspecs.machine_id_search(techspecs_base_url, techspecs_api_key, machine_id, mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") diff --git a/tests/test_product_detail.py b/tests/test_product_detail.py new file mode 100644 index 0000000..1e82814 --- /dev/null +++ b/tests/test_product_detail.py @@ -0,0 +1,35 @@ +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# TechSpecs product ID +techspecs_product_id = "63e96260ff7af4b68a304e40" + +# Query dictionary +query = { + "productId": techspecs_product_id +} + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +try: + # Validate techspecs_product_id + if not isinstance(techspecs_product_id, str): + raise ValueError('TechSpecs Product ID should be a string.') + + # Validate mode + if mode not in ['raw', 'pretty']: + raise ValueError('Invalid mode. Mode should be "raw" or "pretty".') + + # Call TechSpecs API to get product details + response = techspecs.product_detail(techspecs_base_url, techspecs_product_id, techspecs_api_key, mode=mode) + + # Print the product details + print(response) +except Exception as e: + print(f"An error occurred: {e}") diff --git a/tests/test_product_search.py b/tests/test_product_search.py new file mode 100644 index 0000000..5d5480c --- /dev/null +++ b/tests/test_product_search.py @@ -0,0 +1,24 @@ +import techspecs +import json + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +query = { + 'keyword': 'iPhone 13', # product name or version number to search + 'category': '', # product category to search (e.g. 'Smartphones', 'Tablets', or leave empty to search all categories) + 'page': 0 # page number to fetch results from +} + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Search for a product by name, version, or features +try: + response = techspecs.product_search(techspecs_base_url, query, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") diff --git a/tests/test_techspecs_advanced_search.py b/tests/test_techspecs_advanced_search.py new file mode 100644 index 0000000..4994b87 --- /dev/null +++ b/tests/test_techspecs_advanced_search.py @@ -0,0 +1,70 @@ +import techspecs +import datetime + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Set constants +DEFAULT_PAGE = 0 +DEFAULT_MODE = 'pretty' +VALID_MODES = ['pretty', 'raw'] + +# Define function to validate date format +def is_valid_date(date_str): + try: + datetime.datetime.strptime(date_str, '%Y-%m-%d') + return True + except ValueError: + return False + +# Define function to validate parameters +def validate_parameters(brand, category, date=None, page=DEFAULT_PAGE, mode=DEFAULT_MODE): + if not isinstance(brand, list): + raise ValueError('Brand should be a list.') + + if not isinstance(category, list): + raise ValueError('Category should be a list.') + + if date is not None: + if not isinstance(date, dict): + raise ValueError('Invalid date format. Date should be a dictionary with keys "from" and "to".') + elif 'from' not in date or 'to' not in date: + raise ValueError('Invalid date format. Date dictionary should have keys "from" and "to".') + elif not is_valid_date(date['from']) or not is_valid_date(date['to']): + raise ValueError('Invalid date format. Date should be in the format YYYY-MM-DD.') + + if not isinstance(page, int) or page < 0: + raise ValueError('Page should be a non-negative integer.') + + if mode not in VALID_MODES: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.') + +# Define search parameters +brand = ["Apple"] +category = ["Smartphones"] +date = { + "from": "2010-01-01", + "to": "2022-03-15" +} +page = 0 + +# Validate search parameters +try: + validate_parameters(brand, category, date=date, page=page, mode=mode) +except ValueError as e: + print(f"Invalid search parameters: {e}") + exit() + + +# Call TechSpecs API to get all products +try: + response = techspecs.get_all_products(techspecs_base_url, techspecs_api_key, brand, category, date, page, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") From beafdd26bdac2a2ad5ba7a2d320499ab27615cb1 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:48:55 +0100 Subject: [PATCH 14/22] Add files via upload --- src/Techspecs.egg-info/PKG-INFO | 315 +++++++++++++++++++++++++++-- src/Techspecs.egg-info/SOURCES.txt | 13 +- src/techspecs/techspecs.py | 271 ++++++++++++++++++++----- 3 files changed, 532 insertions(+), 67 deletions(-) diff --git a/src/Techspecs.egg-info/PKG-INFO b/src/Techspecs.egg-info/PKG-INFO index ee79f29..c60e6f1 100644 --- a/src/Techspecs.egg-info/PKG-INFO +++ b/src/Techspecs.egg-info/PKG-INFO @@ -1,13 +1,12 @@ Metadata-Version: 2.1 Name: techspecs -Version: 0.0.7 -Summary: Library to make Techspecs API calls -Home-page: https://github.com/pypa/sampleproject -Author: Example Author -Author-email: author@example.com -License: UNKNOWN -Project-URL: Bug Tracker, https://github.com/pypa/sampleproject/issues -Platform: UNKNOWN +Version: 2.0.0 +Summary: TechSpecs Python +Home-page: https://github.com/techspecs/techspecs-python +Author: TechSpecs +Author-email: support@techspecs.io +Project-URL: Bug Tracker, https://github.com/techspecs/techspecs-python/issues +Keywords: TechSpecs API,specifications,phone specs,tablet specs,laptop specs,specs,smartwatch specs,smartphone specs,smartphones,tablets,smartwatches,laptops,Smartphone Specifications,Tablet Specifications,Smartwatch Specifications,Laptop Specifications,Technical Specifications,consumer electronics,ecommerce,techspecs-python,techspecs python,specifications library,tech specs API,tech specs Classifier: Programming Language :: Python :: 3 Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent @@ -15,10 +14,300 @@ Requires-Python: >=3.6 Description-Content-Type: text/markdown License-File: LICENSE -# Techspecs +

+ TechSpecs Logo +

+ +# Introduction + +TechSpecs Python provides easy access to the standardized technical specifications of the world's consumer electronics, including smartphones, tablets, smartwatches, laptops, monitors, TVs and more. + +## Documentation + +- See the [TechSpecs API Docs](https://techspecs.readme.io) + +## API Key + +- [Signup](https://techspecs.io/) to get your TechSpecs API Key + + +## Requirements + +- Python 3.6+ + + +## Installation + +```sh +pip install techspecs +``` + +## Usage + +The library needs to be configured with your TechSpecs api key and base URL which is +available in your [TechSpecs Dashboard](https://techspecs.io/dashboard). + +Set `techspecs_api_key` to your key value and `techspecs_base_url` to your base value. + +### Product Search +#### Search for a device by specifying it's model name, version number or features + +```python +# Search for a product by name, version or features +import techspecs +import json + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +query = { + 'keyword': 'iPhone 13', # product name or version number to search + 'category': '', # product category to search (e.g. 'Smartphones', 'Tablets', or leave empty to search all categories) + 'page': 0 # page number to fetch results from +} + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Search for a product by name, version, or features +try: + response = techspecs.product_search(techspecs_base_url, query, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") + + +``` + + +### Product Details + +```python +# Get the detailed specifications of a product +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# TechSpecs product ID +techspecs_product_id = "63e96260ff7af4b68a304e40" + +# Query dictionary +query = { + "productId": techspecs_product_id +} + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +try: + # Validate techspecs_product_id + if not isinstance(techspecs_product_id, str): + raise ValueError('TechSpecs Product ID should be a string.') + + # Validate mode + if mode not in ['raw', 'pretty']: + raise ValueError('Invalid mode. Mode should be "raw" or "pretty".') + + # Call TechSpecs API to get product details + response = techspecs.product_detail(techspecs_base_url, techspecs_product_id, techspecs_api_key, mode=mode) + + # Print the product details + print(response) +except Exception as e: + print(f"An error occurred: {e}") + + +``` + + +### List all categories +```python +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Define constants +DEFAULT_MODE = 'pretty' +VALID_MODES = ['pretty', 'raw'] + +# Validate parameters +def validate_parameters(mode=DEFAULT_MODE): + if mode not in VALID_MODES: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.') + +# Validate search parameters +try: + validate_parameters(mode=mode) +except ValueError as e: + print(f"Invalid search parameters: {e}") + exit() + +# Call TechSpecs API to get all categories +try: + response = techspecs.get_all_categories(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") + + +``` + + +### List all brands +```python +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Define function to validate parameters +def validate_parameters(mode): + if mode not in ['raw', 'pretty']: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of ["raw", "pretty"].') + +# Validate parameters +try: + validate_parameters(mode) +except ValueError as e: + print(f"Invalid parameters: {e}") + exit() + +# Call TechSpecs API to get all brands +try: + response = techspecs.get_all_brands(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") + + +``` + + +### Advanced Search +#### List all products by brand, category and release date +```python +# List all products by brand, category and release date +import techspecs +import datetime + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Set constants +DEFAULT_PAGE = 0 +DEFAULT_MODE = 'pretty' +VALID_MODES = ['pretty', 'raw'] + +# Define function to validate date format +def is_valid_date(date_str): + try: + datetime.datetime.strptime(date_str, '%Y-%m-%d') + return True + except ValueError: + return False + +# Define function to validate parameters +def validate_parameters(brand, category, date=None, page=DEFAULT_PAGE, mode=DEFAULT_MODE): + if not isinstance(brand, list): + raise ValueError('Brand should be a list.') + + if not isinstance(category, list): + raise ValueError('Category should be a list.') + + if date is not None: + if not isinstance(date, dict): + raise ValueError('Invalid date format. Date should be a dictionary with keys "from" and "to".') + elif 'from' not in date or 'to' not in date: + raise ValueError('Invalid date format. Date dictionary should have keys "from" and "to".') + elif not is_valid_date(date['from']) or not is_valid_date(date['to']): + raise ValueError('Invalid date format. Date should be in the format YYYY-MM-DD.') + + if not isinstance(page, int) or page < 0: + raise ValueError('Page should be a non-negative integer.') + + if mode not in VALID_MODES: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.') + +# Define search parameters +brand = ["Apple"] +category = ["Smartphones"] +date = { + "from": "2010-01-01", + "to": "2022-03-15" +} +page = 0 + +# Validate search parameters +try: + validate_parameters(brand, category, date=date, page=page, mode=mode) +except ValueError as e: + print(f"Invalid search parameters: {e}") + exit() + + +# Call TechSpecs API to get all products +try: + response = techspecs.get_all_products(techspecs_base_url, techspecs_api_key, brand, category, date, page, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") + + +``` + + +### Machine ID Search +#### Search for Apple products by machine id +```python +# Search for an Apple product by machine id +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Serial number of the Apple machine to look up machineid_or_codename ex iphone 11,6 +machine_id = "iphone 11,6" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Look up the Apple machine by its serial number +try: + response = techspecs.machine_id_search(techspecs_base_url, techspecs_api_key, machine_id, mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") + + +``` -This is a python package to make [Techspecs](https://techspecs.readme.io/reference/getting-started-with-your-api-1) -API calls easier. -[Get API key](https://developer.dashboard.techspecs.io/) -to get started. diff --git a/src/Techspecs.egg-info/SOURCES.txt b/src/Techspecs.egg-info/SOURCES.txt index 6b12837..8b59a1a 100644 --- a/src/Techspecs.egg-info/SOURCES.txt +++ b/src/Techspecs.egg-info/SOURCES.txt @@ -2,6 +2,10 @@ LICENSE README.md pyproject.toml setup.cfg +src/TechSpecs.egg-info/PKG-INFO +src/TechSpecs.egg-info/SOURCES.txt +src/TechSpecs.egg-info/dependency_links.txt +src/TechSpecs.egg-info/top_level.txt src/Techspecs.egg-info/PKG-INFO src/Techspecs.egg-info/SOURCES.txt src/Techspecs.egg-info/dependency_links.txt @@ -11,4 +15,11 @@ src/techspecs/techspecs.py src/techspecs.egg-info/PKG-INFO src/techspecs.egg-info/SOURCES.txt src/techspecs.egg-info/dependency_links.txt -src/techspecs.egg-info/top_level.txt \ No newline at end of file +src/techspecs.egg-info/top_level.txt +tests/test_get_all_brandlogos.py +tests/test_get_all_brands.py +tests/test_get_all_categories.py +tests/test_machine_id_search.py +tests/test_product_detail.py +tests/test_product_search.py +tests/test_techspecs_advanced_search.py \ No newline at end of file diff --git a/src/techspecs/techspecs.py b/src/techspecs/techspecs.py index 87de619..1425615 100644 --- a/src/techspecs/techspecs.py +++ b/src/techspecs/techspecs.py @@ -1,119 +1,284 @@ import json import requests +def product_search(techspecs_base_url, query: dict, techspecs_api_key, mode='raw'): + """ + Search for products that match the specified query. -def search(techspecs_base, query: dict, key, mode='raw'): - url = f'https://apis.dashboard.techspecs.io/{techspecs_base}/api/product/search?' - header = { + :param base_url: the base URL of the TechSpecs API + :param query: a dictionary that contains the search query parameters + :param bearer_token: the bearer token for API authentication + :param mode: the output mode ('raw' or 'pretty') + :return: the search results in the specified output mode + """ + q = query["keyword"].strip() + url = f'{techspecs_base_url}/v4/product/search?query={q}' + headers = { "Accept": "application/json", - "x-blobr-key": key, + "Authorization": f"Bearer {techspecs_api_key}", "Content-Type": "application/json" } - parameter = {'query': query['keyword'].replace(' ', '%20')} - payload = {"category": query['category']} - req = requests.post(url, params=parameter, json=payload, headers=header).json() + payload = {"category": query['category'].strip()} + response = requests.post(url, json=payload, headers=headers).json() if mode == 'raw': - return req + return response elif mode == 'pretty': try: - mod_list = req['data']['results'] + mod_list = response['data'] return json.dumps(mod_list, indent=4) - except: - return req - + except KeyError: + return response else: return 'Invalid Mode' -def detail(techspecs_base, techspecs_id, key, mode='raw'): - url = f'https://apis.dashboard.techspecs.io/{techspecs_base}/api/product/get/' - header = { +def product_detail(techspecs_base_url, techspecs_product_id, techspecs_api_key, mode='raw'): + """ + Get detailed information about a specific product. + + :param base_url: the base URL of the TechSpecs API + :param product_id: the ID of the product to get information about + :param bearer_token: the bearer token for API authentication + :param mode: the output mode ('raw' or 'pretty') + :return: the product information in the specified output mode + """ + url = f'{techspecs_base_url}/v4/product/detail' + params = { + 'productId': techspecs_product_id.strip() + } + headers = { "Accept": "application/json", - "Accept-Encoding": "gzip, deflate", - "x-blobr-key": key + "Authorization": f"Bearer {techspecs_api_key}", } - req = requests.get(url + techspecs_id, headers=header).json() + try: + response = requests.get(url, headers=headers, params=params) + response.raise_for_status() + data = response.json() + except requests.exceptions.HTTPError as error: + return f"HTTP error occurred: {error}" + except requests.exceptions.RequestException as error: + return f"An error occurred: {error}" + except ValueError as error: + return f"Failed to decode JSON: {error}" + if mode == 'raw': - return req + return data elif mode == 'pretty': try: - mod_list = req['data']['product'] + mod_list = data['data'] modified_data = [] for m in mod_list: mod_dict = {} for a, b in m.items(): try: mod_dict[a] = b - except: + except TypeError: for x, y in b: mod_dict[x] = y modified_data.append(mod_dict) return json.dumps(modified_data, indent=4) - except: - return req + except KeyError: + return data else: return 'Invalid Mode' -def brands(techspecs_base, key, mode='raw'): - url = f'https://apis.dashboard.techspecs.io/{techspecs_base}/api/product/brands' - header = { + +def get_all_brands(techspecs_base_url, techspecs_api_key, mode='raw'): + """ + Get a list of all brands. + + :param base_url: the base URL of the TechSpecs API + :param bearer_token: the bearer token for API authentication + :param mode: the output mode ('raw' or 'pretty') + :return: the list of brands in the specified output mode + """ + url = f'{techspecs_base_url}/v4/brand/all' + headers = { "Accept": "application/json", - "x-blobr-key": key + "Authorization": f"Bearer {techspecs_api_key}" } - req = requests.get(url, headers=header).json() + try: + response = requests.get(url, headers=headers) + response.raise_for_status() + data = response.json() + except requests.exceptions.HTTPError as error: + return f"HTTP error occurred: {error}" + except requests.exceptions.RequestException as error: + return f"An error occurred: {error}" + except ValueError as error: + return f"Failed to decode JSON: {error}" + if mode == 'raw': - return req + return data elif mode == 'pretty': try: - mod_list = req['data']['brands'] + mod_list = data['data'] return json.dumps(mod_list, indent=4) - except: - return req + except KeyError: + return data else: return 'Invalid Mode' -def categories(techspecs_base, key, mode='raw'): - url = f'https://apis.dashboard.techspecs.io/{techspecs_base}/api/category/getAll' - header = { + +def get_all_categories(techspecs_base_url, techspecs_api_key, mode='raw'): + """ + Get a list of all categories. + + :param base_url: the base URL of the TechSpecs API + :param bearer_token: the bearer token for API authentication + :param mode: the output mode ('raw' or 'pretty') + :return: the list of categories in the specified output mode + """ + url = f'{techspecs_base_url}/v4/category/all' + headers = { "Accept": "application/json", - "x-blobr-key": key + "Authorization": f"Bearer {techspecs_api_key}" } - req = requests.get(url, headers=header).json() + try: + response = requests.get(url, headers=headers) + response.raise_for_status() + data = response.json() + except requests.exceptions.HTTPError as error: + return f"HTTP error occurred: {error}" + except requests.exceptions.RequestException as error: + return f"An error occurred: {error}" + except ValueError as error: + return f"Failed to decode JSON: {error}" + if mode == 'raw': - return req + return data elif mode == 'pretty': try: - mod_list = req['data']['Category'] - return json.dumps(mod_list[1], indent=4) - except: - return req + mod_list = data['data'] + return json.dumps(mod_list, indent=4) + except KeyError: + return data else: return 'Invalid Mode' -def products(techspecs_base, brand: list, category: list, date: dict, page, key, mode='raw'): - url = f"https://apis.dashboard.techspecs.io/{techspecs_base}/api/product/getAll?page=" + str(page) + +def get_all_products(techspecs_base_url, techspecs_api_key, brand=[], category=[], date={}, page=0, mode='raw'): + """ + Get a list of products matching the specified criteria. + + :param base_url: the base URL of the TechSpecs API + :param bearer_token: the bearer token for API authentication + :param brand: a list of brand names to include in the search (default: []) + :param category: a list of category names to include in the search (default: []) + :param date: a dictionary containing 'from' and 'to' date strings to limit the search (default: {}) + :param page: the page number of the search results to retrieve (default: 0) + :param mode: the output mode ('raw' or 'pretty') + :return: the list of products in the specified output mode + """ + url = f'{techspecs_base_url}/v4/product/all?page={page}' payload = { "brand": brand, "category": category, - "from": date['from'], - "to": date['to'] + "from": date.get('from', ''), + "to": date.get('to', '') } - header = { + headers = { "Accept": "application/json", - "X-BLOBR-KEY": key, + "Authorization": f"Bearer {techspecs_api_key}", "Content-Type": "application/json" } - req = requests.post(url, json=payload, headers=header).json() + try: + response = requests.post(url, json=payload, headers=headers) + response.raise_for_status() + data = response.json() + except requests.exceptions.HTTPError as error: + return f"HTTP error occurred: {error}" + except requests.exceptions.RequestException as error: + return f"An error occurred: {error}" + except ValueError as error: + return f"Failed to decode JSON: {error}" + if mode == 'raw': - return req + return data elif mode == 'pretty': try: - mod_list = req['data']['product'] + mod_list = data['data'] return json.dumps(mod_list, indent=4) - except: - return req + except KeyError: + return data else: return 'Invalid Mode' + + + + +def get_all_brand_logos(techspecs_base_url, techspecs_api_key, mode='raw'): + """ + Get a list of all brand logos. + + :param base_url: the base URL of the TechSpecs API + :param bearer_token: the bearer token for API authentication + :param mode: the output mode ('raw' or 'pretty') + :return: the list of brand logos in the specified output mode + """ + url = f'{techspecs_base_url}/v4/brandlogo/all' + headers = { + "Accept": "application/json", + "Authorization": f"Bearer {techspecs_api_key}" + } + try: + response = requests.get(url, headers=headers) + response.raise_for_status() + data = response.json() + except requests.exceptions.HTTPError as error: + return f"HTTP error occurred: {error}" + except requests.exceptions.RequestException as error: + return f"An error occurred: {error}" + except ValueError as error: + return f"Failed to decode JSON: {error}" + + if mode == 'raw': + return data + elif mode == 'pretty': + try: + mod_list = data['data'] + return json.dumps(mod_list, indent=4) + except KeyError: + return data + else: + return 'Invalid Mode' + + + + +def machine_id_search(techspecs_base_url, techspecs_api_key, machine_id, mode='raw'): + """ + Look up a product by its machine ID or code name. + + :param base_url: the base URL of the TechSpecs API + :param bearer_token: the bearer token for API authentication + :param machine_id: the machine ID or code name of the product to look up + :param mode: the output mode ('raw' or 'pretty') + :return: the search results in the specified output mode + """ + url = f'{techspecs_base_url}/v4/product/search/machineid?query={machine_id.strip()}' + headers = { + "Accept": "application/json", + "Authorization": f"Bearer {techspecs_api_key}" + } + try: + response = requests.post(url, headers=headers) + response.raise_for_status() + data = response.json() + except requests.exceptions.HTTPError as error: + return f"HTTP error occurred: {error}" + except requests.exceptions.RequestException as error: + return f"An error occurred: {error}" + except ValueError as error: + return f"Failed to decode JSON: {error}" + + if mode == 'raw': + return data + elif mode == 'pretty': + return json.dumps(data, indent=4) + else: + return 'Invalid Mode' + From 7bb0f8d73bd323f42079737930489b10ff5fc429 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:50:05 +0100 Subject: [PATCH 15/22] Update advanced_search.py --- examples/advanced_search.py | 79 ++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/examples/advanced_search.py b/examples/advanced_search.py index 17f7d32..4994b87 100644 --- a/examples/advanced_search.py +++ b/examples/advanced_search.py @@ -1,29 +1,70 @@ -# List all products by brand, category and release date import techspecs +import datetime -# TechSpecs API Key -techspecs_key = "techspecs_api_key" +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" -# enter the page number to fetch results from -page = 1 +# Output mode ('raw' or 'pretty') +mode = 'pretty' -# type in the name of the brand you're looking for or leave this field empty to see results from all brands -brand = ["Apple"] +# Set constants +DEFAULT_PAGE = 0 +DEFAULT_MODE = 'pretty' +VALID_MODES = ['pretty', 'raw'] -# type in the name of the category you're looking for or leave this field empty to see results from all categories -category = ["smartphone"] +# Define function to validate date format +def is_valid_date(date_str): + try: + datetime.datetime.strptime(date_str, '%Y-%m-%d') + return True + except ValueError: + return False -# please provide a date range to narrow your search. Leave this field empty to fetch all results from all dates -date = { - "from": "2010-01-01", # YYYY-MM-DD - "to": "2022-03-15" # YYYY-MM-DD +# Define function to validate parameters +def validate_parameters(brand, category, date=None, page=DEFAULT_PAGE, mode=DEFAULT_MODE): + if not isinstance(brand, list): + raise ValueError('Brand should be a list.') + + if not isinstance(category, list): + raise ValueError('Category should be a list.') + + if date is not None: + if not isinstance(date, dict): + raise ValueError('Invalid date format. Date should be a dictionary with keys "from" and "to".') + elif 'from' not in date or 'to' not in date: + raise ValueError('Invalid date format. Date dictionary should have keys "from" and "to".') + elif not is_valid_date(date['from']) or not is_valid_date(date['to']): + raise ValueError('Invalid date format. Date should be in the format YYYY-MM-DD.') + + if not isinstance(page, int) or page < 0: + raise ValueError('Page should be a non-negative integer.') + + if mode not in VALID_MODES: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.') + +# Define search parameters +brand = ["Apple"] +category = ["Smartphones"] +date = { + "from": "2010-01-01", + "to": "2022-03-15" } +page = 0 + +# Validate search parameters +try: + validate_parameters(brand, category, date=date, page=page, mode=mode) +except ValueError as e: + print(f"Invalid search parameters: {e}") + exit() -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.products(techspecs_base, brand, category, date, page, techspecs_key, mode='pretty') -# print the search results -print(response) +# Call TechSpecs API to get all products +try: + response = techspecs.get_all_products(techspecs_base_url, techspecs_api_key, brand, category, date, page, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") From b30216c9a16a71e72646ca2dc20b9d7184159349 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:50:40 +0100 Subject: [PATCH 16/22] Update and rename basic_search.py to product_search.py --- examples/basic_search.py | 20 -------------------- examples/product_search.py | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 20 deletions(-) delete mode 100644 examples/basic_search.py create mode 100644 examples/product_search.py diff --git a/examples/basic_search.py b/examples/basic_search.py deleted file mode 100644 index b95ba53..0000000 --- a/examples/basic_search.py +++ /dev/null @@ -1,20 +0,0 @@ -# Search for a product by name, version or features -import techspecs -import json - -# TechSpecs API Key -techspecs_key = "techspecs_api_key" - -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = 'a8TD3mkN49fhg2y' - -query = { - 'keyword': 'iPhone 13', # product name or version number to search - 'category': 'all', # product category to search -} - -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.search(base, query, key, mode='pretty') - -# print the search results -print(response) diff --git a/examples/product_search.py b/examples/product_search.py new file mode 100644 index 0000000..5d5480c --- /dev/null +++ b/examples/product_search.py @@ -0,0 +1,24 @@ +import techspecs +import json + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +query = { + 'keyword': 'iPhone 13', # product name or version number to search + 'category': '', # product category to search (e.g. 'Smartphones', 'Tablets', or leave empty to search all categories) + 'page': 0 # page number to fetch results from +} + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Search for a product by name, version, or features +try: + response = techspecs.product_search(techspecs_base_url, query, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") From 7245c9dc66c0e0d1d57a8619b5580462a2d34906 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:51:35 +0100 Subject: [PATCH 17/22] Update and rename all_brands.py to list_all_brands.py --- examples/all_brands.py | 13 ------------- examples/list_all_brands.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) delete mode 100644 examples/all_brands.py create mode 100644 examples/list_all_brands.py diff --git a/examples/all_brands.py b/examples/all_brands.py deleted file mode 100644 index c77346e..0000000 --- a/examples/all_brands.py +++ /dev/null @@ -1,13 +0,0 @@ -import techspecs - -# TechSpecs API Key -techspecs_key = "techspecs_api_key" - -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" - -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.brands(techspecs_base, techspecs_key, mode='pretty') - -# print the list of all brands -print(response) diff --git a/examples/list_all_brands.py b/examples/list_all_brands.py new file mode 100644 index 0000000..f335b77 --- /dev/null +++ b/examples/list_all_brands.py @@ -0,0 +1,29 @@ +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Define function to validate parameters +def validate_parameters(mode): + if mode not in ['raw', 'pretty']: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of ["raw", "pretty"].') + +# Validate parameters +try: + validate_parameters(mode) +except ValueError as e: + print(f"Invalid parameters: {e}") + exit() + +# Call TechSpecs API to get all brands +try: + response = techspecs.get_all_brands(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") From bb8e61b033668177f8ffb07ebbc76a3d7f184f72 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:52:01 +0100 Subject: [PATCH 18/22] Rename list_all_brands.py to get_all_brands.py --- examples/{list_all_brands.py => get_all_brands.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{list_all_brands.py => get_all_brands.py} (100%) diff --git a/examples/list_all_brands.py b/examples/get_all_brands.py similarity index 100% rename from examples/list_all_brands.py rename to examples/get_all_brands.py From 652ecd92b4e245800b87afb48be636badde17a7e Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:52:20 +0100 Subject: [PATCH 19/22] Update and rename all_categories.py to get_all_categories.py --- examples/all_categories.py | 13 ------------- examples/get_all_categories.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) delete mode 100644 examples/all_categories.py create mode 100644 examples/get_all_categories.py diff --git a/examples/all_categories.py b/examples/all_categories.py deleted file mode 100644 index 18ef2e1..0000000 --- a/examples/all_categories.py +++ /dev/null @@ -1,13 +0,0 @@ -import techspecs - -# TechSpecs API Key -techspecs_key = "techspecs_api_key" - -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" - -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.categories(techspecs_base, techspecs_key, mode='pretty') - -# print the list of all categories -print(response) diff --git a/examples/get_all_categories.py b/examples/get_all_categories.py new file mode 100644 index 0000000..940c5f2 --- /dev/null +++ b/examples/get_all_categories.py @@ -0,0 +1,33 @@ +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Define constants +DEFAULT_MODE = 'pretty' +VALID_MODES = ['pretty', 'raw'] + +# Validate parameters +def validate_parameters(mode=DEFAULT_MODE): + if mode not in VALID_MODES: + raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.') + +# Validate search parameters +try: + validate_parameters(mode=mode) +except ValueError as e: + print(f"Invalid search parameters: {e}") + exit() + +# Call TechSpecs API to get all categories +try: + response = techspecs.get_all_categories(techspecs_base_url, techspecs_api_key, mode=mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") From c307fdade851f39948386eb50112ffa467fb3652 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:52:47 +0100 Subject: [PATCH 20/22] Update product_detail.py --- examples/product_detail.py | 40 +++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/examples/product_detail.py b/examples/product_detail.py index e9b5629..1e82814 100644 --- a/examples/product_detail.py +++ b/examples/product_detail.py @@ -1,17 +1,35 @@ -# Get the standardized specifications of a specified product import techspecs -# TechSpecs API Key -techspecs_key = "techspecs_api_key" +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" -# TechSpecs base https://apis.dashboard.techspecs.io/{techspecs_base} -techspecs_base = "a8TD3mkN49fhg2y" +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" -# TechSpecs product id -techspecs_id = "6186b047987cda5f88311983" +# TechSpecs product ID +techspecs_product_id = "63e96260ff7af4b68a304e40" -# choose between "pretty" or "raw" mode for viewing response -response = techspecs.detail(techspecs_base, techspecs_id, techspecs_key, mode='pretty') +# Query dictionary +query = { + "productId": techspecs_product_id +} -# print the specifications of the product -print(response) +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +try: + # Validate techspecs_product_id + if not isinstance(techspecs_product_id, str): + raise ValueError('TechSpecs Product ID should be a string.') + + # Validate mode + if mode not in ['raw', 'pretty']: + raise ValueError('Invalid mode. Mode should be "raw" or "pretty".') + + # Call TechSpecs API to get product details + response = techspecs.product_detail(techspecs_base_url, techspecs_product_id, techspecs_api_key, mode=mode) + + # Print the product details + print(response) +except Exception as e: + print(f"An error occurred: {e}") From a0b47514ddc59da1acadf1ed84e92c3e6c4b544b Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:53:47 +0100 Subject: [PATCH 21/22] Create machineid_search.py --- examples/machineid_search.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/machineid_search.py diff --git a/examples/machineid_search.py b/examples/machineid_search.py new file mode 100644 index 0000000..31a572b --- /dev/null +++ b/examples/machineid_search.py @@ -0,0 +1,20 @@ +import techspecs + +# TechSpecs API base URL +techspecs_base_url = "https://api.techspecs.io" + +# TechSpecs API bearer token +techspecs_api_key = "your_techspecs_api_key" + +# Serial number of the Apple machine to look up machineid_or_codename ex iphone 11,6 +machine_id = "iphone 11,6" + +# Output mode ('raw' or 'pretty') +mode = 'pretty' + +# Look up the Apple machine by its serial number +try: + response = techspecs.machine_id_search(techspecs_base_url, techspecs_api_key, machine_id, mode) + print(response) +except Exception as e: + print(f"An error occurred: {e}") From 90f57b2daee8bb905d73698976f23980e3f9ba38 Mon Sep 17 00:00:00 2001 From: TechSpecs Date: Tue, 7 Mar 2023 12:54:16 +0100 Subject: [PATCH 22/22] Update setup.cfg --- setup.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.cfg b/setup.cfg index 912f9ad..9cdc9c8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,9 @@ [metadata] name = TechSpecs -version = 1.0.0 +version = 0.0.0 author = TechSpecs author_email = support@techspecs.io -description = TechSpecs library for python +description = TechSpecs Python long_description = file: README.md long_description_content_type = text/markdown url = https://github.com/techspecs/techspecs-python @@ -21,4 +21,4 @@ packages = find: python_requires = >=3.6 [options.packages.find] -where = src \ No newline at end of file +where = src