From e2d8fb2bc4e623b3cb19dbcea96fa304a573c73b Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sun, 14 Aug 2022 01:55:32 +0200 Subject: [PATCH] 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 --- dependencies.py | 4 ++- vision-env/src/google_search.py | 18 ++++++++++ vision-env/src/{vision-test.py => main.py} | 7 ++-- vision-env/src/web_search/amazon_search.py | 31 ++++++++++++++++++ vision-env/src/web_search/google_search.py | 38 ++++++++++++++++++++++ 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 vision-env/src/google_search.py rename vision-env/src/{vision-test.py => main.py} (98%) create mode 100644 vision-env/src/web_search/amazon_search.py create mode 100644 vision-env/src/web_search/google_search.py diff --git a/dependencies.py b/dependencies.py index e1f4170..f4ae2dd 100644 --- a/dependencies.py +++ b/dependencies.py @@ -1,10 +1,12 @@ import os # List of prerequisite packages needed -os.system("pip install virtualenv") os.system("python -m pip install --upgrade pip") +os.system("pip install scipy") os.system("pip install numpy") +os.system("pip install virtualenv") os.system("pip install opencv-python") os.system("pip install pyautogui") os.system("pip install google-cloud") os.system("pip install google-cloud-vision") +os.system("pip install pycopy-webbrowser") diff --git a/vision-env/src/google_search.py b/vision-env/src/google_search.py new file mode 100644 index 0000000..56d7831 --- /dev/null +++ b/vision-env/src/google_search.py @@ -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) \ No newline at end of file diff --git a/vision-env/src/vision-test.py b/vision-env/src/main.py similarity index 98% rename from vision-env/src/vision-test.py rename to vision-env/src/main.py index 1ace2b3..8307709 100644 --- a/vision-env/src/vision-test.py +++ b/vision-env/src/main.py @@ -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) diff --git a/vision-env/src/web_search/amazon_search.py b/vision-env/src/web_search/amazon_search.py new file mode 100644 index 0000000..7ca7d43 --- /dev/null +++ b/vision-env/src/web_search/amazon_search.py @@ -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]) \ No newline at end of file diff --git a/vision-env/src/web_search/google_search.py b/vision-env/src/web_search/google_search.py new file mode 100644 index 0000000..ed3dd77 --- /dev/null +++ b/vision-env/src/web_search/google_search.py @@ -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") \ No newline at end of file