From 8bc8b9832209f7f44723d3dbf98387a4e904a478 Mon Sep 17 00:00:00 2001 From: LG <76845820+im-coder-lg@users.noreply.github.com> Date: Wed, 25 Jan 2023 19:52:19 +0530 Subject: [PATCH 01/13] First INDEV commit! --- .vscode/launch.json | 17 ++++++++++ main.py | 76 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 main.py diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f3a508e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "externalTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..136cd42 --- /dev/null +++ b/main.py @@ -0,0 +1,76 @@ +import os +import sys +from time import sleep + +import requests + +TOKEN = "f2c9ba5917df10d29b7d7f97a4cce627" +BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" +BREAK = "\n\n=====\n\n" + + +def breakliner(): + print(f"{BREAK:-^30}") + return + + +def clearScreen(): + if sys.platform == "windows": + os.system("cls") + else: + os.system("clear") + return + + +def exitQuery(): + exitQ = input("Exit? ") + if exitQ == "y": + exit() + elif exitQ == "n": + clearScreen() + OWMCITY() + + +def OWMCITY(): + # City Name request + print("Enter City Name (should be in compliance to OpenWeatherMap's City Index) :") + CITY = input() + if CITY == "exit": + clearScreen() + print("Three") + sleep(1) + clearScreen() + print("Two") + sleep(1) + clearScreen() + print("One.") + sleep(1) + clearScreen() + print("Exiting...") + sleep(0.5) + exit() + + else: + pass + # The URL in actuality be like: + URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN + + # PROD: Request Response + resp_PROD = requests.get(URL) + if resp_PROD.status_code == 200: + pass + else: + raise TypeError("Oops, wrong city name or code?") + sleep(5) + exit() + + breakliner() + data = resp_PROD.json() + print(data) + breakliner() + return data + + +OWMCITY() + +exitQuery() From 35fdb63619d2a02826169c05f72be78cc0edb32e Mon Sep 17 00:00:00 2001 From: lg Date: Thu, 26 Jan 2023 18:07:00 +0530 Subject: [PATCH 02/13] First. Proper. INDEV. COMMIT! --- .vscode/settings.json | 11 +++++++++++ main.py | 5 ++++- tests/test_api.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100644 tests/test_api.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b1506db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tests", + "-p", + "test*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true +} \ No newline at end of file diff --git a/main.py b/main.py index 136cd42..54ce9a0 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,13 @@ import os import sys from time import sleep +import dotenv import requests -TOKEN = "f2c9ba5917df10d29b7d7f97a4cce627" +dotenv.load_dotenv() + +TOKEN = os.getenv("TOKEN") BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" BREAK = "\n\n=====\n\n" diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..e890958 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,30 @@ +import requests +import os +from dotenv import load_dotenv +import unittest +from time import sleep + + +class testAPILoad(unittest.TestCase): + load_dotenv() + def test_token(self): + TOKEN = os.getenv("TOKEN") + print(TOKEN) + return TOKEN + + def test_request(self): + CITY = "Norway" # test *only* + TOKEN = os.getenv("TOKEN") + BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" + URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN + resp_PROD = requests.get(URL) + if resp_PROD.status_code == 200: + print(resp_PROD.status_code) + pass + else: + raise TypeError("Oops, wrong city name or code?") + sleep(5) + exit() + +if __name__ == "__main__": + unittest.main() From 93a63ef6844c866666c5c048e1636a72870735aa Mon Sep 17 00:00:00 2001 From: lg Date: Thu, 26 Jan 2023 18:14:09 +0530 Subject: [PATCH 03/13] second commit, redefined --- Justfile | 7 +++++++ main.py | 2 +- tests/test_api.py | 11 +++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 Justfile diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..0e9d89a --- /dev/null +++ b/Justfile @@ -0,0 +1,7 @@ +isort: + python3 -m isort *.py + python3 -m isort tests/*.py + +black: + python3 -m black *.py + python3 -m black tests/*.py \ No newline at end of file diff --git a/main.py b/main.py index 54ce9a0..48458be 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,8 @@ import os import sys from time import sleep -import dotenv +import dotenv import requests dotenv.load_dotenv() diff --git a/tests/test_api.py b/tests/test_api.py index e890958..15c5221 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,19 +1,21 @@ -import requests import os -from dotenv import load_dotenv import unittest from time import sleep +import requests +from dotenv import load_dotenv + class testAPILoad(unittest.TestCase): load_dotenv() + def test_token(self): TOKEN = os.getenv("TOKEN") print(TOKEN) return TOKEN - + def test_request(self): - CITY = "Norway" # test *only* + CITY = "Norway" # test *only* TOKEN = os.getenv("TOKEN") BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN @@ -26,5 +28,6 @@ def test_request(self): sleep(5) exit() + if __name__ == "__main__": unittest.main() From 2c31d6d4c964a3a77e40950a2c16cd4a2aca3f82 Mon Sep 17 00:00:00 2001 From: sumeshir26 <68823982+sumeshir26@users.noreply.github.com> Date: Fri, 27 Jan 2023 19:35:16 +0530 Subject: [PATCH 04/13] chore: Add my API token --- main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/main.py b/main.py index 48458be..95cccdc 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,10 @@ -import os import sys from time import sleep -import dotenv import requests -dotenv.load_dotenv() -TOKEN = os.getenv("TOKEN") +TOKEN = "02a48fc85823393c2c20c321febeffb8" BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" BREAK = "\n\n=====\n\n" From 77c076517a9e7436293d65073376b57fe7db4c75 Mon Sep 17 00:00:00 2001 From: sumeshir26 <68823982+sumeshir26@users.noreply.github.com> Date: Fri, 27 Jan 2023 19:35:30 +0530 Subject: [PATCH 05/13] Update main.py --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 95cccdc..4e7132f 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -import sys +import os from time import sleep import requests From 776c782594f9b81695c4057d3727720fe3ff416c Mon Sep 17 00:00:00 2001 From: sumeshir26 <68823982+sumeshir26@users.noreply.github.com> Date: Sun, 29 Jan 2023 19:04:11 +0530 Subject: [PATCH 06/13] fix: Search for city instead of performing hard match. --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 4e7132f..0907897 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ TOKEN = "02a48fc85823393c2c20c321febeffb8" -BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" +BASE_URL = "https://api.openweathermap.org/data/2.5/weather?q=" BREAK = "\n\n=====\n\n" From c2536c9ab2eca3a415ce4813ae1733255be98978 Mon Sep 17 00:00:00 2001 From: LG <76845820+im-coder-lg@users.noreply.github.com> Date: Tue, 31 Jan 2023 17:05:19 +0530 Subject: [PATCH 07/13] woohoo booyah ha! --- Justfile | 5 ++++- main.py | 42 +++++++++++++++++++++++++++++++++--------- requirements.txt | 6 ++++++ tests/test_api.py | 25 +++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 requirements.txt diff --git a/Justfile b/Justfile index 0e9d89a..abb20db 100644 --- a/Justfile +++ b/Justfile @@ -4,4 +4,7 @@ isort: black: python3 -m black *.py - python3 -m black tests/*.py \ No newline at end of file + python3 -m black tests/*.py + +install: + python3 -m pip3 install -r requirements.txt \ No newline at end of file diff --git a/main.py b/main.py index 0907897..da704c5 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,16 @@ import os from time import sleep - +import sys import requests -TOKEN = "02a48fc85823393c2c20c321febeffb8" -BASE_URL = "https://api.openweathermap.org/data/2.5/weather?q=" + +TOKEN = "c439e1209216cc7e7c73a3a8d1d12bfd" +BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" BREAK = "\n\n=====\n\n" +TOKEN = os.getenv("TOKEN") + + def breakliner(): @@ -33,8 +37,8 @@ def exitQuery(): def OWMCITY(): # City Name request - print("Enter City Name (should be in compliance to OpenWeatherMap's City Index) :") - CITY = input() + global CITY + CITY = input("Enter City Name (should be in compliance to OpenWeatherMap's City Index): ") if CITY == "exit": clearScreen() print("Three") @@ -56,21 +60,41 @@ def OWMCITY(): URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN # PROD: Request Response + global resp_PROD resp_PROD = requests.get(URL) if resp_PROD.status_code == 200: pass else: raise TypeError("Oops, wrong city name or code?") - sleep(5) - exit() breakliner() + global data data = resp_PROD.json() print(data) breakliner() - return data - OWMCITY() + + +def data_processing(): + main = data["main"] + humidity = main["humidity"] + pressure = main["pressure"] + temp = main['temp'] + temp_min = main['temp_min'] + temp_max = main['temp_max'] + def ktc(temp, temp_min, temp_max): + temp = temp - 273.15 + temp_min = temp_min - 273.15 + temp_max = temp_max - 273.15 + print("Temperature: ", temp, "°C") + print("Minimum Temperature: ", temp_min, "°C") + print("Maximum Temperature: ", temp_max, "°C") + print(ktc(temp, temp_min, temp_max)) + print(data['weather'][0]['main']) + +data_processing() + + exitQuery() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..801e2e2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +pyowm +requests +python-dotenv +python-unittest +isort +black \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py index 15c5221..1b17e44 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,10 +1,10 @@ import os import unittest from time import sleep - import requests from dotenv import load_dotenv +CITY = "Norway" # test *only* class testAPILoad(unittest.TestCase): load_dotenv() @@ -15,11 +15,12 @@ def test_token(self): return TOKEN def test_request(self): - CITY = "Norway" # test *only* TOKEN = os.getenv("TOKEN") BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN resp_PROD = requests.get(URL) + global data + data = resp_PROD.json() if resp_PROD.status_code == 200: print(resp_PROD.status_code) pass @@ -27,7 +28,27 @@ def test_request(self): raise TypeError("Oops, wrong city name or code?") sleep(5) exit() + return CITY + def test_pyowm(self): + TOKEN = os.getenv("TOKEN") + + main = data["main"] + humidity = main["humidity"] + pressure = main["pressure"] + temp = main['temp'] + temp_min = main['temp_min'] + temp_max = main['temp_max'] + def ktc(temp, temp_min, temp_max): + temp = temp - 273.15 + temp_min = temp_min - 273.15 + temp_max = temp_max - 273.15 + print("Temperature: ", temp, "°C") + print("Minimum Temperature: ", temp_min, "°C") + print("Maximum Temperature: ", temp_max, "°C") + print(ktc(temp, temp_min, temp_max)) + print(data['weather'][0]['main']) + if __name__ == "__main__": unittest.main() From 0916e147c257f595302d6e859d32f64dc39da3c9 Mon Sep 17 00:00:00 2001 From: lg Date: Tue, 31 Jan 2023 17:16:36 +0530 Subject: [PATCH 08/13] proper changes --- Justfile | 2 +- tests/test_api.py | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Justfile b/Justfile index abb20db..9159de8 100644 --- a/Justfile +++ b/Justfile @@ -7,4 +7,4 @@ black: python3 -m black tests/*.py install: - python3 -m pip3 install -r requirements.txt \ No newline at end of file + python3 -m pip install -r requirements.txt \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py index 1b17e44..9b8fa86 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -4,23 +4,19 @@ import requests from dotenv import load_dotenv +TOKEN = os.getenv("TOKEN") +print(TOKEN) CITY = "Norway" # test *only* +BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" +URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN +resp_PROD = requests.get(URL) + class testAPILoad(unittest.TestCase): load_dotenv() - def test_token(self): - TOKEN = os.getenv("TOKEN") - print(TOKEN) - return TOKEN - def test_request(self): TOKEN = os.getenv("TOKEN") - BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" - URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN - resp_PROD = requests.get(URL) - global data - data = resp_PROD.json() if resp_PROD.status_code == 200: print(resp_PROD.status_code) pass @@ -28,10 +24,9 @@ def test_request(self): raise TypeError("Oops, wrong city name or code?") sleep(5) exit() - return CITY - def test_pyowm(self): + def test_data_processcode(self): TOKEN = os.getenv("TOKEN") - + data = resp_PROD.json() main = data["main"] humidity = main["humidity"] pressure = main["pressure"] From 648cda00b4c76d383f6f8eca63859446f4b6afa0 Mon Sep 17 00:00:00 2001 From: lg Date: Tue, 31 Jan 2023 17:17:49 +0530 Subject: [PATCH 09/13] black and isort --- main.py | 24 +++++++++++++----------- tests/test_api.py | 13 ++++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index da704c5..e7d69ee 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,8 @@ import os -from time import sleep import sys -import requests - +from time import sleep +import requests TOKEN = "c439e1209216cc7e7c73a3a8d1d12bfd" BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" @@ -11,8 +10,6 @@ TOKEN = os.getenv("TOKEN") - - def breakliner(): print(f"{BREAK:-^30}") return @@ -38,7 +35,9 @@ def exitQuery(): def OWMCITY(): # City Name request global CITY - CITY = input("Enter City Name (should be in compliance to OpenWeatherMap's City Index): ") + CITY = input( + "Enter City Name (should be in compliance to OpenWeatherMap's City Index): " + ) if CITY == "exit": clearScreen() print("Three") @@ -73,17 +72,18 @@ def OWMCITY(): print(data) breakliner() -OWMCITY() +OWMCITY() def data_processing(): main = data["main"] humidity = main["humidity"] pressure = main["pressure"] - temp = main['temp'] - temp_min = main['temp_min'] - temp_max = main['temp_max'] + temp = main["temp"] + temp_min = main["temp_min"] + temp_max = main["temp_max"] + def ktc(temp, temp_min, temp_max): temp = temp - 273.15 temp_min = temp_min - 273.15 @@ -91,8 +91,10 @@ def ktc(temp, temp_min, temp_max): print("Temperature: ", temp, "°C") print("Minimum Temperature: ", temp_min, "°C") print("Maximum Temperature: ", temp_max, "°C") + print(ktc(temp, temp_min, temp_max)) - print(data['weather'][0]['main']) + print(data["weather"][0]["main"]) + data_processing() diff --git a/tests/test_api.py b/tests/test_api.py index 9b8fa86..1efc660 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,6 +1,7 @@ import os import unittest from time import sleep + import requests from dotenv import load_dotenv @@ -24,15 +25,17 @@ def test_request(self): raise TypeError("Oops, wrong city name or code?") sleep(5) exit() + def test_data_processcode(self): TOKEN = os.getenv("TOKEN") data = resp_PROD.json() main = data["main"] humidity = main["humidity"] pressure = main["pressure"] - temp = main['temp'] - temp_min = main['temp_min'] - temp_max = main['temp_max'] + temp = main["temp"] + temp_min = main["temp_min"] + temp_max = main["temp_max"] + def ktc(temp, temp_min, temp_max): temp = temp - 273.15 temp_min = temp_min - 273.15 @@ -40,10 +43,10 @@ def ktc(temp, temp_min, temp_max): print("Temperature: ", temp, "°C") print("Minimum Temperature: ", temp_min, "°C") print("Maximum Temperature: ", temp_max, "°C") + print(ktc(temp, temp_min, temp_max)) - print(data['weather'][0]['main']) + print(data["weather"][0]["main"]) - if __name__ == "__main__": unittest.main() From e1eb946d61864c4b31db7cc8b0db4d7048bbb139 Mon Sep 17 00:00:00 2001 From: lg Date: Tue, 31 Jan 2023 18:35:05 +0530 Subject: [PATCH 10/13] Ready for merging :+1: --- main.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index e7d69ee..d6bb32a 100644 --- a/main.py +++ b/main.py @@ -66,11 +66,9 @@ def OWMCITY(): else: raise TypeError("Oops, wrong city name or code?") - breakliner() global data data = resp_PROD.json() - print(data) - breakliner() + OWMCITY() @@ -91,10 +89,34 @@ def ktc(temp, temp_min, temp_max): print("Temperature: ", temp, "°C") print("Minimum Temperature: ", temp_min, "°C") print("Maximum Temperature: ", temp_max, "°C") - - print(ktc(temp, temp_min, temp_max)) - print(data["weather"][0]["main"]) - + CITY = data["name"] + sys = data['sys'] + country = sys['country'] + CITY2 = CITY + ',' + ' ' + country + if CITY == CITY2: + pass + else: + CITY = data["name"] + sys = data['sys'] + country = sys['country'] + CITY2 = CITY + ',' + ' ' + country + + w_main = data["weather"][0]["main"] + w_desc = data["weather"][0]["description"] + pressure = main["pressure"] + visibility = data["visibility"] + visibility_new = visibility/1000 + wind = data['wind']['speed'] + def printData(): + breakliner() + print(f"{CITY2:-^30}") + print(f"Weather: {w_main}:- {w_desc}") + ktc(temp, temp_min, temp_max) + print(f"Humidity: {humidity}%") + print(f"Pressure: {pressure} hPa") + print(f"Wind speed: {wind} m/s") + print(f"Visibility: {visibility} m (or) {visibility_new} km") + printData() data_processing() From 8667d46bcbbd57d39bd26a6bc77b5b4448c46097 Mon Sep 17 00:00:00 2001 From: lg Date: Tue, 31 Jan 2023 18:35:42 +0530 Subject: [PATCH 11/13] Last minute formatting --- main.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index d6bb32a..b854123 100644 --- a/main.py +++ b/main.py @@ -70,7 +70,6 @@ def OWMCITY(): data = resp_PROD.json() - OWMCITY() @@ -89,24 +88,26 @@ def ktc(temp, temp_min, temp_max): print("Temperature: ", temp, "°C") print("Minimum Temperature: ", temp_min, "°C") print("Maximum Temperature: ", temp_max, "°C") + CITY = data["name"] - sys = data['sys'] - country = sys['country'] - CITY2 = CITY + ',' + ' ' + country + sys = data["sys"] + country = sys["country"] + CITY2 = CITY + "," + " " + country if CITY == CITY2: pass else: CITY = data["name"] - sys = data['sys'] - country = sys['country'] - CITY2 = CITY + ',' + ' ' + country - + sys = data["sys"] + country = sys["country"] + CITY2 = CITY + "," + " " + country + w_main = data["weather"][0]["main"] w_desc = data["weather"][0]["description"] pressure = main["pressure"] visibility = data["visibility"] - visibility_new = visibility/1000 - wind = data['wind']['speed'] + visibility_new = visibility / 1000 + wind = data["wind"]["speed"] + def printData(): breakliner() print(f"{CITY2:-^30}") @@ -116,8 +117,10 @@ def printData(): print(f"Pressure: {pressure} hPa") print(f"Wind speed: {wind} m/s") print(f"Visibility: {visibility} m (or) {visibility_new} km") + printData() + data_processing() From 6f1beadb1827d60f4a1a7d73acc3d80aaa14276e Mon Sep 17 00:00:00 2001 From: lg Date: Tue, 31 Jan 2023 20:39:07 +0530 Subject: [PATCH 12/13] Fix @Moosems's issue --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index b854123..8aeecba 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ TOKEN = "c439e1209216cc7e7c73a3a8d1d12bfd" BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" BREAK = "\n\n=====\n\n" -TOKEN = os.getenv("TOKEN") +# TOKEN = os.getenv("TOKEN") def breakliner(): From 549318f136339727281fbed46dc6fb0e94d23e54 Mon Sep 17 00:00:00 2001 From: sumeshir26 <68823982+sumeshir26@users.noreply.github.com> Date: Tue, 31 Jan 2023 21:46:34 +0530 Subject: [PATCH 13/13] fix: Actuallay fix @Moosems 's issue --- main.py | 82 ++++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 44 deletions(-) diff --git a/main.py b/main.py index 8aeecba..850b373 100644 --- a/main.py +++ b/main.py @@ -31,48 +31,6 @@ def exitQuery(): clearScreen() OWMCITY() - -def OWMCITY(): - # City Name request - global CITY - CITY = input( - "Enter City Name (should be in compliance to OpenWeatherMap's City Index): " - ) - if CITY == "exit": - clearScreen() - print("Three") - sleep(1) - clearScreen() - print("Two") - sleep(1) - clearScreen() - print("One.") - sleep(1) - clearScreen() - print("Exiting...") - sleep(0.5) - exit() - - else: - pass - # The URL in actuality be like: - URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN - - # PROD: Request Response - global resp_PROD - resp_PROD = requests.get(URL) - if resp_PROD.status_code == 200: - pass - else: - raise TypeError("Oops, wrong city name or code?") - - global data - data = resp_PROD.json() - - -OWMCITY() - - def data_processing(): main = data["main"] humidity = main["humidity"] @@ -119,9 +77,45 @@ def printData(): print(f"Visibility: {visibility} m (or) {visibility_new} km") printData() + +def OWMCITY(): + # City Name request + global CITY + CITY = input( + "Enter City Name (should be in compliance to OpenWeatherMap's City Index): " + ) + if CITY == "exit": + clearScreen() + print("Three") + sleep(1) + clearScreen() + print("Two") + sleep(1) + clearScreen() + print("One.") + sleep(1) + clearScreen() + print("Exiting...") + sleep(0.5) + exit() + else: + pass + # The URL in actuality be like: + URL = BASE_URL + "q=" + CITY + "&appid=" + TOKEN -data_processing() + # PROD: Request Response + global resp_PROD + resp_PROD = requests.get(URL) + if resp_PROD.status_code == 200: + pass + else: + raise TypeError("Oops, wrong city name or code?") + global data + data = resp_PROD.json() + + data_processing() + exitQuery() -exitQuery() +OWMCITY()