From b7fbaff6f3e4d55baedfeeb643f07bafbc6c9500 Mon Sep 17 00:00:00 2001 From: Ghosts6 Date: Wed, 20 Nov 2024 16:24:42 +0000 Subject: [PATCH] backend and setting change --- .gitignore | 2 ++ climate/__pycache__/__init__.cpython-310.pyc | Bin 159 -> 166 bytes climate/__pycache__/settings.cpython-310.pyc | Bin 3271 -> 3146 bytes climate/__pycache__/urls.cpython-310.pyc | Bin 448 -> 455 bytes climate/__pycache__/views.cpython-310.pyc | Bin 501 -> 508 bytes climate/log.txt | 0 climate/settings.py | 4 ++- weather/__pycache__/__init__.cpython-310.pyc | Bin 159 -> 166 bytes weather/__pycache__/admin.cpython-310.pyc | Bin 200 -> 207 bytes weather/__pycache__/apps.cpython-310.pyc | Bin 440 -> 447 bytes weather/__pycache__/models.cpython-310.pyc | Bin 197 -> 204 bytes weather/__pycache__/urls.cpython-310.pyc | Bin 693 -> 700 bytes weather/__pycache__/views.cpython-310.pyc | Bin 6869 -> 6975 bytes .../__pycache__/__init__.cpython-310.pyc | Bin 170 -> 177 bytes weather/views.py | 26 ++++++++++-------- 15 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 .gitignore create mode 100644 climate/log.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2111fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.vscode \ No newline at end of file diff --git a/climate/__pycache__/__init__.cpython-310.pyc b/climate/__pycache__/__init__.cpython-310.pyc index 78172a4a29262b1ce80f3a46c4e655c34f5d4b70..be6ca68be263881f757a3f7fa8982d5f37380c96 100644 GIT binary patch delta 78 zcmbQwxQvk}pO=@50SL};*`-h9u{QJ6&&bbB)lbjJFD}t{NiEJU$uH0^D9X=DO)k+- g&n(F(O^Q#>$-;{0HC!Rp#T5? delta 71 zcmZ3+IG>RxpO=@50SNM0Zl_M|w37uNs) diff --git a/climate/__pycache__/settings.cpython-310.pyc b/climate/__pycache__/settings.cpython-310.pyc index e2904db04770c1f0c34cd9a8c5bba805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$xD3AJTq-c)}~)WL~&tH66=j_N*_> z`BK1()YT^Nnlo^DV#~H#s>bKyw$R_5+Cq0htl;_XzIZ>j;1SF5!Y#gYQ?J^j+ZT&c ubZ=+->CUsm$2$l8pW*@Dc;uhp!|$!@jn;i9Wu?#D7(qigMucu(`t%28g!s4s diff --git a/climate/__pycache__/urls.cpython-310.pyc b/climate/__pycache__/urls.cpython-310.pyc index 5823b77cb10394f0c24a1d2861256aac7a9ea872..e51c92e8cd008a61569d43e4add63f9d93a7fe31 100644 GIT binary patch delta 65 zcmX@We4LplpO=@50SL};*`;sf31MV(ot(%hqF7LrpOu)e6T--7H#w0}M5;VBDWE7nD>b=9zbvz;q%<){KRG8e MH?bsj@-#+60P2MjbpQYW diff --git a/climate/__pycache__/views.cpython-310.pyc b/climate/__pycache__/views.cpython-310.pyc index f65692e5115482d7ef60b5a6acc495bbd35bded0..fcbf4380cc4b4cff3e46c413ed184c717077c1f8 100644 GIT binary patch delta 79 zcmey${D+x0pO=@50SL};*`?o|$h+6fO+O<)H&s79Bfq#r-zBv;yClCrzn~~TD>b=9 hKRvS~qckZ#IVV3aRlhtnu_Pn4C_XQ>ym;czKL9TC9t8jZ delta 72 zcmeyv{FRwEpO=@50SNA~-A=tTk$11Yy?#c1ZmNEIMt*ULzDsIxc1eDLetBwAKv8~H aYI2EwS!Pj5X=09ka!zJ$VoB;G#y$-;{0HC!Rp#T5? delta 71 zcmZ3+IG>RxpO=@50SIog+)kayW3BI`pOK%Ns-K>bUtFT^l3JWyl3$=-o|+U;l%JKF ZT%uo=SyWP*n4_PZlbM@Xk~*$bUtFT^l3JWyl3$=-o|+U;l%JKF ZT%uo=SyWP*n4_PZlbM@Xk~(pv8UQVZ807!} diff --git a/weather/__pycache__/apps.cpython-310.pyc b/weather/__pycache__/apps.cpython-310.pyc index 154fa8608959773ba648dae3d3f8d827b13ad537..60c6e147a966f92862d3b1109dedc3e9352329fc 100644 GIT binary patch delta 80 zcmdnNyq}pTpO=@50SL};*`;sf;b$~+)z8S!P1R4&$S*F@cS$YIF3B&@FDS~-N=+`& iPtPpLC{2n_&dJY9)h|y?EXhbMiqA_eFP`khm diff --git a/weather/__pycache__/models.cpython-310.pyc b/weather/__pycache__/models.cpython-310.pyc index 6fa7042cab3a3e4fc66d012663eb3ee7440da1c7..05837aa2a5dc1bfe3e32d3e1580ba4ed873c3091 100644 GIT binary patch delta 62 zcmX@gc!rTDpO=@50SL};*`-h9NoI7PSRkTUP?VpQnp~ovo>`JnniQX$lb@HWU!Iy+ Ql95^zpO;!*JaL{n06qg0)&Kwi delta 55 zcmX@Zc$ASRpO=@50SIog+)kaylg#Kau|PzsJT)nxC_gJTxkSG#v#6vrF-Jc+Co?y( JBz59abpXsH5_SLp diff --git a/weather/__pycache__/urls.cpython-310.pyc b/weather/__pycache__/urls.cpython-310.pyc index 02dff188514232bc0054b057d9230616f56e6c12..6108eb4f0461c559cc8c53701004e03b6b83a217 100644 GIT binary patch delta 80 zcmdnWx`&k~pO=@50SL};*`;sfv1c-K)z8S!P1R4&$S*F@cS$YIF3B&@FDS~-N=+`& iPtPpLC{2n_&dJY9)h|y?EXhbMiqA_eFP>b*WDNk<`5O@c delta 73 zcmdnPx|NkDpO=@50SK;!-cQ}gW6z{-r=O9Zo2s9lkzZV*?~+=aU6Nm*U!Iy2P?VpQ bnp~n^mRVF%nwX=XoRgWGSdu!qk;xhWR5}>~ diff --git a/weather/__pycache__/views.cpython-310.pyc b/weather/__pycache__/views.cpython-310.pyc index 955d57603812b994e74f28fb7063d46199b249e5..0651ce34a33612fa3ab7d4c3762f7fd23a9206b6 100644 GIT binary patch delta 2293 zcmZ8iU2GiH6~1?7c6Rn>W@rC*ZSTg0q+&zDCWM5)5NMSIXlU9dsVp{_jpIADy;<)# zcg7A5cjO00iV_GRx-o*Yj(5&?7n_UR z?Km@jb9UaJTRPjG>AF3qdBK_X=N#VdITt*6O&z7STvwZPyZonGOMRsf;*&mQbRd6H zN6JcH721FXF%j!%OgpFWwutp(a+g-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wyB@?`RS6&|rL@JeevU z`Vj|DlLa(KMZ%au<>ulb=+qU!BN~@YbLm0^(uM94$RqR#9lY4j_R8;5oqZlGq!*$e zVb2*>h7{WaF>2JSW9(4g1;9%Bu#!=lwSBT9y{Vb}k_|tsVX9F>ehSmWGESy+SS8fL-iJG@bz(Kfx)SYWsg>;XLtQ259j+2okzEN(3%??!@h*!t^NE>3gUm_ zm?&ypug;n?JngDe)iUsPr{(1b~8%I4L8dF@>%vkW}4c<5)JK) z2S{Y(zNS-4Ze(teBUPoYR;@TK|CieVNdN!< diff --git a/weather/migrations/__pycache__/__init__.cpython-310.pyc b/weather/migrations/__pycache__/__init__.cpython-310.pyc index e50b5b1f8d4ba433d75c3c7043766055451250c8..f25c0d52ccb43ec089fb15a3b297244a21458be8 100644 GIT binary patch delta 78 zcmZ3*xRH@3pO=@50SL};*`-h9u{I0Q&&bbB)lbjJFD}t{NiEJU$uH0^D9X=DO)k+- g&n(F(O^Q#>$*oA0IAU$%>V!Z delta 71 zcmdnUxQdY{pO=@50SIog+)kayW3BJ2pOK%Ns-K>bUtFT^l3JWyl3$=-o|+U;l%JKF ZT%uo=SyWP*n4_PZlbM@Xk~*>01OOJG7;OLm diff --git a/weather/views.py b/weather/views.py index d88f254..c3f9d7e 100644 --- a/weather/views.py +++ b/weather/views.py @@ -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: @@ -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: @@ -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: @@ -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) @@ -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: @@ -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()