Giter Club home page Giter Club logo

hqtrivia's Introduction

HQ Trivia Hack

Inspired by this medium post but uses Pillow for screenshotting and Google Vision API for OCR parsing instead.

Usage:

workon venv 
pip install -r requirements.txt

// download a credentials.json service credentials file from a Google Vision-enabled Cloud Platform project (see OCR section below)
// then create config.json following config.json.sample

// connect iphone to Mac
// position quicktime player at top left -> select New Movie Recording
// open recording button dropdown -> switch Movie recording to iphone

// run the full script:
// - will launch browser to google search of the question
// - in terminal, prints out the search results count for each q+a search (usually, take the  one with largest count)
python main.py

1 - Grab screenshot

USAGE: from screengrab import screenshot

  • Quicktime player must be positioned at top left of screen, on iPhone recording
  • Uses PILLOW imagegrab - bounding box grabs only question + the multiple choice answers

2 - OCR detect text

USAGE: from detect_text import parse_screenshot

  • Processes screenshot into question + answers
  • Launches browser to google search of the question

This uses Google Cloud Vision api, so make sure you've downloaded a service account file from a Google Cloud project that has enabled Google Cloud Vision. See "using a service account": https://cloud.google.com/vision/docs/auth

Then add the path of that service account json file config.json as CREDENTIALS_PATH.

py detect_text.py returns a dict:

{
    question: 'After Texas , what U . S . state produces the most crude oil ?'
    answers: ['Oklahoma', 'North Dakota', 'Alaska']
}

3 - Using Google Custom search, run three custom searches with question + answer.

USAGE: from google_search import run_query_all

https://developers.google.com/custom-search/json-api/v1/overview

Compare the total num results for each answer:

answer: Oklahoma === TOTAL: 1,180,000
answer: North Dakota === TOTAL: 1,360,000
answer: Alaska === TOTAL: 1,330,000

Notes:

  • if the question is a "not" question ("which of these is NOT...") take the one with the lowest count
  • it's not unusual for the answer to be the second largest

hqtrivia's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.