-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
garland
committed
Apr 25, 2024
1 parent
1e98761
commit aa62677
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Alert on Low Price | ||
|
||
This will use the Google Search Shopping API to search for an items and alert on the lowest prices. | ||
|
||
The Google Search Shopping API needs some post filtering. Here is the pricess. | ||
|
||
Lets say you search for "Aqara water leak sensor 3 pack" | ||
|
||
```yaml | ||
search_items: | ||
- item: Aqara water leak sensor 3 pack | ||
additional_title_filters: | ||
- 3 pack | ||
- something else | ||
not_from_these_sellers: | ||
- AliExpress.com | ||
- eBay | ||
price: | ||
low: 25 | ||
high: 53 | ||
``` | ||
It will bring back some undesirable results. We will do some post processing: | ||
## Dont process from not_from_these_sellers | ||
If the seller of the item is from this list, it wont process this item further | ||
## additional_title_filters | ||
It will bring back items that are not the 3 pack. | ||
The list of additional_title_filters allows us to keep on filtering until we only | ||
get what we want to see | ||
## Filter by price | ||
Then there is a price filter for low and high. The price has to be inbetween these two | ||
values | ||
# Google SERG API results | ||
```json | ||
"shopping_results":[ | ||
{ | ||
"position": 1, | ||
"title": "Aqara Water Leak Sensor, Requires Aqara Hub, Wireless Water Leak Detector ...", | ||
"link": "https://www.amazon.com/Aqara-11LM-SJCGQ-Water-Sensor/dp/B07D39MSZS?source=ps-sl-shoppingads-lpcontext&ref_=fplfs&psc=1&smid=A35PXP61BJ01A2", | ||
"product_link": "https://www.google.com/shopping/product/16070575325377975061?gl=us", | ||
"product_id": "16070575325377975061", | ||
"serpapi_product_api": "https://serpapi.com/search.json?device=desktop&engine=google_product&gl=us&google_domain=google.com&hl=en&location=United+States&product_id=16070575325377975061", | ||
"number_of_comparisons": "10+", | ||
"comparison_link": "https://www.google.com/shopping/product/16070575325377975061/offers?hl=en&gl=us&uule=w+CAIQICINVW5pdGVkIFN0YXRlcw&q=aqara+water+leak+sensor&prds=eto:7824488265108361142_0,pid:256602637212884877,rsk:PC_15591572458261802167&sa=X&ved=0ahUKEwi6mOye99uFAxXwkK8BHUnACxQQ3q4ECP0J", | ||
"serpapi_product_api_comparisons": "https://serpapi.com/search.json?engine=google_product&filter=eto%3A7824488265108361142_0%2Cpid%3A256602637212884877%2Crsk%3APC_15591572458261802167&gl=us&offers=1&product_id=16070575325377975061&sa=X&uule=w+CAIQICINVW5pdGVkIFN0YXRlcw&ved=0ahUKEwi6mOye99uFAxXwkK8BHUnACxQQ3q4ECP0J", | ||
"source": "Amazon.com - Seller", | ||
"price": "$18.99", | ||
"extracted_price": 18.99, | ||
"best_match": true, | ||
"rating": 3.7, | ||
"reviews": 11, | ||
"extensions": | ||
[ | ||
"Adjustable Alarm", | ||
"Siri" | ||
] | ||
, | ||
"thumbnail": "https://encrypted-tbn0.gstatic.com/shopping?q=tbn:ANd9GcQUhBxkP3xIg3RNHb0DdL-UCmEtmcC5rtCXy2wa2HQ1H7qS9C43XyiKU15apUfBsYP5A0zHuEW8e3btTNEHmPNBU0SUYmXxwyuu91X81lbj&usqp=CAE", | ||
"delivery": "$5.99 delivery" | ||
} | ||
, | ||
``` | ||
|
||
# Setup | ||
``` | ||
pip3 install google-search-results | ||
pip3 install pyyaml | ||
``` |
63 changes: 63 additions & 0 deletions
63
internet-item-price/alert_on_low_price/alert_on_low_price.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from serpapi import GoogleSearch | ||
import yaml | ||
|
||
## This dashboard helps you build your search query | ||
## https://serpapi.com/playground?engine=google_shopping&q=aqara+water+leak+sensor+3+pack&location=United+States&gl=us&hl=en | ||
|
||
|
||
## Open the yaml file and read the contents | ||
with open('search_items_gar.yaml', 'r') as file: | ||
data = yaml.safe_load(file) | ||
|
||
# Access the list by its key and loop through it | ||
for item in data['search_items']: | ||
print(f"Searching for: {item['item']}") | ||
|
||
## Set the search parameters | ||
params = { | ||
"api_key": "8876e8ba87e26bd147881434d36a0ee307d3d1110d598d39f5092b370988ee7a", | ||
"engine": "google_shopping", | ||
"google_domain": "google.com", | ||
"q": item['item'], | ||
"gl": "us", | ||
"hl": "en", | ||
"location": "United States" | ||
} | ||
|
||
## Google Shopping API search | ||
search = GoogleSearch(params) | ||
results = search.get_dict() | ||
|
||
## Loop through the results and run our various post result processing | ||
for product in results['shopping_results']: | ||
|
||
## If the key product['source'] is not found, then stop processing this product | ||
if 'source' not in product: | ||
continue | ||
|
||
## If the words in not_from_these_sellers is found in the product['source'], then stop processing this product | ||
if 'not_from_these_sellers' in item and any(x.lower() in product['source'].lower() for x in item['not_from_these_sellers']): | ||
# print(f"Skipping (not_from_these_sellers): {product['source']}\n") | ||
continue | ||
|
||
## For each additional_title_filters in the yaml file list, check if the words are in the product['title']. | ||
## All strings has to appear in the product['title']. If it is not, then stop processing this product | ||
should_skip_item = False | ||
for a_title_filter in item['additional_title_filters']: | ||
if a_title_filter.lower() not in product['title'].lower(): | ||
# print(f"Skipping {a_title_filter.lower()}: {product['title']}\n") | ||
should_skip_item = True | ||
|
||
## If we did not find all of the additional_title_filters strings in the title, then skip this product | ||
if should_skip_item: | ||
continue | ||
|
||
print(f"Title: {product['title']}\nPrice: {product['price']}\nSource: {product['source']}\n") | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
15 changes: 15 additions & 0 deletions
15
internet-item-price/alert_on_low_price/search_items_gar.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
search_items: | ||
- item: Aqara water leak sensor 3 pack | ||
## additional_title_filters are filters for the title after the search results has | ||
## been returned. Sometimes google returns items that are not the exact match. | ||
## The list here are "ANDs", all of them has to be found in the title of the | ||
## resutlts. | ||
additional_title_filters: | ||
- 3 pack | ||
- aqara | ||
not_from_these_sellers: | ||
- AliExpress.com | ||
price: | ||
low: 25 | ||
high: 53 |