├── Pipfile ├── Pipfile.lock └── the_weather ├── db.sqlite3 ├── manage.py ├── the_weather ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-35.pyc │ ├── settings.cpython-35.pyc │ ├── urls.cpython-35.pyc │ └── wsgi.cpython-35.pyc ├── settings.py ├── urls.py └── wsgi.py └── weather ├── __init__.py ├── __pycache__ ├── __init__.cpython-35.pyc ├── admin.cpython-35.pyc ├── forms.cpython-35.pyc ├── models.cpython-35.pyc ├── urls.cpython-35.pyc └── views.cpython-35.pyc ├── admin.py ├── apps.py ├── forms.py ├── migrations ├── 0001_initial.py ├── __init__.py └── __pycache__ │ ├── 0001_initial.cpython-35.pyc │ └── __init__.cpython-35.pyc ├── models.py ├── templates └── weather │ └── index.html ├── tests.py ├── urls.py └── views.py /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | 3 | name = "pypi" 4 | url = "https://pypi.python.org/simple" 5 | verify_ssl = true 6 | 7 | 8 | [packages] 9 | 10 | django = "*" 11 | requests = "*" 12 | 13 | 14 | [dev-packages] 15 | 16 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "970dad4c8055aa4221d5236776d9cd66a5bcc8bb8b06fa5ed6a12a4c9d79f4eb" 5 | }, 6 | "host-environment-markers": { 7 | "implementation_name": "cpython", 8 | "implementation_version": "3.5.2", 9 | "os_name": "posix", 10 | "platform_machine": "x86_64", 11 | "platform_python_implementation": "CPython", 12 | "platform_release": "4.4.0-17133-Microsoft", 13 | "platform_system": "Linux", 14 | "platform_version": "#1-Microsoft Fri Mar 23 13:12:00 PST 2018", 15 | "python_full_version": "3.5.2", 16 | "python_version": "3.5", 17 | "sys_platform": "linux" 18 | }, 19 | "pipfile-spec": 6, 20 | "requires": {}, 21 | "sources": [ 22 | { 23 | "name": "pypi", 24 | "url": "https://pypi.python.org/simple", 25 | "verify_ssl": true 26 | } 27 | ] 28 | }, 29 | "default": { 30 | "certifi": { 31 | "hashes": [ 32 | "sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296", 33 | "sha256:edbc3f203427eef571f79a7692bb160a2b0f7ccaa31953e99bd17e307cf63f7d" 34 | ], 35 | "version": "==2018.1.18" 36 | }, 37 | "chardet": { 38 | "hashes": [ 39 | "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691", 40 | "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae" 41 | ], 42 | "version": "==3.0.4" 43 | }, 44 | "django": { 45 | "hashes": [ 46 | "sha256:2d8b9eed8815f172a8e898678ae4289a5e9176bc08295676eff4228dd638ea61", 47 | "sha256:d81a1652963c81488e709729a80b510394050e312f386037f26b54912a3a10d0" 48 | ], 49 | "version": "==2.0.4" 50 | }, 51 | "idna": { 52 | "hashes": [ 53 | "sha256:8c7309c718f94b3a625cb648ace320157ad16ff131ae0af362c9f21b80ef6ec4", 54 | "sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f" 55 | ], 56 | "version": "==2.6" 57 | }, 58 | "pytz": { 59 | "hashes": [ 60 | "sha256:65ae0c8101309c45772196b21b74c46b2e5d11b6275c45d251b150d5da334555", 61 | "sha256:c06425302f2cf668f1bba7a0a03f3c1d34d4ebeef2c72003da308b3947c7f749" 62 | ], 63 | "version": "==2018.4" 64 | }, 65 | "requests": { 66 | "hashes": [ 67 | "sha256:6a1b267aa90cac58ac3a765d067950e7dbbf75b1da07e895d1f594193a40a38b", 68 | "sha256:9c443e7324ba5b85070c4a818ade28bfabedf16ea10206da1132edaa6dda237e" 69 | ], 70 | "version": "==2.18.4" 71 | }, 72 | "urllib3": { 73 | "hashes": [ 74 | "sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b", 75 | "sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f" 76 | ], 77 | "version": "==1.22" 78 | } 79 | }, 80 | "develop": {} 81 | } 82 | -------------------------------------------------------------------------------- /the_weather/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/db.sqlite3 -------------------------------------------------------------------------------- /the_weather/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "the_weather.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /the_weather/the_weather/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/the_weather/__init__.py -------------------------------------------------------------------------------- /the_weather/the_weather/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/the_weather/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/the_weather/__pycache__/settings.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/the_weather/__pycache__/settings.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/the_weather/__pycache__/urls.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/the_weather/__pycache__/urls.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/the_weather/__pycache__/wsgi.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/the_weather/__pycache__/wsgi.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/the_weather/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for the_weather project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.0.4. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '+cze%0+*oz67ke)+)&6zncb_^rkr0=o!cgqlx$br3(@#-u+2^1' 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 | 'weather', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'the_weather.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'the_weather.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/2.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/2.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/2.0/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | -------------------------------------------------------------------------------- /the_weather/the_weather/urls.py: -------------------------------------------------------------------------------- 1 | """the_weather URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/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, include 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | path('', include('weather.urls')), 22 | ] 23 | -------------------------------------------------------------------------------- /the_weather/the_weather/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for the_weather 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/2.0/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", "the_weather.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /the_weather/weather/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/__init__.py -------------------------------------------------------------------------------- /the_weather/weather/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/weather/__pycache__/admin.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/__pycache__/admin.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/weather/__pycache__/forms.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/__pycache__/forms.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/weather/__pycache__/models.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/__pycache__/models.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/weather/__pycache__/urls.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/__pycache__/urls.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/weather/__pycache__/views.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/__pycache__/views.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/weather/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import City 3 | 4 | admin.site.register(City) -------------------------------------------------------------------------------- /the_weather/weather/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class WeatherConfig(AppConfig): 5 | name = 'weather' 6 | -------------------------------------------------------------------------------- /the_weather/weather/forms.py: -------------------------------------------------------------------------------- 1 | from django.forms import ModelForm, TextInput 2 | from .models import City 3 | 4 | class CityForm(ModelForm): 5 | class Meta: 6 | model = City 7 | fields = ['name'] 8 | widgets = { 9 | 'name': TextInput(attrs={'class' : 'input', 'placeholder' : 'City Name'}), 10 | } #updates the input class to have the correct Bulma class and placeholder -------------------------------------------------------------------------------- /the_weather/weather/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.4 on 2018-04-12 04:23 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='City', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=25)), 19 | ], 20 | options={ 21 | 'verbose_name_plural': 'cities', 22 | }, 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /the_weather/weather/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/migrations/__init__.py -------------------------------------------------------------------------------- /the_weather/weather/migrations/__pycache__/0001_initial.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/migrations/__pycache__/0001_initial.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/weather/migrations/__pycache__/__init__.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PrettyPrinted/weather_app_django_scotch/96b1cda14d8fb906afb961d379cc24177df338be/the_weather/weather/migrations/__pycache__/__init__.cpython-35.pyc -------------------------------------------------------------------------------- /the_weather/weather/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class City(models.Model): 4 | name = models.CharField(max_length=25) 5 | 6 | def __str__(self): #show the actual city name on the dashboard 7 | return self.name 8 | 9 | class Meta: #show the plural of city as cities instead of citys 10 | verbose_name_plural = 'cities' -------------------------------------------------------------------------------- /the_weather/weather/templates/weather/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | What's the weather like? 8 | 9 | 10 | 11 |
12 |
13 |
14 |

15 | What's the weather like? 16 |

17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | {% csrf_token %} 26 |
27 |
28 | {{ form.name }} 29 |
30 |
31 | 34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | {% for weather in weather_data %} 46 |
47 |
48 |
49 |
50 | Image 51 |
52 |
53 |
54 |
55 |

56 | {{ weather.city }} 57 |
58 | {{ weather.temperature }}° F 59 |
{{ weather.description }} 60 |

61 |
62 |
63 |
64 |
65 | {% endfor %} 66 |
67 |
68 |
69 |
70 | 72 | 73 | -------------------------------------------------------------------------------- /the_weather/weather/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /the_weather/weather/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.index), #the path for our index view 6 | ] -------------------------------------------------------------------------------- /the_weather/weather/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | import requests 3 | from .models import City 4 | from .forms import CityForm 5 | 6 | def index(request): 7 | cities = City.objects.all() #return all the cities in the database 8 | 9 | url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid=271d1234d3f497eed5b1d80a07b3fcd1' 10 | 11 | if request.method == 'POST': # only true if form is submitted 12 | form = CityForm(request.POST) # add actual request data to form for processing 13 | form.save() # will validate and save if validate 14 | 15 | form = CityForm() 16 | 17 | weather_data = [] 18 | 19 | for city in cities: 20 | 21 | city_weather = requests.get(url.format(city)).json() #request the API data and convert the JSON to Python data types 22 | 23 | weather = { 24 | 'city' : city, 25 | 'temperature' : city_weather['main']['temp'], 26 | 'description' : city_weather['weather'][0]['description'], 27 | 'icon' : city_weather['weather'][0]['icon'] 28 | } 29 | 30 | weather_data.append(weather) #add the data for the current city into our list 31 | 32 | context = {'weather_data' : weather_data, 'form' : form} 33 | 34 | return render(request, 'weather/index.html', context) #returns the index.html template 35 | --------------------------------------------------------------------------------