Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find page by space and title #29

Closed
danizen opened this issue Sep 5, 2019 · 1 comment
Closed

Find page by space and title #29

danizen opened this issue Sep 5, 2019 · 1 comment

Comments

@danizen
Copy link
Contributor

danizen commented Sep 5, 2019

I have an idea to find the id of the page by space (key or title) and by page title. For a new page, the parent title could be given.

This would add a dependence (if I were to implement it) on jmespath. A search would have the following inputs:

  • space - interpreted as either space key or title
  • title - exact or approximate title of page

A method for an exact search:

def find_page(session, baseurl, **kwargs):
    cql_query_template = (
         'type=page'
         ' and (space="{space:s}" OR space.title~"{space:s}")'
         ' and title="{title:s}"')
    cql_query = cql_query_template.format(**kwargs)
    response = session.get(baseurl + '/search', params={'cql': cql_query})
    if not response.ok:
        raise Something()
    response_data = response.json()
    if response_data['size'] != 1:
        return None
    page_id = jmespath.search('results[0].content.id', response_data)
    page_link = baseurl + '/content/' + page_id
    return page_link

This could be generalized to support multiple "strategies", each a function taking the session, baseurl, and kwargs. This makes the search function more maintainable:

def cql_search_strategy(cql_query_template):
    def _strategy(session, baseurl, **kwargs):
        nonlocal cql_query_template
        cql_query = cql_query_template.format(**kwargs)
        response = session.get(baseurl + '/search', params={'cql': cql_query})
        # ....
    return _strategy

exact_title_strategy = cql_search_strategy('type=page and (space="{space:s}" OR space.title~"{space:s}") and title="{title:s}"')
title_contains_startegy = cql_search_strategy('type=page and (space="{space:s}" OR space.title~"{space:s}") and title~"{title:s}"')
@danizen
Copy link
Contributor Author

danizen commented Sep 5, 2019

Now that I am more up-to-speed on the existing issues #3 and #4, I think it is more natural to have a wrapper script that calls nbconflux.api.notebook_to_page appropriately for my environment.

The search strategies would not be simple at all - what should the parent page be? In my corporate environment I may be able to specify the parent page for all my notebooks, but what about in some other environment.

@danizen danizen closed this as completed Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant