<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <img src="http
Step1:  Tutorial - How to work with the OpenEnergy Platform (OEP)
<br>
<div class="alert alert-block alert-danger">
This is an important information!
</div>
<div class="alert alert-block alert-info">
This is an information!
</div>
<div class="alert alert-block alert-success">
This is your task!
</div>
This tutorial gives you an overview of the OpenEnergy Platform and how you can work with the REST-full-HTTP API in Python. <br>
The full API documentaion can be found on ReadtheDocs.io.
Part I
0 Get started - Sign-in and get your own token <br>
0 Setup token <br>
1 Create a table <br>
2 Delete a table <br>
3 Query table columns <br>
4 Insert Data into a table <br>
5 Insert data into a specific row <br>
6 Alter data in a table <br>
Links and further information
How to work with Python and Jupyter Notebooks <br>
OPSD wiki <br>
nbviewer example
Overview of Packages
Step2:  0.1 About the Database and used Packages
Data are stored and ordered by topic under the "schema" tab
Step3:  1. Create a table / Table Architecure
You installed all Python packages? Let's create our first database table
Step4:  <div class="alert alert-block alert-info">
**Response [201]** succesfully created table! <br>
**Response [500]** table already exists!
</div>
Step5:  <div class="alert alert-block alert-info">
**Response [200]** table exists! <br>
**Response [404]** table doesn't exist!
</div>
Table can be seen online
Step6:  <div class="alert alert-block alert-info">
**Response [200]** succesfully deleted table! <br>
**Response [404]** table doesn't exist and cannot be deleted!
</div>
Step7:  <div class="alert alert-block alert-info">
**Response [404]** table does not exists!
</div>
<div class="alert alert-block alert-success">
Now create the table again!
</div>
3. Query table columns
Step8:  4. Insert Data into a table
Now we insert a power plant with name, type and latitude longitude cooridinates.
Step9:  <div class="alert alert-block alert-info">
**201** succesfully inserted data!
</div>
Step10:  <div class="alert alert-block alert-info">
It is row number **[1]**!
</div>
Step11:  If you want to insert multiple lines of data like two power plants in this case, you can insert a list of dictionaries with as many entries as the table has columns. 
<div class="alert alert-block alert-info">
**201** succesfully inserted data!
</div>
Step12:  <div class="alert alert-block alert-info">
It is row number **[2]** and **[3]**!
</div>
5. Insert data into a specific row
Step13:  <div class="alert alert-block alert-info">
**201** succesfully inserted data! <br>
**200** row already taken!
</div>
<div class="alert alert-block alert-success">
Insert some powerplants!
</div>
Step14:  6. Alter data in a table
Step15:  <div class="alert alert-block alert-info">
**200** table exists!
</div>
<ASSISTANT_TASK:>
Python Code:
__copyright__ = "Reiner Lemoine Institut, Zentrum für nachhaltige Energiesysteme Flensburg"
__license__   = "GNU Affero General Public License Version 3 (AGPL-3.0)"
__url__       = "https://github.com/openego/data_processing/blob/master/LICENSE"
__author__    = "wolfbunke, Ludee"
Explanation: <img src="http://193.175.187.164/static/OEP_logo_2_no_text.svg" alt="OpenEnergy Platform" height="100" width="100"  align="left"/>
OpenEnergy Platform
End of explanation
import requests
import pandas as pd
from IPython.core.display import HTML
# 
# 
# oedb
oep_url= 'http://oep.iks.cs.ovgu.de/'
# token
your_token = ''
Explanation: Tutorial - How to work with the OpenEnergy Platform (OEP)
<br>
<div class="alert alert-block alert-danger">
This is an important information!
</div>
<div class="alert alert-block alert-info">
This is an information!
</div>
<div class="alert alert-block alert-success">
This is your task!
</div>
This tutorial gives you an overview of the OpenEnergy Platform and how you can work with the REST-full-HTTP API in Python. <br>
The full API documentaion can be found on ReadtheDocs.io.
Part I
0 Get started - Sign-in and get your own token <br>
0 Setup token <br>
1 Create a table <br>
2 Delete a table <br>
3 Query table columns <br>
4 Insert Data into a table <br>
5 Insert data into a specific row <br>
6 Alter data in a table <br>
Links and further information
How to work with Python and Jupyter Notebooks <br>
OPSD wiki <br>
nbviewer example
Overview of Packages:
http://geopandas.org/install.html#installing-geopandas  <br>
http://docs.python-requests.org/en/master/
Part I
0. Get started - Sign-in and get your own token
The registration has to be done in the Openmod Wiki. <br>
Login to the OpenEnergy Platform.
1.  Click on the login button and sign in
<img src="images/login.png"  alt="OpenEnergy Platform login" height="100" width="100" align="left"/>  <br><br>
2.  Copy your token
<img src="images/token.png"  alt="OpenEnergy Platform Token" height="400" width="500" align="left" /> 
0. Setup token
<br>
<div class="alert alert-block alert-danger">
Do not push your token to GitHub!
</div>
End of explanation
data = {"query": 
        {"name": "Windpark, Am Speller Sand", 
         "type":  "wind_onshore",
         "capacity": 20000,
         "lat":   52.40731,
         "lon":    7.46118
        }}
