Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 90626d0

Browse files
Add files via upload
1 parent 233f826 commit 90626d0

File tree

7 files changed

+228
-0
lines changed

7 files changed

+228
-0
lines changed

‎tests/test_get_all_brandlogos.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import techspecs
2+
3+
# TechSpecs API base URL
4+
techspecs_base_url = "https://api.techspecs.io"
5+
6+
# TechSpecs API bearer token
7+
techspecs_api_key = "your_techspecs_api_key"
8+
9+
# Output mode ('raw' or 'pretty')
10+
mode = 'pretty'
11+
12+
# Call TechSpecs API to get all brand logos
13+
try:
14+
response = techspecs.get_all_brand_logos(techspecs_base_url, techspecs_api_key, mode=mode)
15+
print(response)
16+
except Exception as e:
17+
print(f"An error occurred: {e}")

‎tests/test_get_all_brands.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import techspecs
2+
3+
# TechSpecs API base URL
4+
techspecs_base_url = "https://api.techspecs.io"
5+
6+
# TechSpecs API bearer token
7+
techspecs_api_key = "your_techspecs_api_key"
8+
9+
# Output mode ('raw' or 'pretty')
10+
mode = 'pretty'
11+
12+
# Define function to validate parameters
13+
def validate_parameters(mode):
14+
if mode not in ['raw', 'pretty']:
15+
raise ValueError(f'Invalid mode: {mode}. Mode should be one of ["raw", "pretty"].')
16+
17+
# Validate parameters
18+
try:
19+
validate_parameters(mode)
20+
except ValueError as e:
21+
print(f"Invalid parameters: {e}")
22+
exit()
23+
24+
# Call TechSpecs API to get all brands
25+
try:
26+
response = techspecs.get_all_brands(techspecs_base_url, techspecs_api_key, mode=mode)
27+
print(response)
28+
except Exception as e:
29+
print(f"An error occurred: {e}")

‎tests/test_get_all_categories.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import techspecs
2+
3+
# TechSpecs API base URL
4+
techspecs_base_url = "https://api.techspecs.io"
5+
6+
# TechSpecs API bearer token
7+
techspecs_api_key = "your_techspecs_api_key"
8+
9+
# Output mode ('raw' or 'pretty')
10+
mode = 'pretty'
11+
12+
# Define constants
13+
DEFAULT_MODE = 'pretty'
14+
VALID_MODES = ['pretty', 'raw']
15+
16+
# Validate parameters
17+
def validate_parameters(mode=DEFAULT_MODE):
18+
if mode not in VALID_MODES:
19+
raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.')
20+
21+
# Validate search parameters
22+
try:
23+
validate_parameters(mode=mode)
24+
except ValueError as e:
25+
print(f"Invalid search parameters: {e}")
26+
exit()
27+
28+
# Call TechSpecs API to get all categories
29+
try:
30+
response = techspecs.get_all_categories(techspecs_base_url, techspecs_api_key, mode=mode)
31+
print(response)
32+
except Exception as e:
33+
print(f"An error occurred: {e}")

‎tests/test_machine_id_search.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import techspecs
2+
3+
# TechSpecs API base URL
4+
techspecs_base_url = "https://api.techspecs.io"
5+
6+
# TechSpecs API bearer token
7+
techspecs_api_key = "your_techspecs_api_key"
8+
9+
# Serial number of the Apple machine to look up machineid_or_codename ex iphone 11,6
10+
machine_id = "iphone 11,6"
11+
12+
# Output mode ('raw' or 'pretty')
13+
mode = 'pretty'
14+
15+
# Look up the Apple machine by its serial number
16+
try:
17+
response = techspecs.machine_id_search(techspecs_base_url, techspecs_api_key, machine_id, mode)
18+
print(response)
19+
except Exception as e:
20+
print(f"An error occurred: {e}")

