def workflowy_login(): data = app.current_request.json_body # Login to workflowy and collect the session token.. try: wf = Workflowy(username=data['username'], password=data['password']) return {'session_id': wf.browser.session.cookies.get('sessionid')} except WFLoginError: raise BadRequestError("Cannot authorize with Workflowy")
def test_op(session: Workflowy): # create nodes node = session.root.create() node2 = session.root.create() assert not node assert node2 not in node # node relation subnode = node.create() subnode2 = node.create() subnode3 = node.create() assert node assert len(node) == 3 assert subnode2.parent == node assert subnode3.parent == node # node support iter for some in node: if subnode == some: break else: assert False subnode.edit("Welcome") subnode.delete() assert len(node) == 2 # edit node and marked as complete subnode2.edit("test") subnode2.edit(description="Welcome") subnode2.complete() # edit node subnode3.edit("test2") subnode3.uncomplete() assert session.main[subnode3.projectid].raw is subnode3.raw nodes = {node, node2, subnode2, subnode3} for node in session.root.walk(): node.projectid # UUID-like str or "None"(DEFAULT_ROOT_NODE_ID) node.last_modified # last modified time in python or workflowy time node.name # name node.children # children node.description # description node.completed_at # complete marking time in python or workflowy time (or None) node.is_completed # [READ-ONLY?] boolean value for completed. node.shared node.parent # parent node (or None, that is root node) # just print tree; session.root.pretty_print() # or node.pretty_print() with session.transaction(): for node in nodes: node.delete()
def workflowy_data(): data = app.current_request.json_body # Login to workflowy and collect the session token.. try: wf = Workflowy(sessionid=data['session_id']) data = [] for root_node in wf.root: data.append(render_nested_json(root_node)) return data except WFLoginError: raise BadRequestError("Cannot authorize with Workflowy")
def parse_email(event): obj = s3_client.get_object(Bucket='email.personalstats.nl', Key=event.key) email_file = obj['Body'].read().decode('utf-8') email_content = email.message_from_string(email_file) email_code = email_content['to'].split('-', 1)[0] sub = email_content['to'][len(email_code) + 1:].split('@')[0] cognito_user = cognito_client.list_users( UserPoolId=config('COGNITO_USER_POOL_ID'), Filter="sub = \"{}\"".format(sub)).get('Users') if len(cognito_user) != 1: s3_client.delete_object(Bucket='email.personalstats.nl', Key=event.key) raise NotFoundError( 'User {sub}, not found, deleting message'.format(sub)) attributes = cognito_user[0].get("Attributes", []) user_email_code = list( filter(lambda attr: attr.get("Name") == "custom:email_code", attributes)) if not email_code == user_email_code[0].get("Value"): s3_client.delete_object(Bucket='email.personalstats.nl', Key=event.key) raise NotFoundError('User not found, deleting message') # Get session id session_id = list( filter(lambda attr: attr.get("Name") == "custom:session_id", attributes)) if len(session_id) != 1: s3_client.delete_object(Bucket='email.personalstats.nl', Key=event.key) raise NotFoundError('User not found, deleting message') # Get the post data: expecting: {"name": "node content here"} # data = app.current_request.json_body # Setup workflowy wf = Workflowy(sessionid=session_id[0].get("Value")) node = wf.root.create() try: node.edit(email_content['subject']) return {"status": 'ok'} except WFLoginError: # TODO: email the user once the let them know we have trouble with the # connection to workflowy. (and then suffix the expended session ID) s3_client.delete_object(Bucket='email.personalstats.nl', Key=event.key) raise BadRequestError( "Cannot authorize with Workflowy, deleting message") # print("Object uploaded for bucket: %s, key: %s" % (event.bucket, event.key)) s3_client.delete_object(Bucket='email.personalstats.nl', Key=event.key)
def workflowy_inbox_handler(update, context): chat_id = update.effective_chat.id message = update.message.text wf = Workflowy(sessionid=config.WORKFLOWY_SESSION_ID) inbox_node = wf.main.find_node(config.WORKFLOWY_NODE_UUID) message_node = inbox_node.create() message_node.edit(message) success_message = f"✅ Додано в Inbox\! [Переглянути]({config.WORKFLOWY_INBOX_URI})" context.bot.send_message(chat_id=chat_id, text=success_message, parse_mode=ParseMode.MARKDOWN_V2)
def webhook_activate(webhook_code, cognito_id): # See if we can find a user in Cognito cognito_user = cognito_client.list_users( UserPoolId=config('COGNITO_USER_POOL_ID'), Filter="sub = \"{}\"".format(cognito_id)).get('Users') if len(cognito_user) != 1: raise NotFoundError('Webhook not found') # Check if the user has a webhook code attributes = cognito_user[0].get("Attributes", []) user_webhook_code = list( filter(lambda attr: attr.get("Name") == "custom:webhook_code", attributes)) if len(user_webhook_code) != 1: raise NotFoundError('Webhook not found') # Check if the webhook code matches if not webhook_code == user_webhook_code[0].get("Value"): raise NotFoundError('Webhook not found') # Get the session ID from the user attributes session_id = list( filter(lambda attr: attr.get("Name") == "custom:session_id", attributes)) if len(session_id) != 1: raise NotFoundError('Webhook not found') # Get the post data: expecting: {"name": "node content here"} data = app.current_request.json_body # Setup workflowy wf = Workflowy(sessionid=session_id[0].get("Value")) node = wf.root.create() try: node.edit(data.get("name")) return {"status": 'ok'} except WFLoginError: # TODO: email the user once the let them know we have trouble with the # connection to workflowy. (and then suffix the expended session ID) raise BadRequestError("Cannot authorize with Workflowy")
def session(): return Workflowy("hBYC5FQsDC")
from wfapi import Workflowy wf = Workflowy("hBYC5FQsDC")
def test_print(session: Workflowy): session.pretty_print()