Example #1
0
def reload_everything():
    import pkgutil

    files = [name for _, name, _ in pkgutil.iter_modules([''])]
    print(files)
    for file in files:
        reload(file)
Example #2
0
def start(num_browsers):
    global browser, translator

    print('Opening Firefox...')
    browser.start(num_browsers)
    colorama.init()
    translator = Translator()
    print('Done!')
Example #3
0
def reload(module_name='gbot'):
    module_name = profiles.get_name(module_name)
    module = importlib.import_module(module_name)
    importlib.reload(module)

    if module_name in profiles.PROFILES.values():
        profiles.reload()

    print(f'Module \'{module_name}\' reloaded!')
Example #4
0
def search(get_q, answers, driver=-1):
    q = get_q()
    q = q.replace(QUOTE, ' ')
    print('Google:',
          Back.GREEN + Fore.BLACK + q + Back.RESET + Fore.RESET + NEWLINE)

    url = get_search_url(q)
    browser.open_url(url, driver)

    return extract_results(answers, driver)
Example #5
0
def run_normal(search_answers_for_image=False):
    sw.start()

    print('Capturing...')
    ip = '192.168.1.' + str(oct4)
    image = screenstream.capture(ip)
    image = screen.process(image)
    history.add(image)

    run_image(image, search_answers_for_image)

    sw.stop_and_print('run() took: ')
Example #6
0
def splitted(text, answers):
    if lang:
        answers = lang.trim_answers(answers)
    print('Trimmed:', NEWLINE, NEWLINE.join(answers), NEWLINE, sep='')

    counts = []
    splitted_text = text.split()

    for a in answers:
        count = max([splitted_text.count(word) for word in a.split()])
        counts.append(count)

    return counts
Example #7
0
def run_history(folder, image, search_answers_for_image=False):
    sw.start()

    profile = profiles.current_profile
    dirname = os.path.dirname(__file__).replace('\\', '/')

    try:
        image = Image.open(f'{dirname}/{profile}/history/{folder}/{image}.png')
    except FileNotFoundError as e:
        print(e, NEWLINE)
        return

    image = screen.post_process(image)
    run_image(image, search_answers_for_image)

    sw.stop_and_print('run_history() took: ')
Example #8
0
def run_image(image, search_answers_for_image=False):
    print('OCR...')
    text = ocr.read_image(image, *config.ocr)

    while True:
        print(text, NEWLINE)
        text = quiz.process(text)
        q = NEWLINE.join(text)
        if quiz.is_valid(q):
            break
        else:
            text = ocr.read_image(image, *config.ocr2)
    print(q, NEWLINE)

    answer(q, search_answers_for_image)
Example #9
0
def print_no_results(s):
    print(Back.RED, 'No results found! ', s, Back.RESET, sep='')
Example #10
0
def print_roundrobin_reversed(to_be_printed):
    to_be_printed = [text.split(NEWLINE * 2)[::-1] for text in to_be_printed]
    combined_results = zip(*to_be_printed)
    for result in combined_results:
        for text in result:
            print(text, NEWLINE)
Example #11
0
 def get_eng_q(q):
     print('Translating...', end='\r')
     q = gg.translate(q)
     print('Translated:', NEWLINE, q)
     return q
Example #12
0
 def get_no_ans_q(q, answers):
     q = q.replace(' '.join(answers), '')
     print('Removed Answers:', NEWLINE, q)
     return q
Example #13
0
def answer(q, search_answers_for_image=False):
    def get_q(q):
        return q

    def get_no_ans_q(q, answers):
        q = q.replace(' '.join(answers), '')
        print('Removed Answers:', NEWLINE, q)
        return q

    def get_eng_q(q):
        print('Translating...', end='\r')
        q = gg.translate(q)
        print('Translated:', NEWLINE, q)
        return q

    translated = False

    print('')

    question = extract_question(q)
    answers = extract_answers(q)

    q = q.replace(NEWLINE, ' ')

    searches = []

    if search_answers_for_image:
        searches.append(('Image', True, answers))
        for i in range(len(answers)):
            gg.search_image(answers[i], i)
    else:
        get_q = partial(get_q, q)
        get_no_ans_q = partial(get_no_ans_q, q, answers)

        searches.append(('', get_q, answers, 0))
        searches.append((NO_ANS, get_no_ans_q, answers, 1))

        answers_in_eng = any([gg.is_eng(a) for a in answers])

        if config.enable_translate and (config.force_translate
                                        or answers_in_eng):
            if not answers_in_eng:
                answers = [gg.translate(a) for a in answers]
            get_eng_q = partial(get_eng_q, q)

            searches.append((ENG, get_eng_q, answers, 2))

    to_be_printed = []
    name_to_points = {}

    with ThreadPool(3) as pool:
        results = pool.map(do_search, searches)

    for search_res in results:
        name, formatted, exact_count, split_count = search_res

        to_be_printed.append(formatted)
        name_to_points[name + EXACT] = exact_count
        name_to_points[name + SPLIT] = split_count

    print_roundrobin_reversed(to_be_printed)

    name_to_points = points.negate_if_negative(q, name_to_points)
    points.add_total(name_to_points)
    name_to_points = points.color_best(name_to_points)

    # add answers as headers
    table = {ANSWERS: answers}
    table.update(name_to_points)

    print(question, NEWLINE)
    print(tabulate(table, headers='keys'))
    print(NEWLINE)
Example #14
0
from stopwatch import Stopwatch

sw = Stopwatch()
sw.start()
print('Loading...')

import screenstream
import gg
import ocr
import history
import count
import points
import os
import profiles
import importlib

from tabulate import tabulate
from colorama import Back, Fore
from PIL import Image
from functools import partial
from multiprocessing.dummy import Pool as ThreadPool
from lprint import print

print('Done!', end=' ')
sw.stop_and_print()

TAB = '\t'
SPACE = ' '
NEWLINE = '\n'
QUOTE = '"'