Exemplo n.º 1
0
def _save_query(key: str) -> str:
    key_bytes = key.encode('ascii')
    difficulty = muid.difficulty(key)

    if difficulty < MIN_DIFFICULTY:
        detail = f'key is of difficulty {difficulty} < MIN_DIFFICULTY={MIN_DIFFICULTY}'
        raise HTTPException(http.HTTPStatus.EXPECTATION_FAILED, detail=detail)

    bhash = muid.bhash(key_bytes).decode('ascii')
    animal = muid.animal(key_bytes)

    log.info(
        f"bhash={repr(bhash)}, difficulty={repr(difficulty)}, animal={repr(animal)}"
    )

    query = keys_tbl.insert().values(key=key,
                                     difficulty=difficulty,
                                     hash=bhash,
                                     animal=animal,
                                     used_by=None)
    return query
Exemplo n.º 2
0
def test_str():
    key = '5ac8e9f7e58181a384951460e8da1a73'
    nml = muid.animal(key)
    assert nml == 'Leadable Boa'
Exemplo n.º 3
0
def test_many():
    for example in EXAMPLES:
        animal = muid.animal(example['key'])
        assert animal == example['pretty']
Exemplo n.º 4
0
from microprediction import MicroCrawler, new_key
from pprint import pprint
import muid

difficulty = 8
print('Generating MUID of difficulty '+str(difficulty)+' - please be patient')
write_key = new_key(difficulty=difficulty)
print(write_key)
print(muid.animal(write_key) + ' is starting up ')
crawler   = MicroCrawler(write_key=write_key, sleep_time=30, verbose=True )
crawler.run()

pprint(crawler.get_performance())


Exemplo n.º 5
0
 def key_difficulty(key):
     return len(muid.animal(key).replace(' ', ''))
Exemplo n.º 6
0
 def animal_from_key(key):
     return muid.animal(key)
 def key_difficulty(key):
     animal = KeyConventions.animal_from_key(key)
     return 0 if animal is None else len(muid.animal(key).replace(' ', ''))