Skip to content

Commit

Permalink
commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiq-code committed Feb 13, 2024
0 parents commit 3ff5674
Show file tree
Hide file tree
Showing 40 changed files with 502 additions and 0 deletions.
Binary file added db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'weatherproject.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
Binary file added static/Untitled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
168 changes: 168 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@

:root {
--white: #ffffff;
--off-white: #e5e5e5;
--transp-white-1: rgba(255, 255, 255, 0.25);
--transp-white-2: rgba(255, 255, 255, 0.18);
--blue-1: #62b8f5;
--blue-2: #4475ef;
--shadow: rgba(3, 46, 87, 0.2);
}
/* body{
background: linear-gradient(270deg, var(--blue-1), var(--blue-2));
} */
*{
margin:0;
padding:0;
box-sizing:border-box;
font-family: "Poppins", sans-serif;
}
h1{
text-align: center;
color: rgb(5,41,51);
margin-bottom: 15px;
}
h2{
font-size: 2rem;
}
form{
display:grid;
grid-template-columns:72% 25%;
grid-gap:3%;
}
.container{
width: 50%;;
/* background-color: #77ACF1; */
background: var(--transp-white-2);
backdrop-filter: blur(10px);
margin: 5rem auto;
padding: 2rem;
border: 2px solid var(--transp-white-2);
border-radius: 10px;
color:rgb(5,41,51);
height: 600px;
}
input, .btn ::placeholder{
background-color: transparent;

/* color: var(--off-white);
border-bottom: 2px solid var(--transp-white-1); */
padding: .5rem;
border-radius: 10px;
outline: none;
border: 1px solid white;
}
.btn{
padding: .5rem 1rem;
/* background-color:#F0EBCC ;
color:#04009A ; */
border:2px solid #04009A ;
cursor:pointer;
transition:.3s;
color: var(--blue-2);
background-color: transparent;
border-radius: 0.3em;
}
.btn:hover{
transform: translateY(-3px);
background-color:rgb(5,41,51);
color:#fff ;
}
.weather{
margin-top:3rem;
display:flex;
justify-content: space-between;
align-items:center;
height:200px;

}
.left{
width:100%;
/* background-color:#343A40 ; */
padding:.3rem;
padding-bottom: 0;
border-radius:10px 0 0 10px;
height:220px;
line-height:3;
text-transform: uppercase;
background: var(--transp-white-2);
backdrop-filter: blur(10px);

}
.temp{
text-align: center;
margin-top: 15px;
}
.city{
margin-top: -22px;
text-align: center;
}
.right{
border-radius:10px ;
text-align:center;
height:220px;
width:100%;
border-radius:0 10px 10px 0;
/* margin-left:.5rem; */
line-height:2.5;
background: var(--transp-white-2);
backdrop-filter: blur(10px);

}
.icon{

/* background:#d8c6c6; */
height:85px;
padding: .5rem;
border-radius:0 10px 0 0;
color:#04009A;
/* filter: drop-shadow(0 1.8em 3.7em var(--shadow)); */
}
.condition{
height:135px;
/* background:#292929 ; */
/* padding: .5rem; */
border-radius:0 0 10px;
color:rgb(5,41,51);
font-size: 20px;
}
@media only screen and (max-width: 1000px) {
.container{
width:80%;
}
}
@media only screen and (max-width: 700px) {
.weather {
flex-direction:column;
height:auto;
}
.container{
text-align:center;
width:90%;
height:90%;
}
.right{
margin-top:.5rem;
margin-left:0;
}
form{
grid-template-columns:100%;

}


}

/*
@import url('https://fonts.googleapis.com/css?family=Source+Code+Pro:200'); */

body {
background-image: url('https://images.pexels.com/photos/3008509/pexels-photo-3008509.jpeg?auto=compress&cs=tinysrgb&w=1600');
background-size:cover;
background-repeat: no-repeat;
margin: 0;
width: 1920px;

}

