Skip to content

Commit

Permalink
backend and setting change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghosts6 committed Nov 20, 2024
1 parent fc25d20 commit b7fbaff
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
.vscode
Binary file modified climate/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified climate/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file modified climate/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified climate/__pycache__/views.cpython-310.pyc
Binary file not shown.
Empty file added climate/log.txt
Empty file.
4 changes: 3 additions & 1 deletion climate/settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os
from pathlib import Path
from dotenv import load_dotenv

load_dotenv()
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-xuw!&ymb!t0y%wt36u%jo4w#7z95&*bj8rian^=#-%g$ly*c_0'
SECRET_KEY = os.getenv('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
Expand Down
Binary file modified weather/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified weather/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file modified weather/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file modified weather/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified weather/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified weather/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file modified weather/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
26 changes: 15 additions & 11 deletions weather/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
from geopy.geocoders import Nominatim
from geopy.exc import GeocoderUnavailable
from datetime import datetime
from dotenv import load_dotenv
import json
import pytz
import requests
import os

def get_news(api_key, query, count=5):
news_url = f'https://newsapi.org/v2/everything?q={query}&apiKey={api_key}&pageSize={count}'
load_dotenv()
API_KEY = os.getenv('API_KEY')

def get_news(API_KEY, query, count=5):
news_url = f'https://newsapi.org/v2/everything?q={query}&apiKey={API_KEY}&pageSize={count}'
response = requests.get(news_url)

if response.status_code == 200:
Expand All @@ -37,10 +41,10 @@ def get_news(api_key, query, count=5):


def home(request):
api_key = '0f00a482322f82d0c38ea32028a6eada'
API_KEY = os.getenv('API_KEY')
cities = ['London', 'Toronto', 'Dubai', 'Tehran', 'New York', 'Los Angeles']
weather_news_list = []
paris_url = f'http://api.openweathermap.org/data/2.5/weather?q=Paris&appid={api_key}'
paris_url = f'http://api.openweathermap.org/data/2.5/weather?q=Paris&appid={API_KEY}'
paris_response = requests.get(paris_url)

if paris_response.status_code == 200:
Expand Down Expand Up @@ -76,7 +80,7 @@ def home(request):
latitude = location.latitude
longitude = location.longitude

user_location_url = f'http://api.openweathermap.org/data/2.5/weather?lat={latitude}&lon={longitude}&appid={api_key}'
user_location_url = f'http://api.openweathermap.org/data/2.5/weather?lat={latitude}&lon={longitude}&appid={API_KEY}'
user_location_response = requests.get(user_location_url)

if user_location_response.status_code == 200:
Expand All @@ -103,7 +107,7 @@ def home(request):


for city in cities:
api_url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}'
api_url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}'
response = requests.get(api_url)

print(response.text)
Expand Down Expand Up @@ -138,8 +142,8 @@ def weather(request):

if city_name:

api_key = '0f00a482322f82d0c38ea32028a6eada'
weather_url = f'http://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}'
API_KEY = os.getenv('API_KEY')
weather_url = f'http://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={API_KEY}'
time_url = f'http://worldtimeapi.org/api/timezone/Europe/{city_name}.json'

try:
Expand Down Expand Up @@ -204,11 +208,11 @@ def kelvin_to_celsius(kelvin):

def search_weather(request):
city_name = request.GET.get('city_name', '')
api_key = '0f00a482322f82d0c38ea32028a6eada'
API_KEY = os.getenv('API_KEY')

if city_name and api_key:
if city_name and API_KEY:
try:
api_url = f'https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}'
api_url = f'https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={API_KEY}'
response = requests.get(api_url)
data = response.json()

Expand Down

0 comments on commit b7fbaff

Please sign in to comment.