Explanation: 0.1 About the Database and used Packages
Data are stored and ordered by topic under the "schema" tab:
https://oep.iks.cs.ovgu.de/dataedit/schemas  </div> 
The data tables can be accessed by calling them via http request. </div> 
The "request" package will handle the HTTP communication with the OEP database. It sends requests that insert (put, post, delete) or read (get) data in/from the databank. For either request the URL of a requested table has to be included. 
For all "put", "post" and "delete" requests one has to include the authentification token as a header, like in the "delete table " example.</div> 
Example:
python
requests.delete(oep_url+'/api/v0/schema/'+schema+'/tables/'+table, headers=
                {'Authorization': 'Token %s'%your_token} )
About the table structure:  <br>
The tables are organized in rows and columns that can be adressed via: <br>
```python
requests.post(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/')
and
requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/columns')
```
In the following tutorial the schema will be <div>
'model_draft'<div>
and the table <div>
'example_api_table_test'. <div>
Inserted data must have the structure of a dictionary / json with a key for every column of the table and the respective value like in: 
Random example from OpenStreetMap with freely chosen capacity.
End of explanation
# create table
schema = 'model_draft'
table = 'example_api_table_test'
data = { "query": 
        { "columns": [{ "name":"id", "data_type": "bigserial", "is_nullable": "NO" },
                      { "name":"name", "data_type": "varchar", "character_maximum_length": "50" },
                      { "name":"type", "data_type": "varchar", "character_maximum_length": "20" },
                      { "name":"capacity", "data_type": "decimal" },
                      { "name":"lat", "data_type": "numeric" },
                      { "name":"lon", "data_type": "numeric" } ],
         "constraints": [ { "constraint_type": "PRIMARY KEY", "constraint_parameter": "id" } ] 
        } }
requests.put(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/',
             json=data, headers={'Authorization': 'Token %s'%your_token} )