Empty file added weatherapp/__init__.py
Empty file.
Binary file added weatherapp/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/views.cpython-311.pyc
Binary file not shown.
Binary file added weatherapp/__pycache__/views.cpython-39.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions weatherapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions weatherapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class WeatherappConfig(AppConfig):
name = 'weatherapp'
Empty file.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions weatherapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
56 changes: 56 additions & 0 deletions weatherapp/templates/weatherapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% load static %}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Weather App</title>
<link rel="stylesheet" href="{% static 'style.css' %}">
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;600&display=swap"
rel="stylesheet"
/>
</head>

<body {% if exception_occurred %}
style="background-image: url('https://images.pexels.com/photos/3008509/pexels-photo-3008509.jpeg?auto=compress&cs=tinysrgb&w=1600');"
{% else %}
style="background-image: url('{{ image_url }}');"
{% endif %}>
<div class="container">
<h1 class="heading">Weather App</h1>

<form method="POST">
{% csrf_token %}
<input type="text" name="city" placeholder="Enter City">
<button type="submit" class="btn">Search</button>
</form>
<div class="weather">
<div class="left">
<h2 class="temp">{{ temp }}&#176; C</h2>
<h2 class="city">{{ city }}</h2>
</div>
<div class="right">
<div class="icon">
<p><img src="http://openweathermap.org/img/w/{{ icon }}.png" width="120px"></p>
</div>
<div class="condition">
<p>{{ description }}</p>
<p>{{ day }}</p>
</div>
</div>
</div>
</div>


{% if exception_occurred %}
<script>
window.onload = function() {
alert("City information is not available to Weather API");
}
</script>
{% endif %}

</body>
</html>
3 changes: 3 additions & 0 deletions weatherapp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
5 changes: 5 additions & 0 deletions weatherapp/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.home),
]
58 changes: 58 additions & 0 deletions weatherapp/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from django.shortcuts import render
from django.contrib import messages
import requests
import datetime


def home(request):

if 'city' in request.POST:
city = request.POST['city']
else:
city = 'indore'

url = f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid=ad4bbb96fa3d51295147d143d029e1ba'
PARAMS = {'units':'metric'}

API_KEY = 'AIzaSyA_w0pPujrG3Eii303pqnCeBhIzYBcdvlU'
SEARCH_ENGINE_ID = '078378d643c1e45f7'



query = city + " 1920x1080"
page = 1
start = (page - 1) * 10 + 1
searchType = 'image'
city_url = f"https://www.googleapis.com/customsearch/v1?key={API_KEY}&cx={SEARCH_ENGINE_ID}&q={query}&start={start}&searchType={searchType}&imgSize=xlarge"

data = requests.get(city_url).json()
count = 1
search_items = data.get("items")
image_url = search_items[1]['link']


try:

data = requests.get(url,params=PARAMS).json()
description = data['weather'][0]['description']
icon = data['weather'][0]['icon']
temp = data['main']['temp']
day = datetime.date.today()

return render(request,'weatherapp/index.html' , {'description':description , 'icon':icon ,'temp':temp , 'day':day , 'city':city , 'exception_occurred':False ,'image_url':image_url})

except KeyError:
exception_occurred = True
messages.error(request,'Entered data is not available to API')
# city = 'indore'
# data = requests.get(url,params=PARAMS).json()

# description = data['weather'][0]['description']
# icon = data['weather'][0]['icon']
# temp = data['main']['temp']
day = datetime.date.today()

return render(request,'weatherapp/index.html' ,{'description':'clear sky', 'icon':'01d' ,'temp':25 , 'day':day , 'city':'indore' , 'exception_occurred':exception_occurred } )



Empty file added weatherproject/__init__.py
Empty file.
Binary file added weatherproject/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added weatherproject/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added weatherproject/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file added weatherproject/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added weatherproject/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
Binary file added weatherproject/__pycache__/wsgi.cpython-39.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions weatherproject/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for weatherproject project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'weatherproject.settings')

application = get_asgi_application()
Loading

0 comments on commit 3ff5674

Please sign in to comment.