Skip to content

Instantly share code, notes, and snippets.

@realhardik18
Last active July 30, 2022 08:27
Show Gist options
  • Save realhardik18/6d9975e8b21989afadd836c800df8b31 to your computer and use it in GitHub Desktop.
Save realhardik18/6d9975e8b21989afadd836c800df8b31 to your computer and use it in GitHub Desktop.
from flask import Flask
from flask_restful import Resource, Api, reqparse
import pandas
app = Flask(__name__)
api = Api(app)
#download the data set from https://www.kaggle.com/datasets/fernandol/countries-of-the-world
dataset = pandas.read_csv('countries of the world.csv')
def InfoAboutCountry(country):
headers = list(dataset.head(0))
country_data = dataset.loc[dataset['Country'] == country+' '].values[0]
return dict(zip(headers, country_data))
class CountryAPI(Resource):
def get(self):
parser = reqparse.RequestParser()
parser.add_argument('country', type=str)
country = dict(parser.parse_args())['country']
data = InfoAboutCountry(country)
return data
api.add_resource(CountryAPI, '/data', endpoint='data')
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment