Metadata-Version: 2.1
Name: hidroconta
Version: 1.2.1
Summary: Facilitate access to Demeter REST interface endpoints, provided by Hidroconta S.A.U.
Home-page: UNKNOWN
Author: JavierL
Author-email: javier.lopez@hidroconta.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# Integrations-PythonAPI
Python API to facilitate access to Demeter REST interface endpoints.

The API allows the management of large amounts of data using the Pandas library, provided that the following directive is used in method calls:
```
# Pandas = True returns a pandas dataframe instead a json
```

The way to use the API is the following:

- Import the desired modules:
```
import hydroconta.api as demeter
import hydroconta.types as hydrotypes
import pandas as pd
import datetime
import hydroconta.endpoints as hydroenpoints
```
- Select the server with which you want to communicate (you can modify it at any time):
```
# Set server
demeter.set_server(hydroendpoints.Server.MAIN)
```

- Login to this server
```
# Login
demeter.login('USERNAME', 'PASSWORD')
```

Once the previous steps have been followed, you can make any query about the system.
Some of them are:

- Search
```
# Search
df = demeter.search(text='SAT', element_types=[hydrotypes.Element.COUNTER, hydrotypes.Element.ANALOG_INPUT, hydrotypes.Element.RTU], status=hidrotypes.Status.ENABLED, pandas=True)
print(df)
```

- Getting history
```
# Get historics
df = demeter.get_historics(start_date=datetime.datetime.now(), end_date=datetime.datetime.now(), element_ids=[1000], subtype=hydrotypes.AnalogInputHist.subtype, subcode=[hidrotypes.AnalogInputHist.subcode], pandas=True)
print(df)
```

- Getting elements
```
# Get
df = demeter.get_rtus(element_id=17512, pandas=True)
print(df)
```
The API also defines a special exception when the call to the Demeter endpoint does not return the expected result.
The exception is called 'DemeterStatusCodeException' and contains the HTTP error code.
```
# Exception treatment
try:
    df = demeter.get_rtus(element_id=17512, pandas=True).
except demeter.DemeterStatusCodeException as status_code:
    print('Error {}'.format(status_code))
```
- Finally, a logout should be made on the server
```
demeter.logout()
```



