Skip to content

Commit

Permalink
Add sample script to add versions to a format (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Dec 23, 2019
1 parent 2872be7 commit e1a2bd9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion isogeo_pysdk/api/routes_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def update(self, frmt: Format) -> Format:
>>> # add new versions locally
>>> fmt_postgis.versions.extend(["3.0", "3.1"])
>>> # update online
>>> fmt_postgis_updted = isogeo.formats.update(fmt_pgis)
>>> fmt_postgis_updted = isogeo.formats.update(fmt_postgis)
"""
# check format UUID
if not checker.check_is_uuid(frmt._id):
Expand Down
71 changes: 71 additions & 0 deletions isogeo_pysdk/samples/current/add_format_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: UTF-8 -*-
#! python3 # noqa E265


"""
Name: Isogeo sample - Edit formats list in the API
Purpose: Used to update formats list, for example to add a new version
Author: Julien Moura (@geojulien)
Made on December 2019 to comply with the CD 14 request
"""


# ##############################################################################
# ########## Libraries #############
# ##################################

# Standard library
import logging
from os import environ
from timeit import default_timer

# 3rd party
from dotenv import load_dotenv

# Isogeo
from isogeo_pysdk import Isogeo

# #############################################################################
# ######## Globals #################
# ##################################

# environment vars
load_dotenv("prod.env", override=True)

# #############################################################################
# ##### Stand alone program ########
# ##################################
if __name__ == "__main__":
# chronometer
START_TIME = default_timer()

# handle warnings
if environ.get("ISOGEO_PLATFORM").lower() == "qa":
import urllib3

urllib3.disable_warnings()

# -- Authentication and connection ---------------------------------
# Isogeo client
isogeo = Isogeo(
auth_mode="user_legacy",
client_id=environ.get("ISOGEO_API_USER_LEGACY_CLIENT_ID"),
client_secret=environ.get("ISOGEO_API_USER_LEGACY_CLIENT_SECRET"),
auto_refresh_url="{}/oauth/token".format(environ.get("ISOGEO_ID_URL")),
platform=environ.get("ISOGEO_PLATFORM", "qa"),
)

# getting a token
isogeo.connect(
username=environ.get("ISOGEO_USER_NAME"),
password=environ.get("ISOGEO_USER_PASSWORD"),
)

# get a format
fmt_postgis = isogeo.formats.get("postgis")
fmt_postgis.versions.extend(["3.1", "3.0", "2.5", "2.4", "2.3"])
fmt_postgis_updted = isogeo.formats.update(fmt_postgis)

# properly closing connection
isogeo.close()

0 comments on commit e1a2bd9

Please sign in to comment.