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:
+3
-1
@@ -1,10 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# List of prerequisite packages needed
|
# List of prerequisite packages needed
|
||||||
os.system("pip install virtualenv")
|
|
||||||
os.system("python -m pip install --upgrade pip")
|
os.system("python -m pip install --upgrade pip")
|
||||||
|
os.system("pip install scipy")
|
||||||
os.system("pip install numpy")
|
os.system("pip install numpy")
|
||||||
|
os.system("pip install virtualenv")
|
||||||
os.system("pip install opencv-python")
|
os.system("pip install opencv-python")
|
||||||
os.system("pip install pyautogui")
|
os.system("pip install pyautogui")
|
||||||
os.system("pip install google-cloud")
|
os.system("pip install google-cloud")
|
||||||
os.system("pip install google-cloud-vision")
|
os.system("pip install google-cloud-vision")
|
||||||
|
os.system("pip install pycopy-webbrowser")
|
||||||
|
|||||||
@@ -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 numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
import math
|
import math
|
||||||
import colors_detection
|
|
||||||
import json
|
import json
|
||||||
from genericpath import isfile
|
from genericpath import isfile
|
||||||
from pyautogui import size
|
from pyautogui import size
|
||||||
from google.cloud import vision
|
from google.cloud import vision
|
||||||
|
|
||||||
|
import colors_detection
|
||||||
|
import google_search
|
||||||
# Minimum score required for labels detection
|
# Minimum score required for labels detection
|
||||||
MIN_SCORE_REQUIRED = 0.80
|
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)
|
image = cv2.resize(image, (scaled_width, scaled_height), interpolation=cv2.INTER_CUBIC)
|
||||||
cv2.imwrite('~/vision-env/images/testset/test0/copy_res.jpg', image)
|
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()
|
clone = image.copy()
|
||||||
|
|
||||||
cv2.namedWindow("image")
|
cv2.namedWindow("image")
|
||||||
@@ -186,3 +186,6 @@ for color_info in filtered_colors:
|
|||||||
'\tScore: ' + str(round(color_info.score, 5)) +
|
'\tScore: ' + str(round(color_info.score, 5)) +
|
||||||
'\tColor Name: ' + color_name +
|
'\tColor Name: ' + color_name +
|
||||||
'\n')
|
'\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")
|
||||||
Reference in New Issue
Block a user