Explanation: 1. Create a table / Table Architecure
You installed all Python packages? Let's create our first database table:
<div class="alert alert-block alert-info">
The API is enabled for the following schmemas only: **'model_draft'** & **'sandbox'**
</div>
<div class="alert alert-block alert-info">
A table must have a column **'id'** of type **'bigserial'**!
</div>
<div class="alert alert-block alert-success">
Change the name of the table!
</div>
End of explanation
# check if exists
schema = 'model_draft'
table = 'example_api_table_test'
requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table)
Explanation: <div class="alert alert-block alert-info">
**Response [201]** succesfully created table! <br>
**Response [500]** table already exists!
</div>
End of explanation
# Delete your table
schema = 'model_draft'
table = 'example_api_table_test'
requests.delete(oep_url+'/api/v0/schema/'+schema+'/tables/'+table, headers={'Authorization': 'Token %s'%your_token} )
Explanation: <div class="alert alert-block alert-info">
**Response [200]** table exists! <br>
**Response [404]** table doesn't exist!
</div>
Table can be seen online:
http://oep.iks.cs.ovgu.de/dataedit/view/model_draft/example_api_table_test
2. Delete a table
End of explanation
# check if exists
schema = 'model_draft'
table = 'example_api_table_test'
requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table)
Explanation: <div class="alert alert-block alert-info">
**Response [200]** succesfully deleted table! <br>
**Response [404]** table doesn't exist and cannot be deleted!
</div>
End of explanation
# table columns
schema = 'model_draft'
table = 'example_api_table_test'
result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/columns')
json_result = result.json()
json_result['capacity']
# all:
#json_result
Explanation: <div class="alert alert-block alert-info">
**Response [404]** table does not exists!
</div>
<div class="alert alert-block alert-success">
Now create the table again!
</div>
3. Query table columns
End of explanation
# insert data
schema = 'model_draft'
table = 'example_api_table_test'
data = {"query": 
        {"name": "Windpark, Am Speller Sand", 
         "type": "wind_onshore",
         "capacity": 20000,
         "lat":   52.40731,
         "lon":    7.46118
        }}
result = requests.post(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/new', 
                       json=data, headers={'Authorization': 'Token %s'%your_token} )
result.status_code
Explanation: 4. Insert Data into a table
Now we insert a power plant with name, type and latitude longitude cooridinates.
End of explanation
# show the id of the new row
json_result = result.json()
json_result['data']
Explanation: <div class="alert alert-block alert-info">
**201** succesfully inserted data!
</div>
End of explanation
# insert data
schema = 'model_draft'
table = 'example_api_table_test'
data = {"query": [{"name": "Anlage 2", 
                   "type": "photovoltaics",
                   "capacity": 10,
                   "lat":   51.804783,
                   "lon":    11.686346},
                  
                 {"name": "Anlage 3", 
                  "type": "photovoltaic", 
                   "capacity": 5.5,
                   "lat":   51.804783,
                   "lon":    11.6341573
                 }]}
result = requests.post(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/new', 
                       json=data, headers={'Authorization': 'Token %s'%your_token} )
result.status_code
Explanation: <div class="alert alert-block alert-info">
It is row number **[1]**!
</div>
End of explanation
# show the id of the new rows
json_result = result.json()
json_result['data']
Explanation: If you want to insert multiple lines of data like two power plants in this case, you can insert a list of dictionaries with as many entries as the table has columns. 
<div class="alert alert-block alert-info">
**201** succesfully inserted data!
</div>
End of explanation
# insert data to row 11
schema = 'model_draft'
table = 'example_api_table_test'
rownumber = '11'
data = {"query": 
        {"name": "Anlage 11", 
                  "type": "photovoltaic", 
                   "capacity": 5.5,
                   "lat":   51.804783,
                   "lon":    10.41573
                 }}
result = requests.put(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/'+rownumber, 
                       json=data, headers={'Authorization': 'Token %s'%your_token} )
result.status_code
Explanation: <div class="alert alert-block alert-info">
It is row number **[2]** and **[3]**!
</div>
5. Insert data into a specific row
End of explanation
# insert some data
Explanation: <div class="alert alert-block alert-info">
**201** succesfully inserted data! <br>
**200** row already taken!
</div>
<div class="alert alert-block alert-success">
Insert some powerplants!
</div>
End of explanation
# alter data
schema = 'model_draft'
table = 'example_api_table_test'
result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/') # Load the names via GET
result.status_code
Explanation: 6. Alter data in a table
End of explanation
row = "1"
data = {"query": {"capacity": "2", "type": "pv"}}
result = requests.post(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/{id}'.format(id=row), json=data, headers={'Authorization': 'Token %s'%your_token})
result.status_code
Explanation: <div class="alert alert-block alert-info">
**200** table exists!
</div>
End of explanation
<END_TASK>