Exemplo n.º 1
0
    def __init__(self, orgs, tickets, users):
        super(BL, self).__init__()
        setup_logging()
        self.logger = logging.getLogger()

        self.orgs = orgs
        self.tickets = tickets
        self.users = users
Exemplo n.º 2
0
def main():
    setup_logging()
    logger = logging.getLogger()

    try:
        __build()

    except (KeyboardInterrupt, Exception) as e:
        logger.warn("Stopping tokoin: %s", str(e))
Exemplo n.º 3
0
    return fnames


def get_name_from_filename(fname: str) -> str:
    return os.path.splitext(os.path.basename(fname))[0].replace("_", " ")


GoodreadsArgs = namedtuple("GoodreadsArgs", [
    "quiet",
    "person",
    "book_file",
    "always_use_cache",
])

if __name__ == "__main__":
    setup_logging(verbose=True)
    fnames = get_filenames()
    for fname in fnames:
        person_name = get_name_from_filename(fname)
        logging.debug("Resolving picks for %s", person_name)
        args = GoodreadsArgs(
            quiet=False,
            person=person_name,
            book_file=fname,
            always_use_cache=True,
        )
        try:
            goodreads.main(args)
        except goodreads.NoCacheOverrideException:
            logging.debug("Not overriding choices for %s", person_name)
Exemplo n.º 4
0
    return unique_flag


def get_all_book_titles(all_people: List[str]) -> List[dict]:
    all_books = []
    s = set([])
    for person in all_people:
        books = read_resolved_books_for_person(person)
        book_ids = [get_book_id(book) for book in books]
        for book_id, book in zip(book_ids, books):
            if book_id not in s:
                all_books.append(book)
                s.add(book_id)
    return all_books


if __name__ == "__main__":
    setup_logging(verbose=False)
    # when None it means everyone
    cohort = None
    all_people = [person for person in get_all_people()]
    all_books = get_all_book_titles(all_people)
    are_unique = check_books_unique(all_books)
    if not are_unique:
        logging.error("Books not unique, stopping computation")
        raise SystemExit()
    scores = get_basic_bitch_scores(all_people)
    for person in sorted(scores, key=scores.get, reverse=True):
        score = scores[person]
        print("%s -> %.3f" % (person, score))
import data
import fit
import models
from log_utils import setup_logging


