Writing to Sqlite In this part we are going to learn how to connect Flask to Sqlite Database and we can insert the form data. In this example we going to use the Sqlite Dict Python library. You can use whatever database you want, but in this case we are using Sqlite because use a […]
Flask
Further Processing
Print POST Data In any web app, you’ll have to process incoming request data from users. Flask, like any other web framework, allows you to access the request data easily. Next step is going to be to make use of the value: from flask import Flask from flask import render_template app = Flask(__name__) @app.route(“/”), methods=[‘GET’, […]
Data POST and adding Logic
Adding custom data calculation Now let’s do more data calculation. We open “process_data.py” and edit the file with this script: def calculate_coin(price_usd): return (float(price_usd) > 40 def process(): data = get_data(“/v1/ticker/?limit=10”) all_coins = [] for coin in data: coin [“isover40”] = calculate_coin(coin[“price_usd”]) all_coins.append(coin) return all_coins Creating Bootstrap form and submit button In this part we […]
More API and output
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(): […]
Use of Bootstrap and styling
Starting with Bootstrap Bootstrap is a framework to help you design websites faster and easier. It includes HTML and CSS based design templates for typography, forms, buttons, tables, navigation, modals, etc. In the HTML Code from the last exercises named “index.html” create a new header section and we are going to input the bootstrap CSS <html> […]