├── README.md ├── crypto_proj ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── settings.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── wsgi.cpython-38.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── db.sqlite3 ├── img ├── coingecko.png └── main.png ├── manage.py ├── positions ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── admin.cpython-38.pyc │ ├── models.cpython-38.pyc │ └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-38.pyc │ │ └── __init__.cpython-38.pyc ├── models.py ├── templates │ └── positions │ │ └── main.html ├── tests.py └── views.py └── templates └── base.html /README.md: -------------------------------------------------------------------------------- 1 | # :zap: Python Django Crypto 2 | 3 | * Python-Django app to fetch and display crypto currency prices from the [Coingecko cryptocurrency API](https://www.coingecko.com/en/api) 4 | * Code from a tutorial by [Pyplane](https://www.youtube.com/channel/UCQtHyVB4O4Nwy1ff5qQnyRw) - see [:clap: Inspiration](#clap-inspiration) below 5 | * **Note:** to open web links in a new window use: _ctrl+click on link_ 6 | 7 | ![GitHub repo size](https://img.shields.io/github/repo-size/AndrewJBateman/python-django-crypto?style=plastic) 8 | ![GitHub pull requests](https://img.shields.io/github/issues-pr/AndrewJBateman/python-django-crypto?style=plastic) 9 | ![GitHub Repo stars](https://img.shields.io/github/stars/AndrewJBateman/python-django-crypto?style=plastic) 10 | ![GitHub last commit](https://img.shields.io/github/last-commit/AndrewJBateman/python-django-crypto?style=plastic) 11 | 12 | 13 | ## :page_facing_up: Table of contents 14 | 15 | * [:zap: Python Django Crypto](#zap-python-django-crypto) 16 | * [:page_facing_up: Table of contents](#page_facing_up-table-of-contents) 17 | * [:books: General info](#books-general-info) 18 | * [:camera: Screenshots](#camera-screenshots) 19 | * [:signal_strength: Technologies](#signal_strength-technologies) 20 | * [:floppy_disk: Setup](#floppy_disk-setup) 21 | * [:computer: Code Examples](#computer-code-examples) 22 | * [:cool: Features](#cool-features) 23 | * [:clipboard: Status & To-do list](#clipboard-status--to-do-list) 24 | * [:clap: Inspiration](#clap-inspiration) 25 | * [:envelope: Contact](#envelope-contact) 26 | 27 | ## :books: General info 28 | 29 | * [Coingecko cryptocurrency API](https://www.coingecko.com/en/api) supplied crypto currency information in JSON format. It is free and does not require an API key 30 | * [Bootstrap starter template](https://getbootstrap.com/docs/4.3/getting-started/introduction/) used in `templates/base.html` 31 | 32 | ## :camera: Screenshots 33 | 34 | ![screen print](./img/main.png) 35 | ![screen print](./img/coingecko.png) 36 | 37 | ## :signal_strength: Technologies 38 | 39 | * [Python v3](https://www.python.org/) programming language 40 | * [Django v3](https://www.djangoproject.com/) server-side web framework 41 | * [Coingecko cryptocurrency API](https://www.coingecko.com/en/api) 42 | * [Bootstrap v4](https://getbootstrap.com/docs/4.5/getting-started/introduction/) framework 43 | * [requests v2](https://pypi.org/project/requests/) Python HTTP library package 44 | * [Celery v5](https://pypi.org/project/celery/) Distributed Task Queue 45 | * [Redis](https://redislabs.com/) key value store 46 | * [Homebrew v2](https://brew.sh/2019/02/02/homebrew-2.0.0/) - not for Windows - replace with Chocolatey? 47 | 48 | ## :floppy_disk: Setup 49 | 50 | * [Install Python](https://docs.python-guide.org/starting/installation/) 51 | * [Install pip](https://docs.python-guide.org/dev/virtualenvs/#installing-pipenv) 52 | * [Install Django](https://docs.djangoproject.com/en/3.1/howto/windows/) by typing `pip install Django` 53 | * Run `django-admin startproject crypto_proj` to create a new project [ref. docs](https://docs.djangoproject.com/en/3.1/intro/tutorial01/) 54 | * Open `crypto_proj` in VS Code 55 | * Run `python manage.py startapp positions` to create Python module 56 | * Add code 57 | * Run `pip freeze` to see list of modules installed. [Ref. Docs](https://pip.pypa.io/en/stable/reference/pip_freeze/) 58 | * Run `python manage.py makemigrations` for changes to models etc. 59 | * Run `python manage.py migrate` to migrate the migration files. 60 | * To add a superuser run `python manage.py createsuperuser --username=joe --email=joe@example.com` [Ref. Docs](https://docs.djangoproject.com/en/3.1/topics/auth/default/) and log into admin panel 61 | * Run `python manage.py runserver` to run server on port 8000. A refresh is needed after any code changes 62 | 63 | ## :computer: Code Examples 64 | 65 | * extract from - tba 66 | 67 | ```python 68 | 69 | ``` 70 | 71 | ## :cool: Features 72 | 73 | * Django inbuilt packages - admin dashboard 74 | 75 | ## :clipboard: Status & To-do list 76 | 77 | * Status: Incomplete: paused at video 3 - 4.05 while I check Homebrew for Windows - video only shows Mac version 78 | * To-do: check if chocolatey package manager can replace Homebrew which is not for Windows 79 | 80 | ## :clap: Inspiration 81 | 82 | * [Pyplane: Youtube: Django real time application | django channels, celery, redis | part 1 - overview](https://www.youtube.com/watch?v=Ib8UwwnPYsE) 83 | * [Pyplane: Youtube: Django real time application | django channels, celery, redis | part 2](https://www.youtube.com/watch?v=YQRg5Mrg1oY) 84 | * [Pyplane: Youtube: Django real time application | django celery in practice | part 3](https://www.youtube.com/watch?v=DhscKT1t8Vs) 85 | * [Pyplane: Youtube: Django real time application | django celery in practice | part 4](https://www.youtube.com/watch?v=wfVwApNPcHs) 86 | 87 | ## :file_folder: License 88 | 89 | * N/A 90 | 91 | ## :envelope: Contact 92 | 93 | * Repo created by [ABateman](https://github.com/AndrewJBateman), email: gomezbateman@yahoo.com 94 | -------------------------------------------------------------------------------- /crypto_proj/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/crypto_proj/__init__.py -------------------------------------------------------------------------------- /crypto_proj/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/crypto_proj/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /crypto_proj/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/crypto_proj/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /crypto_proj/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/crypto_proj/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /crypto_proj/__pycache__/wsgi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/crypto_proj/__pycache__/wsgi.cpython-38.pyc -------------------------------------------------------------------------------- /crypto_proj/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for crypto_proj project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crypto_proj.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /crypto_proj/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for crypto_proj project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 't0$k(qfc0_$3r_82%)2ijlof_8$$7ng65%^6k0nu$c(e)9ha$k' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 41 | 'positions', 42 | ] 43 | 44 | MIDDLEWARE = [ 45 | 'django.middleware.security.SecurityMiddleware', 46 | 'django.contrib.sessions.middleware.SessionMiddleware', 47 | 'django.middleware.common.CommonMiddleware', 48 | 'django.middleware.csrf.CsrfViewMiddleware', 49 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 50 | 'django.contrib.messages.middleware.MessageMiddleware', 51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 52 | ] 53 | 54 | ROOT_URLCONF = 'crypto_proj.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [BASE_DIR / 'templates'], 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'context_processors': [ 63 | 'django.template.context_processors.debug', 64 | 'django.template.context_processors.request', 65 | 'django.contrib.auth.context_processors.auth', 66 | 'django.contrib.messages.context_processors.messages', 67 | ], 68 | }, 69 | }, 70 | ] 71 | 72 | WSGI_APPLICATION = 'crypto_proj.wsgi.application' 73 | 74 | 75 | # Database 76 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 77 | 78 | DATABASES = { 79 | 'default': { 80 | 'ENGINE': 'django.db.backends.sqlite3', 81 | 'NAME': BASE_DIR / 'db.sqlite3', 82 | } 83 | } 84 | 85 | 86 | # Password validation 87 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 88 | 89 | AUTH_PASSWORD_VALIDATORS = [ 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 101 | }, 102 | ] 103 | 104 | 105 | # Internationalization 106 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 107 | 108 | LANGUAGE_CODE = 'en-us' 109 | 110 | TIME_ZONE = 'UTC' 111 | 112 | USE_I18N = True 113 | 114 | USE_L10N = True 115 | 116 | USE_TZ = True 117 | 118 | 119 | # Static files (CSS, JavaScript, Images) 120 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 121 | 122 | STATIC_URL = '/static/' 123 | -------------------------------------------------------------------------------- /crypto_proj/urls.py: -------------------------------------------------------------------------------- 1 | """crypto_proj URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | from positions.views import home_view 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('', home_view, name='home'), 23 | ] 24 | -------------------------------------------------------------------------------- /crypto_proj/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for crypto_proj project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crypto_proj.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/db.sqlite3 -------------------------------------------------------------------------------- /img/coingecko.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/img/coingecko.png -------------------------------------------------------------------------------- /img/main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/img/main.png -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crypto_proj.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /positions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/positions/__init__.py -------------------------------------------------------------------------------- /positions/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/positions/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /positions/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/positions/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /positions/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/positions/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /positions/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/positions/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /positions/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Test, Position 3 | 4 | # Register your models here. 5 | 6 | admin.site.register(Test) 7 | admin.site.register(Position) -------------------------------------------------------------------------------- /positions/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class PositionsConfig(AppConfig): 5 | name = 'positions' 6 | -------------------------------------------------------------------------------- /positions/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.2 on 2020-11-01 15:53 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Position', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=200)), 19 | ('image', models.URLField()), 20 | ('price', models.CharField(max_length=200)), 21 | ('rank', models.CharField(max_length=10)), 22 | ('market_cap', models.CharField(max_length=10)), 23 | ], 24 | ), 25 | migrations.CreateModel( 26 | name='Test', 27 | fields=[ 28 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 29 | ('name', models.CharField(max_length=200)), 30 | ], 31 | ), 32 | ] 33 | -------------------------------------------------------------------------------- /positions/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/positions/migrations/__init__.py -------------------------------------------------------------------------------- /positions/migrations/__pycache__/0001_initial.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/positions/migrations/__pycache__/0001_initial.cpython-38.pyc -------------------------------------------------------------------------------- /positions/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewJBateman/python-django-crypto/c2ff3c50970dbf86dfaea1d17f7d3e7769956e00/positions/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /positions/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | 5 | class Test(models.Model): 6 | name = models.CharField(max_length=200) 7 | 8 | def __str__(self): 9 | return str(self.id); 10 | 11 | class Position(models.Model): 12 | name = models.CharField(max_length=200) 13 | image = models.URLField() 14 | price = models.CharField(max_length=200) 15 | rank = models.CharField(max_length=10) 16 | market_cap = models.CharField(max_length=200) 17 | 18 | def __str__(self): 19 | return str(self.name) -------------------------------------------------------------------------------- /positions/templates/positions/main.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} 2 | 3 | {% block title %} 4 | main page 5 | {% endblock title %} 6 | 7 | {% block content %} 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | {% if data %} 20 | {% for obj in data %} 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {% endfor %} 29 | {% else %} 30 |

No data

31 | {% endif %} 32 | 33 |
LogoNameRankMarket capPrice
{{obj.name}}{{obj.market_cap_rank}}{{obj.market_cap}}{{obj.current_price}}
34 | {% endblock content %} 35 | 36 | {% block scripts %} 37 | {% endblock scripts %} 38 | -------------------------------------------------------------------------------- /positions/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /positions/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | import requests 3 | from django.http import HttpResponse 4 | 5 | # Create your views here. 6 | 7 | def home_view(request): 8 | url = 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=USD&order=market_cap_desc&per_page=100&page=1&sparkline=false' 9 | data = requests.get(url).json() 10 | 11 | # return HttpResponse(data) 12 | 13 | context = {'data': data} 14 | 15 | return render(request, 'positions/main.html', context) -------------------------------------------------------------------------------- /templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Crypto App | {% block title %}{% endblock title %} 12 | 13 | 14 |
15 | {% block content %} 16 | {% endblock content %} 17 |
18 | 19 | {% block scripts %} 20 | {% endblock scripts %} 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | --------------------------------------------------------------------------------