def parse_args():
    parser = argparse.ArgumentParser(
        description="Train classification models on ImageNet",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    models.add_model_args(parser)
    fit.add_fit_args(parser)
    data.add_data_args(parser)
    dali.add_dali_args(parser)
    data.add_data_aug_args(parser)
    return parser.parse_args()


if __name__ == '__main__':
    args = parse_args()
    if 'horovod' in args.kv_store:
        hvd.init()

    setup_logging(args)
    dllogger.log(step='PARAMETER', data=vars(args))

    model = models.get_model(**vars(args))
    data_loader = data.get_data_loader(args)

    fit.fit(args, model, data_loader)
Exemplo n.º 6
0
    elif args.command == "reward_create":
        function = reward_create
    elif args.command == "referral_config":
        function = referral_config
    elif args.command == "referral_create":
        function = referral_create
    elif args.command == "referral_remind":
        function = referral_remind
    elif args.command == "referral_list":
        function = referral_list
    elif args.command == "referral_validate":
        function = referral_validate
    elif args.command == "referral_claim":
        function = referral_claim
    elif args.command == "stash_save":
        function = stash_save
    elif args.command == "stash_save_check":
        function = stash_save_check
    else:
        parser.print_help()
        sys.exit(EXIT_NO_COMMAND)

    if function:
        function(args)


if __name__ == "__main__":
    setup_logging(logger, logging.DEBUG)
    log_socketio_version(logger)
    run_parser()
Exemplo n.º 7
0
    KEEP_RUNNING = False


def g_exception(greenlet):
    # pylint: disable=broad-except
    try:
        greenlet.get()
    except Exception as e:
        stack_trace = traceback.format_exc()
        msg = f"{e}\n---\n{stack_trace}"
        utils.email_exception(logger, msg)


KEEP_RUNNING = True
if __name__ == "__main__":
    ch = log_utils.setup_logging(logger, logging.DEBUG)
    log_utils.log_socketio_version(logger)

    # create tables
    db.create_all()
    create_role(Role.ROLE_ADMIN, "super user")
    create_role(Role.ROLE_FINANCE,
                "Can view all records, can authorize rewards")
    create_role(Role.ROLE_PROPOSER, "Can propose rewards")
    create_role(Role.ROLE_REFERRAL_CLAIMER, "Can claim referrals")
    create_role(Role.ROLE_USER, "Normal user")
    create_permission(Permission.PERMISSION_RECIEVE, "view account name")
    create_permission(Permission.PERMISSION_BALANCE, "view account balance")
    create_permission(Permission.PERMISSION_HISTORY, "view account history")
    create_permission(Permission.PERMISSION_TRANSFER, "transfer funds")
    create_permission(Permission.PERMISSION_ISSUE, "issue funds")
Exemplo n.º 8
0
    def set_page_title(self, search_str: str, page_title: str) -> None:
        if search_str not in self.cache:
            self.cache[search_str] = {}
        self.cache[search_str]["page_title"] = page_title

    def set_html_filename(self, search_str: str, fname: str) -> None:
        if search_str not in self.cache:
            self.cache[search_str] = {}
        self.cache[search_str]["html_file"] = fname

    def get_html_filename(self, search_str: str) -> str:
        return self.cache[search_str]["html_file"]


if __name__ == "__main__":
    setup_logging()
    parser = ArgumentParser()
    parser.add_argument("search_str")
    args = parser.parse_args()
    try:
        wiki_cache = WikiCache.load()
    except IOError:
        wiki_cache = WikiCache()
    search_str = args.search_str
    if search_str in wiki_cache:
        logging.debug("Loading page from cache...")
        fname = wiki_cache.get_html_filename(search_str)
        logging.debug("Reading HTML from file '%s'..." % fname)
        html = read_html(fname)
    else:
        data = search_wikipedia_curl(search_str)
Exemplo n.º 9
0
def main(args) -> bool:
    """
    Perform book resolution using goodreads and the command line for the given person
    :return:        If the resolution cache exists, return true iff it has been override
                    If it does *not* exist, return true
    """
    setup_logging(not args.quiet)
    chosen_books = []
    output_fname = get_output_fname(args.person)
    try:
        goodreads_resolution_cache = GoodreadsResolutionCache.load()
    except IOError:
        goodreads_resolution_cache = GoodreadsResolutionCache()
        goodreads_resolution_cache.save()
    if os.path.exists(output_fname):
        if args.always_use_cache:
            logging.warning(
                "Resolved picks file already exists for %s. Not overwriting.",
                args.person)
            raise NoCacheOverrideException()
        print("Resolved picks file already exists for {}.".format(args.person))
        if not confirm("Overwrite?"):
            raise NoCacheOverrideException()
    for book in get_books_from_file(args.book_file):
        # the 'book' is actually a query
        if book in goodreads_resolution_cache:
            logging.info("Found '%s' in Goodreads resolution cache", book)
            candidate = goodreads_resolution_cache.get_book(book)
            chosen_books.append(candidate)
        else:
            logging.info("Searching for '%s' on goodreads for person %s...",
                         book, args.person)
            root = search_for_book(book)
            relevant_books = suggest_book_from_results(book, root)
            if relevant_books == []:
                print("WARNING: no results for query \"{}\"".format(book))
                print("Possible typo?")
                if skip_or_exit():
                    continue
                # basically not skipping will write
            elif len(relevant_books) == 1:
                candidate = relevant_books[0]
            else:
                candidate = get_obviously_correct_book(relevant_books)
                if candidate:
                    logging.debug("We have a winner!")
                else:
                    logging.debug("No obviously correct book")
                    try:
                        candidate = resolve_via_human(book, relevant_books)
                    except NoBookSelectedException:
                        if skip_or_exit():
                            continue

            goodreads_resolution_cache.save_title_resolution(
                book, candidate.get_goodreads_id(), candidate)
            goodreads_resolution_cache.save()
            chosen_books.append(candidate)
    # create the candidates pool
    save_chosen_books(args.person, chosen_books)
    return True