Code Monkey home page Code Monkey logo

export-docx-py's Introduction

Isogeo - DOCX Exporter

PyPI PyPI - Python Version

Build Status Azure DevOps coverage

Documentation Status Code style: black

Python package to export Isogeo metadata into Word documents using the Python SDK and docxtpl.

Usage in a nutshell

  1. Install:

    pip install isogeo-export-docx
  2. Authenticate

    # import
    from isogeo_pysdk import Isogeo
    # API client
    isogeo = Isogeo(
        auth_mode="group",
        client_id=ISOGEO_API_GROUP_CLIENT_ID,
        client_secret=ISOGEO_API_GROUP_CLIENT_SECRET,
        auto_refresh_url="{}/oauth/token".format(ISOGEO_ID_URL),
        platform=ISOGEO_PLATFORM,
    )
    
    # getting a token
    isogeo.connect()
  3. Make a search:

    search = isogeo.search(include="all",)
    # close session
    isogeo.close()
  4. Export:

    # import
    from isogeotodocx import Isogeo2docx
    
    # output folder
    Path("_output/").mkdir(exist_ok=True)
    # template
    template_path = Path(r"tests\fixtures\template_Isogeo.docx")
    
    # instanciate
    toDocx = Isogeo2docx()
    
    # parse results and export it
    for md in search_results.results:
        # load metadata as object
        metadata = Metadata.clean_attributes(md)
        # prepare the template
        tpl = DocxTemplate(template_path.resolve())
        # fill the template
        toDocx.md2docx(docx_template=tpl, md=metadata)
        # filename
        md_name = metadata.title_or_name(slugged=1)
        uuid = "{}".format(metadata._id[:5])
        out_docx_filename = "_output/{}_{}.docx".format(md_name, uuid)
    
        # save it
        tpl.save(out_docx_filename)
    
        # delete template object
        del tpl

export-docx-py's People

Contributors

guts avatar simonsampere avatar

Watchers

 avatar  avatar

export-docx-py's Issues

Export Word : quelques champs ne sont pas récupérés correctement

Reproduire

  1. Lancer l'application isogeo2office.exe
  2. Exporter un catalogue en Word

Exemple pour la fiche Arbres remarquables de l'AEV
https://app.isogeo.com/groups/c18ddc43d1c045fc85c2ba1b4233eef1/resources/2906680962424c5aa2555fc8b2a33faf/identification

Au regard du fichier word metadonneesdonnees_libres_arbre_rem_newversion.docx obtenu en PJ, on constate :

  • Les conditions de diffusion ne sont pas récupérées ;
  • Le lien vers l'OpenCatalog n'est pas le bon ;
  • Les ressources ne sont pas récupérées (lien vers le site arbres.org par exemple).

metadonneesdonnees_libres_arbre_rem_newversion.docx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.