Skip to content

Instantly share code, notes, and snippets.

@shilpavijay
Last active February 7, 2018 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shilpavijay/00b2ea2ccff38e1d7ac48bd67872912c to your computer and use it in GitHub Desktop.
Save shilpavijay/00b2ea2ccff38e1d7ac48bd67872912c to your computer and use it in GitHub Desktop.
Frozen flask
to install:
Frozen-Flask
to run:
python <pyfilename> build
import sys
from flask import Flask
from flask import render_template
import pandas as pd
from flask_frozen import Freezer
debug = True
app = Flask(__name__)
app.config.from_object(__name__)
freezer = Freezer(app)
def getData():
try:
dfRawData = pd.read_csv("static/data.csv")
dfRawData.set_index('Country', inplace=True)
df = dfRawData.fillna(0)
df.drop(df.index[0], inplace=True) #drops row no. 1
df.drop(df.index[2:65],inplace=True)
df.drop(df.index[40:],inplace=True)
#drop column by name:
df.drop([col for col in df.columns if ".2" not in col and "Country" not in col], axis=1,inplace=True)
df.drop(df.columns[6:],axis=1,inplace=True)
df.rename(columns=lambda x: x.replace('.2',''), inplace=True)
return df
except Exception as e:
print(e)
return "Error"
# @app.route('/getJson/')
# def getJson(df):
# df.to_json(orient="records")
# return 1
def generateExcel(df):
df.to_csv("static/dataRefined.csv")
@app.route('/')
def main():
df = getData()
generateExcel(df)
return render_template("index.html")
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "build":
freezer.freeze()
else:
app.run(port=8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment