1
0

Implementation of search function for google.com and amazon.com (#20)

* Update dependencies

* Import new libraries for google search

* Implement simple google search function

* Global variable

* Rename main file

* Rename main file

* Add functions to do Google searches

* Remove unnecessary import

* Implement Amazon search for labels and colors

* Ops forgot to comment out test stuff
This commit is contained in:
Erick
2022-08-14 01:55:32 +02:00
committed by GitHub
parent a4a07da57d
commit e2d8fb2bc4
5 changed files with 95 additions and 3 deletions
+18
View File
@@ -0,0 +1,18 @@
import webbrowser
try:
from googlesearch import search
except ImportError:
print("No module named 'google' found")
#search_tm = ["never", "gonna", "give", "you", "up"]
def google_search(search_terms):
google_base_link = "https://www.google.com/search?q="
url = google_base_link + " ".join(search_terms)
print(url)
if __name__ == "__main__":
search_terms = []
google_search(search_terms)
@@ -4,12 +4,13 @@ import sys
import numpy as np
import cv2
import math
import colors_detection
import json
from genericpath import isfile
from pyautogui import size
from google.cloud import vision
import colors_detection
import google_search
# Minimum score required for labels detection
MIN_SCORE_REQUIRED = 0.80
@@ -98,7 +99,6 @@ if img_width / scr_width > 1 or img_height / scr_height > 1:
image = cv2.resize(image, (scaled_width, scaled_height), interpolation=cv2.INTER_CUBIC)
cv2.imwrite('~/vision-env/images/testset/test0/copy_res.jpg', image)
#FIXME: fix absolute/relative path problem on Linux on cloning image
clone = image.copy()
cv2.namedWindow("image")
@@ -186,3 +186,6 @@ for color_info in filtered_colors:
'\tScore: ' + str(round(color_info.score, 5)) +
'\tColor Name: ' + color_name +
'\n')
#queries = ["test", "search"]
#google_search(queries)
@@ -0,0 +1,31 @@
import webbrowser
def join_data(labels = [], colors = []):
for i in range(len(labels)):
label_joint = "+".join(labels[i])
for j in range(len(colors)):
color_joint = "+".join(colors[j])
return label_joint + " " + color_joint
def generate_url(keywords):
url = "https://www.amazon.it/s?k="
return url + keywords
def amazon_search(labels, colors):
keyword_list = join_data(labels, colors)
# C'mon Jeffrey you can do it!
jeff_net = generate_url(keyword_list)
webbrowser.open(jeff_net)
print(jeff_net)
if __name__ == "__main__":
amazon_search([""], [""])
## NOTHING TO SEE HERE...
#lbl = ["jeff", "besos", "halloween", "costume"]
#clr = ["orange"]
#amazon_search([lbl], [clr])
@@ -0,0 +1,38 @@
import webbrowser
def join_data(labels = [], colors = []):
for i in range(len(labels)):
label_joint = "+".join(labels[i])
for j in range(len(colors)):
color_joint = "+".join(colors[j])
return label_joint + " " + color_joint
def generate_url(keywords, search_type):
if search_type == '--shopping':
pre_url = "https://www.google.com/search?q="
post_url = "h&source=lmns&tbm=shop"
return pre_url + keywords + post_url
elif search_type == '--images':
pre_url = "https://www.google.com/search?q="
post_url = "&newwindow=1&tbm=isch&source=lnms"
return pre_url + keywords + post_url
else:
url = "https://www.google.com/search?q="
return url + keywords
def google_search(labels, colors, search_type):
keyword_list = join_data(labels, colors)
print(keyword_list)
url = generate_url(keyword_list, search_type)
webbrowser.open(url)
print(url)
## TEST ZONE - KEEP AWAY!
#lbl = ["shirt", "long", "sleeve"]
#clr = ["blue", "light"]
#google_search([lbl], [clr], "--images")