Hello to everyone,
I want help about a task programming.
I am newbie in Python and from a Company send me a task to solve it.
So I am begginer in Python language and I have learned the basic and work from live server and view in browser.
Application Programming Task
The task is to implement an API that will have retrieve, store and expose currency exchange rates. All endpoints should use a database of your choice as a persistence layer. The following endpoints are needed: - POST - /register (No Auth needed) This endpoint should accept username, password, confirmPassword in JSON format. After validating the input it should create and persist a user in the DB. - POST - /login (No Auth needed) This endpoint should accept username, password in JSON format. After validating the input and checking that user exists and password is correct should return a Json Web Token (JWT) that should
be used to communicate with the other 2 endpoints of the API. - POST - /seed (Needs Authentication) This endpoint should use a free currency API of your choice. Keep in mind that you will need to potentially register with this API to use it and also respect potential request rate limits. When called it should retrieve the exchange rates for all currencies with EUR, USD, CHF andGBP as base currency respectively. e.g. {base: EUR, currencies: [{ EUR: 1, USD: 0.86, CAD: 1.23, SGD: 2.7 ⌠}} // Base EUR {base: USD, currencies: [{ EUR: 1.23, USD: 1, CAD: 0.67, SGD: 8.2 ⌠}} // Base USD ⌠The exchange rates should then be persisted in the database using a schema that makes
sense. - GET - /rates/{base} (Needs Authentication) This endpoint should return all exchange rate from the database in both JSON and XML format. It should support pagination and sorting alphabetically or by exchange rate. - GET - /rates/{base}/{target} (Needs Authentication)
Should return the particular exchange rate. - POST - /rates/{base}/{target} (Needs Authentication) Should create / update the particular exchange rate. In order to be able to discover, test and understand the API make sure it utilizes the OpenAPISpecification (Swagger) which will automatically create a UI interface that will serve as API documentation and testing bed.
Îâm not sure if i started right and I am trying many hours but I would like your help.
Thanks in advance
Below is the code:
print âContent-type:text/htmlâ
print ââ
import requests
import getpass
import json
import argparse
from datetime import date
import time
def callAPI(sourcelist, sourcecurrency, destcurrency):
jsonlist = []
APIKEY=getpass.getpass(prompt="ccc0b100-8a55-11ec-8276-b71d1ddd6a9b (hidden)")
URLBASE='https://freecurrencyapi.net/dashboard'
for date in sourcelist:
url=f'{URLBASE}?access_key={APIKEY}&date={date}¤cies={sourcecurrency},{destcurrency}&format=1c'
convert=requests.get(url)
jsonlist.append(convert.json())
time.sleep(1)
return(jsonlist)
print("Exchange Rates via 'https://freecurrencyapi.net/â")