├── .gitgnore
├── WeatherInfo
├── mainApp
│ ├── __init__.py
│ ├── migrations
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-38.pyc
│ │ │ └── 0001_initial.cpython-38.pyc
│ │ └── 0001_initial.py
│ ├── tests.py
│ ├── urls.py
│ ├── admin.py
│ ├── __pycache__
│ │ ├── admin.cpython-38.pyc
│ │ ├── apps.cpython-38.pyc
│ │ ├── forms.cpython-38.pyc
│ │ ├── models.cpython-38.pyc
│ │ ├── urls.cpython-38.pyc
│ │ ├── views.cpython-38.pyc
│ │ └── __init__.cpython-38.pyc
│ ├── apps.py
│ ├── forms.py
│ ├── models.py
│ ├── views.py
│ └── templates
│ │ └── index.html
├── WeatherInfo
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── urls.cpython-38.pyc
│ │ ├── wsgi.cpython-38.pyc
│ │ ├── __init__.cpython-38.pyc
│ │ └── settings.cpython-38.pyc
│ ├── asgi.py
│ ├── wsgi.py
│ ├── urls.py
│ └── settings.py
├── db.sqlite3
└── manage.py
├── README.md
├── Screenshot
└── Screenshot from 2021-09-10 10-16-19.png
├── requirements.txt
└── pyvenv.cfg
/.gitgnore:
--------------------------------------------------------------------------------
1 | bin/
2 | lib/
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Weather-App-Django
2 | Django Weather App.
3 |
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/WeatherInfo/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/db.sqlite3
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/urls.py:
--------------------------------------------------------------------------------
1 |
2 | from django.urls import path
3 | from . import views
4 |
5 | urlpatterns = [
6 | path('', views.index),
7 | ]
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 | from .models import City
3 |
4 | # Register your models here.
5 |
6 | admin.site.register(City)
--------------------------------------------------------------------------------
/Screenshot/Screenshot from 2021-09-10 10-16-19.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/Screenshot/Screenshot from 2021-09-10 10-16-19.png
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/__pycache__/admin.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/__pycache__/admin.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/__pycache__/apps.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/__pycache__/apps.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/__pycache__/forms.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/__pycache__/forms.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/__pycache__/models.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/__pycache__/models.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/__pycache__/urls.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/__pycache__/urls.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/__pycache__/views.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/__pycache__/views.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/__pycache__/urls.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/WeatherInfo/__pycache__/urls.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/__pycache__/wsgi.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/WeatherInfo/__pycache__/wsgi.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/WeatherInfo/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/__pycache__/settings.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/WeatherInfo/__pycache__/settings.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class MainappConfig(AppConfig):
5 | default_auto_field = 'django.db.models.BigAutoField'
6 | name = 'mainApp'
7 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | asgiref==3.4.1
2 | certifi==2021.5.30
3 | charset-normalizer==2.0.4
4 | Django==3.2.7
5 | idna==3.2
6 | pytz==2021.1
7 | requests==2.26.0
8 | sqlparse==0.4.1
9 | urllib3==1.26.6
10 |
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/migrations/__pycache__/__init__.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/migrations/__pycache__/__init__.cpython-38.pyc
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/migrations/__pycache__/0001_initial.cpython-38.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abdullahthewebbee/Weather-App-Django-main/HEAD/WeatherInfo/mainApp/migrations/__pycache__/0001_initial.cpython-38.pyc
--------------------------------------------------------------------------------
/pyvenv.cfg:
--------------------------------------------------------------------------------
1 | home = /usr
2 | implementation = CPython
3 | version_info = 3.8.10.final.0
4 | virtualenv = 20.0.17
5 | include-system-site-packages = false
6 | base-prefix = /usr
7 | base-exec-prefix = /usr
8 | base-executable = /usr/bin/python3
9 |
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/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 | }
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 |
5 | class City(models.Model):
6 | name = models.CharField(max_length=25)
7 |
8 | def __str__(self): #show the actual city name on the dashboard
9 | return self.name
10 |
11 | class Meta:
12 | verbose_name_plural = 'cities'
13 |
14 | # verbose name plural is a human readable name you give to the objects
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for WeatherInfo 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.2/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', 'WeatherInfo.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for WeatherInfo 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.2/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', 'WeatherInfo.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.2.7 on 2021-09-10 04:24
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.BigAutoField(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 |
--------------------------------------------------------------------------------
/WeatherInfo/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', 'WeatherInfo.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 |
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/urls.py:
--------------------------------------------------------------------------------
1 | """WeatherInfo URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/3.2/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('mainApp.urls')),
22 |
23 | ]
24 |
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render
2 | import requests
3 | from .models import City
4 | from .forms import CityForm
5 |
6 | # Create your views here.
7 |
8 | def index(request):
9 | cities = City.objects.all()
10 |
11 | url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid=[Your Api key, just add key and remove the bracket]'
12 |
13 | if request.method == 'POST':
14 | form = CityForm(request.POST)
15 | form.save()
16 |
17 | form = CityForm()
18 |
19 | weather_data = []
20 |
21 | for city in cities:
22 | city_weather = requests.get(url.format(city)).json()
23 |
24 | weather = {
25 | 'city' : city,
26 | 'temperature' : city_weather['main']['temp'],
27 | 'description' : city_weather['weather'][0]['description'],
28 | 'icon' : city_weather['weather'][0]['icon'],
29 | 'humidity': city_weather['main']['humidity'],
30 | 'pressure': city_weather['main']['pressure'],
31 | 'country': city_weather['sys']['country'],
32 | 'sunrise': city_weather['sys']['sunrise'],
33 | 'sunset': city_weather['sys']['sunset'],
34 | 'windspeed': city_weather['wind']['speed']
35 | }
36 |
37 | weather_data.append(weather)
38 |
39 | context = {'weather_data': weather_data, 'form': form}
40 |
41 | return render(request, 'index.html', context)
42 |
43 |
--------------------------------------------------------------------------------
/WeatherInfo/mainApp/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Weather
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | What's the weather like?
16 |
17 |
18 |
19 |
20 |
41 |
42 |
43 |
44 |
45 | {% for weather in weather_data %}
46 |
47 |
48 |
53 |
54 |
55 |
56 | {{ weather.city }}
57 |
58 | {{ weather.temperature }}° F
59 |
Humidity: {{weather.humidity}}
60 |
Pressure: {{weather.pressure}}
61 |
Country: {{weather.country}}
62 |
Sunrise: {{weather.sunrise}}
63 |
Sunset: {{weather.sunset}}
64 |
Wind Speed: {{weather.windspeed}}
65 |
{{ weather.description }}
66 |
67 |
68 |
69 |
70 |
71 | {% endfor %}
72 |
73 |
74 |
75 |
76 |
78 |
79 |
--------------------------------------------------------------------------------
/WeatherInfo/WeatherInfo/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for WeatherInfo project.
3 |
4 | Generated by 'django-admin startproject' using Django 3.2.7.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.2/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/3.2/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.2/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = 'django-insecure-qik3p%=6rf1og(^85p%l1cr(%cf@6j9418w_5ao793$9zdf6+#'
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 | 'mainApp' #add
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 = 'WeatherInfo.urls'
55 |
56 | TEMPLATES = [
57 | {
58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59 | 'DIRS': [],
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 = 'WeatherInfo.wsgi.application'
73 |
74 |
75 | # Database
76 | # https://docs.djangoproject.com/en/3.2/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.2/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.2/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.2/howto/static-files/
121 |
122 | STATIC_URL = '/static/'
123 |
124 | # Default primary key field type
125 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
126 |
127 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
128 |
--------------------------------------------------------------------------------