2022-11-09 00:34:33 +02:00
|
|
|
from src.fw_api import list_libraries
|
|
|
|
from pyfzf.pyfzf import FzfPrompt
|
|
|
|
from loguru import logger
|
|
|
|
|
|
|
|
fzf = FzfPrompt()
|
|
|
|
|
|
|
|
|
|
|
|
def libraries(pg=None):
|
|
|
|
libs_res = list_libraries(pg=pg)
|
|
|
|
libs_count = libs_res.get('count')
|
|
|
|
libs_next = libs_res.get('next')
|
|
|
|
libs_prev = libs_res.get('previous')
|
|
|
|
libs = list_libraries()['results']
|
|
|
|
libraries_listing = []
|
|
|
|
if libs_next:
|
|
|
|
libraries_listing.append('Next')
|
|
|
|
if libs_prev:
|
|
|
|
libraries_listing.append('Prev')
|
|
|
|
for lib_i in libs:
|
|
|
|
index = libs.index(lib_i)
|
|
|
|
lib_name = lib_i.get('name')
|
2022-11-09 14:47:57 +02:00
|
|
|
lib_by = lib_i.get('actor').get('full_username')
|
|
|
|
libraries_listing.append(f'{index}.{lib_name} | by {lib_by}')
|
2022-12-18 03:02:53 +02:00
|
|
|
lib_select = fzf.prompt(
|
|
|
|
libraries_listing, f'--header=\'found {libs_count} libraries\'')[0].split('.', 1)
|
2022-11-09 00:34:33 +02:00
|
|
|
if lib_select[0] == 'Next':
|
|
|
|
libraries(pg=libs_next)
|
|
|
|
elif lib_select[0] == 'Prev':
|
|
|
|
libraries(pg=libs_prev)
|
|
|
|
else:
|
|
|
|
lib_addr = lib_select[0]
|
|
|
|
lib_name = lib_select[1]
|
|
|
|
lib_uuid = libs[int(lib_addr)].get('uuid')
|
|
|
|
return None, 'library', lib_name, lib_uuid
|