Tutorial on how to get this app running

Python Shell in your local terminal

The api provided from the HydroShare python library is very direct and easy to use. However to run it smoothly, you will need to perform a few functions as shown below to get efficient results:

Step 1: You will need to download install the hs_restclient before you can start programming with the api. So in the terminal, type

    
        pip install hs_restclient

    
  

Step 2: Now initiate by typing 'python' or 'python3'

Now we can start programming in Python

You will need to import a few modules depending on the api provided by HydroShare. For example let us consider this simple api of adding a file to a resource that belongs to us in HydroShare.

The api to do that is as follows,

    
        from hs_restclient import HydroShare, HydroShareAuthBasic
        auth = HydroShareAuthBasic(username='myusername', password='mypassword')
        hs = HydroShare(auth=auth)
        fpath = '/path/to/somefile.txt'
        resource_id = hs.addResourceFile('ID OF RESOURCE GOES HERE', fpath)
    
  

The HydroShare, HydroShareAuthBasic modules are imported from HydroShare which help carry out the api functions.

You could replace the 'myusername' with your HydroShare username and the 'mypassword' with your password of your HydroShare account.

Next, enter the path of file which you would want to upload and it is eneterd with fpath. This will help with pushing the file from that location to the HydroShare database.

The Resource ID should be entered in the place of 'ID OF RESOURCE GOES HERE'

The resource Id is a unique identifier for every resource on HydroShare. You can findit by browsing to your HydroShare resource copying the ID from the URL. Like for example, this is an example hyperlink https://www.hydroshare.org/resource/08c6e88adaa647cd9bb28e5d619178e0/ from which the 32 letter combination at the end is called the resource id. And so the resource id from the example hyperlink is 08c6e88adaa647cd9bb28e5d619178e0

Resource ID

Online Python Shell

You can also try working each of the api functions online. It is the same process as doing it in the terminal, only that you will need not install hs_restclient using pip.

So you could use the code as shown below as a demo, which is the same case of adding a file to a resource that belongs to you in HydroShare.

The api to do that is as follows,

    
        from hs_restclient import HydroShare, HydroShareAuthBasic
        auth = HydroShareAuthBasic(username='myusername', password='mypassword')
        hs = HydroShare(auth=auth)
        fpath = '/path/to/somefile.txt'
        resource_id = hs.addResourceFile('ID OF RESOURCE GOES HERE', fpath)
    
  

The HydroShare, HydroShareAuthBasic modules are imported from HydroShare which help carry out the api functions.

You could replace the 'myusername' with your HydroShare username and the 'mypassword' with your password of your HydroShare account.

Next, enter the path of file which you would want to upload and it is eneterd with fpath. This will help with pushing the file from that location to the HydroShare database.

The Resource ID should be entered in the place of 'ID OF RESOURCE GOES HERE'

Here is the online Python IDE that will help you practise the code shown above.

Tethys Development Platform

The tethys platform helps with using all these functions in the webapp. But in order to use them with the same ease and functionality you will have to install this app in your local tethys virtual environment.

In order to learn about the installation of tethys, you can click here.

Once you have installed tethys in your local and have learnt how to install an app in development, you can go ahead and clone the source code from here and install it.

I have enabled HydroShare authentication for login but in order for that to work, you will have to edit your 'portal_config.yml' file which can be found in this location path '/Users/(your_username)/.tethys/portal_config.yml'

The content found below can be copied and be used to replace it with the existing data in your yml file.

    
    # Portal Level Config File

    # see tethys documentation for how to setup this file
    version: 1.0
    name:
    apps: {}
    settings:
    SECRET_KEY: zcaK7mnAszRLZxUci0m66o65cShSukF33qGXKkcIB5LegvvVsO
    AUTHENTICATION_BACKENDS:
        - tethys_services.backends.hydroshare.HydroShareOAuth2
    OAUTH_CONFIGS:
        SOCIAL_AUTH_HYDROSHARE_KEY: 'NAltmPyhuPITKrId2ZFdc7U0unHCAc5qHa4M3oLz'
        SOCIAL_AUTH_HYDROSHARE_SECRET: 'leWjRXtmUDmDL2YePG0KfRFbqUi0FX5XgvXiLsFGA3uVEWEaUnww7m7POjl0yqPKgNddgVFhVeremgiRqce74YjgxA2o2gkoek1q1lB7okuaJmyJQVIqM322mbpiIU0L'
    site_content: {}