Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import shelve
- from os import getenv
- app_id=getenv('app_id')
- app_token=getenv('app_token')
- class API:
- def __init__(self, app_id, app_token, cache_file='db'):
- self.app_token = app_token
- self.app_id = app_id
- self.cache = shelve.open(cache_file, writeback=True)
- self._auth()
- def _auth(self):
- # do ur auth action
- self.cache['token'] = 'some_token'
- pass
- @property
- def logged_in(self):
- return bool(self.cache.get('token'))
- def funcs(self):
- pass
- class Action:
- def __init__(self, func, usage:str):
- self.usage = usage
- self.run = func
- class Nooi:
- def __init__(self, app_id, app_token):
- self.api = API(app_id, app_token)
- self.actions = dict()
- def run(self):
- if self.api.logged_in:
- self.login()
- while True:
- for k, func in self.actions.items():
- print(f'[{k}]: {func.usage}')
- choice = input('Choose your action:')
- if choice not in self.actions:
- print('Not valid action')
- continue
- action = self.actions[choice]
- try:
- action.run(self)
- except BaseException as e:
- print(e)
- continue
- def register(self, action:str, usage:str):
- def wrapper(func):
- self.actions[action] = Action(func, usage)
- def inner_wrapper(*args, **kwargs):
- return func(*args, **kwargs)
- return inner_wrapper
- return wrapper
- def login(self):
- pass
- nooi = Nooi(app_id=app_id, app_token=app_token)
- @nooi.register('cd', usage='Enter directory')
- def enter_file(instance):
- print('u r in enter directory action')
- fp = instance.fp
- choice = input('Input file index')
- @nooi.register('p', usage='Exit directory')
- def exit_file(instance):
- print('u r in exit directory action')
- fp = instance.fp
- choice = input('Input file index')
- @nooi.register('d', usage='Download file')
- def exit_file(instance):
- print('u r in Download file action')
- fp = instance.fp
- choice = input('Input file index')
- if __name__ == '__main__':
- nooi.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement