Trivia Search is a project that uses Google's Cloud Vision and Custom Search APIs to answer trivia questions.
Inspired by Toby Mellor.
NOTE: This violates HQ Trivia’s Terms of Service if used in a live game. Therefore I have never used this during a live game and the above proof-of-concept demonstration is performed on a previous recorded game found on YouTube. I don’t condone the use of a bot in a live game.
You shall not (directly or indirectly): […] (v) use manual or automated software, devices, or other processes to “crawl” or “spider” any page of the App; (vi) harvest or scrape any Content from the Services;'
GIF created with LiceCap.
git clone [email protected]:bzsinger/trivia-search.git
- Sign up for Google Cloud to use Google's Cloud Vision API
- Within your Google Cloud dashboard, create a new project
- Download the Google Cloud SDK
- If the SDK downloads as a zip file, unzip and
cd
into thegoogle-cloud-sdk
directory. Run./install.sh
- When prompted to 'Modify profile to update your $PATH and enable shell command completion?', respond 'Y' and press enter
- In a new Terminal window, run
gcloud init
in thegoogle-cloud-sdk
folder
- Create a
keys.js
file in thetrivia-search
directory - Open the file and add the following code:
module.exports = {
API_KEY: 'PASTE_KEY_HERE',
CUSTOM_SEARCH_ENGINE: 'PASTE_SEARCH_ENGINE_ID_HERE'
}
- On the Google CSE page, create a new search engine by clicking 'Add'
- Enter 'www.example.com' under 'Sites to Search'
- Click on 'Create' and navigate back to the homepage
- Click on your new search engine's name
- Under 'Sites to Search', click the box next to 'www.example.com' and then click the 'Delete' button. Confirm the deletion by pressing 'OK'
- Set 'Search the entire web' to 'On'
- Scroll back up and click 'Search engine ID' in the details section
- Replace the
PASTE_SEARCH_ENGINE_ID_HERE
text inkeys.js
with the Search engine ID - On the Custom Search JSON page, scroll to the 'API key section'
- Click 'Get a key' and select the Google Cloud project you created earlier
- Replace the
PASTE_KEY_HERE
text inkeys.js
with the API key you just created
- On the Getting Started with Authentication page, within the 'Creating a service account' section, click on the 'Go to the Create Service Account Key page' button
- Ensure that the project you are creating a service key for is the project you created earlier
- Under 'Service Account', select 'New Service Account'
- Name the service account and set your role as 'Project > Owner'
- Ensure the key type is JSON and click the 'Create' button
- Continuing with the instructions from the Getting Started with Authentication page, after you've downloaded your key, place it in the directory of your choice
- Run
export GOOGLE_APPLICATION_CREDENTIALS="/[PATH]/[FILE_NAME].json"
, replacingPATH
with the path to your key andFILE_NAME
with your key's file name - Enable Google Cloud Vision for the project by navigating to the Cloud Vision API page, ensure the project is correct, and click 'Enable'
NOTE: You may be billed if you run too many custom searches or Cloud Vision queries
- Navigate to the Billing page and click 'Create Billing Account'
- Ensure the project and the billing account details are correct
- Name the billing account and click 'Continue'
- Complete the billing profile and click 'Submit and enable billing'
- Waiting for Mac screenshot thumbnail may delay your results. Disable it by following the instructions here.
cd trivia-search
npm install
./run-trivia.sh
Take screenshots of trivia questions and answers (see example above)
(Ctrl-C to exit)
|- helper-modules
|--- extract-qa.js - extracts question and answers from given text
|--- get-results.js - parses given search results
|--- print-results.js - prints results to the console in a human-readable format
|--- question-type.js - quick functions for categorizing a question (standard, these, negative)
|--- search.js - conducts a Google search for given text and returns a parsing of the results
|--- standard-question.js - protocol for handling a standard question
|--- these-question.js - protocol for handling a question that contains 'these' or 'the following'
|- test - landing folder for screenshots
|- test-completed - created by run script, stores screenshots post-parsing
|- index.js - conducts OCR and passes text along to search
|- keys.js - stores keys for search
|- package.json - project meta-information
|- README.md - you're here
|- run-trivia.sh - a script to easily run this project