Tutorial on how to get this app running

In this page you will learn to execute the first few steps needed to get this app running on your tethys local portal

Python Shell in your local terminal

The API provided from the HydroShare Python library is fairly simple, but requires a few functions to be performed before it can run. Below are step by step instructions on how to perform the necessary prefacing functions.

Step 1: Install the hs_restclient

It is mandatory to download and install the hs_restclient before programming with the API. To do this, copy and paste the code shown below into the terminal

    
pip install hs_restclient

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

Finally, the programming in Python may begin!

Some modules may need to be imported beforehand depending on the API provided by HydroShare. For example, consider the API for adding a file to a HydroShare resource. The API code for this is shown below:

    
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 and HydroShareAuthBasic modules are imported from HydroShare, which help carry out the many API functions.

Replace the ‘myusername’ with the your personal HydroShare username and the ‘mypassword’ with the your HydroShare password.

Next, enter the path of the user’s chosen file which must be uploaded and entered with fpath. This helps with pushing the file from the original 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.