项目作者: AndrewJBateman

项目描述 :
:clipboard: Displays covid API data using Bootstrap and Bootswatch theme.
高级语言: Python
项目地址: git://github.com/AndrewJBateman/python-django-covid.git
创建时间: 2020-12-20T21:42:04Z
项目社区:https://github.com/AndrewJBateman/python-django-covid

开源协议:

下载


:zap: Python Django Site

  • Python-Django app to display Covid data
  • Code from a tutorial by TopNotch Programmer - see :clap: Inspiration below
  • Note: to open web links in a new window use: ctrl+click on link

GitHub repo size
GitHub pull requests
GitHub Repo stars
GitHub last commit

:page_facing_up: Table of contents

:books: General info

:camera: Screenshots

screen print

:signal_strength: Technologies

:floppy_disk: Setup

  • Install Python
  • Install pip
  • Install Django by typing pip install Django
  • Run django-admin startproject example_proj to create a new project ref. docs
  • Open example_proj in VS Code
  • Run python manage.py startapp new_module to create Python module
  • Add code
  • Run pip freeze to see list of modules installed. Ref. Docs
  • Run python manage.py makemigrations for changes to models etc.
  • Run python manage.py migrate to migrate the migration files.
  • For Admin panel: to add a superuser Run python manage.py createsuperuser --username=joe --email=joe@example.com Ref. Docs
  • Run python manage.py runserver to run server on port 8000 and open /admin console

:computer: Code Examples

  • extract from views.py to get Covid data from API and prepare data required for html template
  1. def home(request):
  2. url = "https://covid-193.p.rapidapi.com/statistics"
  3. querystring = {"country":"France"}
  4. headers = {
  5. 'x-rapidapi-key': "a6f5f5daa9msh415e131fbb7e735p1994d1jsnb2bc491b075e",
  6. 'x-rapidapi-host': "covid-193.p.rapidapi.com"
  7. }
  8. response = requests.request("GET", url, headers=headers, params=querystring).json()
  9. data = response['response']
  10. d = data[0]
  11. print(d)
  12. context = {
  13. 'country': d['country'],
  14. 'all': d['cases']['total'],
  15. 'recovered': d['cases']['recovered'],
  16. 'deaths': d['deaths']['total'],
  17. 'new': d['cases']['new'],
  18. 'critical': d['cases']['critical'],
  19. 'date': d['day']
  20. }
  21. return render(request, 'index.html', context)

:cool: Features

:clipboard: Status & To-do list

  • Status: Working
  • To-do: Add commas to numbers. Move API code to services, add country pull-down selector.

:clap: Inspiration

:file_folder: License

  • N/A

:envelope: Contact