2019-07-19 06:33:34 +02:00
|
|
|
import logging
|
2019-06-06 11:43:47 +02:00
|
|
|
|
2020-01-03 21:34:04 +01:00
|
|
|
from src.server.external import request_lbrynet
|
2019-07-19 06:33:34 +02:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
ID_LIST = {'claim_id', 'parent_id', 'comment_id', 'channel_id'}
|
|
|
|
|
|
|
|
|
2019-08-24 05:51:39 +02:00
|
|
|
async def get_claim_from_id(app, claim_id, **kwargs):
|
2020-01-07 05:16:46 +01:00
|
|
|
try:
|
|
|
|
return (await request_lbrynet(app, 'claim_search', claim_id=claim_id, **kwargs))['items'][0]
|
|
|
|
except IndexError:
|
|
|
|
return
|
2019-08-24 05:51:39 +02:00
|
|
|
|
|
|
|
|
2019-07-19 06:33:34 +02:00
|
|
|
def clean_input_params(kwargs: dict):
|
|
|
|
for k, v in kwargs.items():
|
2019-09-06 17:33:38 +02:00
|
|
|
if type(v) is str and k is not 'comment':
|
2019-07-19 06:33:34 +02:00
|
|
|
kwargs[k] = v.strip()
|
|
|
|
if k in ID_LIST:
|
|
|
|
kwargs[k] = v.lower()
|
2020-03-27 22:44:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
def clean(thing: dict) -> dict:
|
|
|
|
return {k: v for k, v in thing.items() if v is not None}
|