Other API Endpoints
Let’s continue here with more API and a little bit more of functionality. So we have a URL for another endpoint to get more data. You can edit into your “process_data.py” file:
import json def get_data(query_string): import http.client conn = http.client.HTTPSConnection("api.coinmarketcap.com") conn.request("GET","{}".format(query_string")) res = conn.getresponse() data = res.read() return json.loads(data.decode("utf-8")) def process(): data = get_data("/v1/ticker/bitcoin/") return data
Now we can start another method. You can copy and paste it underneath the code below:
def process(): data = get_data("/v1/ticker/?limit=10") return data
Also remember you have to pass it in your “app.py”:
from flask import Flask from flask import render_template app = Flask(__name__) @app.route("/") def index (): return render_template("index.html", data=process_data.process(), process_coin=process_data.process_coin()) if __name__ == "__main__": app.run(debug=True)
And then add the ending somewhere in the “index.html”:
{{process_coins}}
Parsing other Dictionaries
Creating Bootstrap Table
Tables allow you to aggregate a huge amount of data and present it in a clear and orderly way. Bootstrap tables provide additional benefits like responsiveness and the possibility of manipulating the table styles.
<table class="table-hover table_border"> <tr> <th>Name</th> </tr> <td>{% for item in process_coins %}</td> <tr> <td>{{item["name"]}}</td> </tr> {% endfor %} </table>