def connect_to_todoist(self, api_token=None): if connected_to_internet(): if api_token is None: from dev.old.resources import default_token_path api_token = default_token_path if os.path.exists(api_token): from pyutils import get_token api_token = get_token(api_token) if True: print("WARNING - using mock to generate mock.") prototype = TodoistAPI(api_token) engine = 'pkl' # 'json' or 'pkl' from secrets import lib_root mock_path = os.path.join(lib_root, 'app_data', 'mock_TodoistAPI_py{}.{}'.format('3' if is_python_3() else '2', engine)) from pyutils import Mock self._api = Mock(prototype, dump_path=mock_path, dump_engine=engine) else: self._api = TodoistAPI(api_token) else: prototype = TodoistAPI() engine = 'pkl' # 'json' or 'pkl' from secrets import lib_root mock_path = os.path.join(lib_root, 'app_data', 'mock_TodoistAPI_py{}.{}'.format('3' if is_python_3() else '2', engine)) from pyutils import Mock self._api = Mock(prototype, dump_path=mock_path, dump_engine=engine)
def connect_to_todoist(self, api_token): import todoist if api_token is None: from dev.old.resources import default_token_path api_token = default_token_path if os.path.exists(api_token): from pyutils import get_token api_token = get_token(api_token) self._api = todoist.TodoistAPI(api_token)
def connect_to_todoist(self, api_token=None): if connected_to_internet(): import todoist if api_token is None: from resources import default_token_path api_token = default_token_path if os.path.exists(api_token): from pyutils import get_token api_token = get_token(api_token) self._api = todoist.TodoistAPI(api_token) else: raise NotImplementedError( "Todo - mock todoist api client that behaves ")
def __init__(self, mode='console'): self.last_request_ts = now() - timedelta( seconds=REQUEST_MEMORY_TIMEOUT) self.last_args = dict() self.mode = mode self.templates = WeightedRandomGenerator(templates) self.content_generators = { key: WeightedRandomGenerator(content[key]) for key in content } self._run_flag = True self.greetings = WeightedRandomGenerator(load_json('./greetings.json')) if self.mode == "telegram": from pyutils import get_token # done self.bot = telegram.Bot(get_token('./api.token')) self.update_id = None
def main(api_token): from pyutils import connected_to_internet if not connected_to_internet(): raise RuntimeError("Need connection to the internet to generate mock") if api_token is None: from resources import default_token_path api_token = default_token_path if os.path.exists(api_token): from pyutils import get_token api_token = get_token(api_token) else: raise RuntimeError("Need api token to generate mock") prototype = todoist.TodoistAPI(api_token) from resources import lib_root engine = 'pkl' # 'json' or 'pkl' mock_path = os.path.join(lib_root, 'resources', 'mock_TodoistAPI.{engine}'.format(engine=engine)) from pyutils import Mock mock_api = Mock(prototype, dump_path=mock_path, dump_engine=engine) api = todoist.TodoistAPI(api_token) from resources import lib_root engine = 'pkl' # 'json' or 'pkl' mock_path = os.path.join(lib_root, 'resources', 'mock_TodoistAPI.{engine}'.format(engine=engine)) from pyutils import Mock mock_api = Mock(prototype, dump_path=mock_path, dump_engine=engine) # now do sample requests print("Sync:\n", mock_api.sync().__repr__()[:200]) # _ = mock_api.updates # no such field, what was i thinking print("\n\tActivity:\n", mock_api.activity.__repr__()[:200]) print("\n\tcommit:\n", mock_api.commit().__repr__()[:200]) print("\n\titems:\n", mock_api.items.all().__repr__()[:200]) print("\n\tprojects:\n", mock_api.projects.all().__repr__()[:200]) print('It seems mock is doing alright')
unix_lib_path = os.path.expanduser("~/work/pa/PersonalAssistant") win_lib_path = 'C:\\Users\\Petr\\Desktop\\HomeAutomation\\PersonalAssistant' def is_unix(): val = os.path.join('_', '_') return val == "_/_" if is_unix(): if unix_lib_path not in sys.path: sys.path.append(unix_lib_path) else: if win_lib_path not in sys.path: sys.path.append(win_lib_path) import lib.stack as palib import pyutils import resources # ---------------------------------------------------------------------------------------------------------------------- # 2) class TodoistAPI from todoist.api import TodoistAPI api = TodoistAPI(pyutils.get_token()) # ---------------------------------------------------------------------------------------------------------------------- # 3) class PersonalAssistant pa = palib.PersonalAssistant()
# step 1, import todoist api from todoist.api import TodoistAPI import sys, os # os.path.abspath(__file__) # os.getcwd() personal_assistant_path = 'C:\\Users\\Petr\\Desktop\\HomeAutomation\\PersonalAssistant' sys.path.append(personal_assistant_path) # os.listdir(personal_assistant_path) from pyutils import get_token api = TodoistAPI(get_token()) api.sync() api.state.keys() # ['collaborators', # 'day_orders_timestamp', # 'live_notifications_last_read_id', # 'items', # 'collaborator_states', # 'labels', # 'reminders', # 'locations', # 'settings_notifications', # 'project_notes', # 'user', # 'filters', # 'day_orders', # 'live_notifications',