‎tests/test_product_detail.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import techspecs
2+
3+
# TechSpecs API base URL
4+
techspecs_base_url = "https://api.techspecs.io"
5+
6+
# TechSpecs API bearer token
7+
techspecs_api_key = "your_techspecs_api_key"
8+
9+
# TechSpecs product ID
10+
techspecs_product_id = "63e96260ff7af4b68a304e40"
11+
12+
# Query dictionary
13+
query = {
14+
"productId": techspecs_product_id
15+
}
16+
17+
# Output mode ('raw' or 'pretty')
18+
mode = 'pretty'
19+
20+
try:
21+
# Validate techspecs_product_id
22+
if not isinstance(techspecs_product_id, str):
23+
raise ValueError('TechSpecs Product ID should be a string.')
24+
25+
# Validate mode
26+
if mode not in ['raw', 'pretty']:
27+
raise ValueError('Invalid mode. Mode should be "raw" or "pretty".')
28+
29+
# Call TechSpecs API to get product details
30+
response = techspecs.product_detail(techspecs_base_url, techspecs_product_id, techspecs_api_key, mode=mode)
31+
32+
# Print the product details
33+
print(response)
34+
except Exception as e:
35+
print(f"An error occurred: {e}")

‎tests/test_product_search.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import techspecs
2+
import json
3+
4+
# TechSpecs API base URL
5+
techspecs_base_url = "https://api.techspecs.io"
6+
7+
# TechSpecs API bearer token
8+
techspecs_api_key = "your_techspecs_api_key"
9+
10+
query = {
11+
'keyword': 'iPhone 13', # product name or version number to search
12+
'category': '', # product category to search (e.g. 'Smartphones', 'Tablets', or leave empty to search all categories)
13+
'page': 0 # page number to fetch results from
14+
}
15+
16+
# Output mode ('raw' or 'pretty')
17+
mode = 'pretty'
18+
19+
# Search for a product by name, version, or features
20+
try:
21+
response = techspecs.product_search(techspecs_base_url, query, techspecs_api_key, mode=mode)
22+
print(response)
23+
except Exception as e:
24+
print(f"An error occurred: {e}")
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import techspecs
2+
import datetime
3+
4+
# TechSpecs API base URL
5+
techspecs_base_url = "https://api.techspecs.io"
6+
7+
# TechSpecs API bearer token
8+
techspecs_api_key = "your_techspecs_api_key"
9+
10+
# Output mode ('raw' or 'pretty')
11+
mode = 'pretty'
12+
13+
# Set constants
14+
DEFAULT_PAGE = 0
15+
DEFAULT_MODE = 'pretty'
16+
VALID_MODES = ['pretty', 'raw']
17+
18+
# Define function to validate date format
19+
def is_valid_date(date_str):
20+
try:
21+
datetime.datetime.strptime(date_str, '%Y-%m-%d')
22+
return True
23+
except ValueError:
24+
return False
25+
26+
# Define function to validate parameters
27+
def validate_parameters(brand, category, date=None, page=DEFAULT_PAGE, mode=DEFAULT_MODE):
28+
if not isinstance(brand, list):
29+
raise ValueError('Brand should be a list.')
30+
31+
if not isinstance(category, list):
32+
raise ValueError('Category should be a list.')
33+
34+
if date is not None:
35+
if not isinstance(date, dict):
36+
raise ValueError('Invalid date format. Date should be a dictionary with keys "from" and "to".')
37+
elif 'from' not in date or 'to' not in date:
38+
raise ValueError('Invalid date format. Date dictionary should have keys "from" and "to".')
39+
elif not is_valid_date(date['from']) or not is_valid_date(date['to']):
40+
raise ValueError('Invalid date format. Date should be in the format YYYY-MM-DD.')
41+
42+
if not isinstance(page, int) or page < 0:
43+
raise ValueError('Page should be a non-negative integer.')
44+
45+
if mode not in VALID_MODES:
46+
raise ValueError(f'Invalid mode: {mode}. Mode should be one of {VALID_MODES}.')
47+
48+
# Define search parameters
49+
brand = ["Apple"]
50+
category = ["Smartphones"]
51+
date = {
52+
"from": "2010年01月01日",
53+
"to": "2022年03月15日"
54+
}
55+
page = 0
56+
57+
# Validate search parameters
58+
try:
59+
validate_parameters(brand, category, date=date, page=page, mode=mode)
60+
except ValueError as e:
61+
print(f"Invalid search parameters: {e}")
62+
exit()
63+
64+
65+
# Call TechSpecs API to get all products
66+
try:
67+
response = techspecs.get_all_products(techspecs_base_url, techspecs_api_key, brand, category, date, page, mode=mode)
68+
print(response)
69+
except Exception as e:
70+
print(f"An error occurred: {e}")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /