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
def test_str(): key = '5ac8e9f7e58181a384951460e8da1a73' nml = muid.animal(key) assert nml == 'Leadable Boa'
def test_many(): for example in EXAMPLES: animal = muid.animal(example['key']) assert animal == example['pretty']
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())
def key_difficulty(key): return len(muid.animal(key).replace(' ', ''))
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(' ', ''))