openweathermap.org/ import sys import requests from PyQt5.QtWidgets import (QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout) from PyQt5.QtCore import Qt class WeatherApp(QWidget): def __init__(self): super().__init__() self.city_label = QLabel("Enter city name: ", self) self.city_input = QLineEdit(self) self.get_weather_button = QPushButton("Get Weather", self) self.temperature_label = QLabel(self) self.emoji_label = QLabel(self) self.description_label = QLabel(self) self.initUI() def initUI(self): self.setWindowTitle("Weather App") vbox = QVBoxLayout() vbox.addWidget(self.city_label) vbox.addWidget(self.city_input) vbox.addWidget(self.get_weather_button) vbox.addWidget(self.temperature_label) vbox.addWidget(self.emoji_label) vbox.addWidget(self.description_label) self.setLayout(vbox) self.city_label.setAlignment(Qt.AlignCenter) self.city_input.setAlignment(Qt.AlignCenter) self.temperature_label.setAlignment(Qt.AlignCenter) self.emoji_label.setAlignment(Qt.AlignCenter) self.description_label.setAlignment(Qt.AlignCenter) self.city_label.setObjectName("city_label") self.city_input.setObjectName("city_input") self.get_weather_button.setObjectName("get_weather_button") self.temperature_label.setObjectName("temperature_label") self.emoji_label.setObjectName("emoji_label") self.description_label.setObjectName("description_label") self.setStyleSheet(""" QLabel, QPushButton{ font-family: calibri; } QLabel#city_label{ font-size: 40px; font-style: italic; } QLineEdit#city_input{ font-size: 40px; } QPushButton#get_weather_button{ font-size: 30px; font-weight: bold; } QLabel#temperature_label{ font-size: 75px; } QLabel#emoji_label{ font-size: 100px; font-family: Segoe UI emoji; } QLabel#description_label{ font-size: 50px; } """) self.get_weather_button.clicked.connect(self.get_weather) def get_weather(self): api_key = "YOUR API KEY GOES HERE" city = self.city_input.text() url = f"api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}" try: response = requests.get(url) response.raise_for_status() data = response.json() if data["cod"] == 200: self.display_weather(data) except requests.exceptions.HTTPError as http_error: match response.status_code: case 400: self.display_error("Bad request: Please check your input") case 401: self.display_error("Unauthorized: Invalid API key") case 403: self.display_error("Forbidden: Access is denied") case 404: self.display_error("Not found: City not found") case 500: self.display_error("Internal Server Error: Please try again later") case 502: self.display_error("Bad Gateway: Invalid response from the server") case 503: self.display_error("Service Unavailable: Server is down") case 504: self.display_error("Gateway Timeout: No response from the server") case _: self.display_error(f"HTTP error occurred: {http_error}") except requests.exceptions.ConnectionError: self.display_error("Connection Error: Check your internet connection") except requests.exceptions.Timeout: self.display_error("Timeout Error: The request timed out") except requests.exceptions.TooManyRedirects: self.display_error("Too many Redirects: Check the URL") except requests.exceptions.RequestException as req_error: self.display_error(f"Request Error: {req_error}") def display_error(self, message): self.temperature_label.setStyleSheet("font-size: 30px;") self.temperature_label.setText(message) self.emoji_label.clear() self.description_label.clear() def display_weather(self, data): self.temperature_label.setStyleSheet("font-size: 75px;") temperature_k = data["main"]["temp"] temperature_c = temperature_k - 273.15 temperature_f = (temperature_k * 9/5) - 459.67 weather_id = data["weather"][0]["id"] weather_description = data["weather"][0]["description"] self.temperature_label.setText(f"{temperature_f:.0f}°F") self.emoji_label.setText(self.get_weather_emoji(weather_id)) self.description_label.setText(weather_description) @staticmethod def get_weather_emoji(weather_id): if 200
@শখেরবাড়ি৯৯০3 ай бұрын
Great🎉
@ZaeNonQ3 ай бұрын
this will be good for my non-existent portofolio!
@KouroshKrypticАй бұрын
Wdym?
@LouOllivier-Hostin2 ай бұрын
You are an incredible human being, congratulations buddy !
@gameios9923 ай бұрын
Hello Bro, i am studying your course and that is amazing. Thank you. Hope i can become a freelancer by your lessons
@শখেরবাড়ি৯৯০3 ай бұрын
Thanks for all your videos as a 12 year old i learned a lot . You are pure programming gigachad...
@rohlualalrohluaralte3 ай бұрын
He really is a good teacher..I enjoyed this a lot...I'm 9 btw
@felixiyy3 ай бұрын
Yea he's an amazing teacher , I'm 7 yrs old , I understood everything❤
@axelgallo83613 ай бұрын
yeah he great i`m 4 yer old thank bro code
@heyimrith3 ай бұрын
Yea that right as a 11 month old I agree that, I use my brother account
@felixiyy3 ай бұрын
Actually my brother who is still in the uterus has learnt quite a lot of programming, he even has made a snake game from bro codes tutorial
@_ba0_2 ай бұрын
Bro is here to save the day again. Thanks to you now I can make guis that don't suck😀
@wrightsolution3 ай бұрын
plz bro make a playlist on javascript projects. You're the only channel in which i could understand and enjoy programming
@yokochannn3 ай бұрын
damn bro u already at 2m? your channel is the reason i love do coding and learn about programming. Now i take scicomp course and go back to your channel to learn more
@jjdifsjdfinsd27 күн бұрын
Nice video ima doing GCSEs in python at my school so doing this as extra at home really helps thank you for theses videos! ❤
@Hlmg-hw6om7 сағат бұрын
Great Tutorial. Thank you very much :)
@Krishna-kk5xx3 ай бұрын
Thanks for this master piece bro
@mistron1763 ай бұрын
You are a legend man
@meowmeowzza3 ай бұрын
Bro Code have you ever made a lua course video? I know you did for C++, both of the languages go together very well would love it if you made a lua course!
@fallenkafielАй бұрын
How I learn coding with Python by watching coding videos and following along with bro code.
@zyn_rgy3 ай бұрын
The best Tech Giga-Chad i've ever seen
@nkproduction55703 ай бұрын
Bro Code is THE GOAT
@sergeikalabanov70673 ай бұрын
Thank you!! Perfect!!
@BeanBagGaming593 ай бұрын
bro can u please make a tutorial on unreal engine 5 and if you dont know it yet , with your expertise you can prob learn it in like 4 hours lol ur tutorials are the best on youtube forsure so if u can do a tutorial on unreal engine 5 that would be so amazing
@NSA.3 ай бұрын
Great
@kingfares13713 ай бұрын
which should I watch this playlist or the 12 hours video??
@Mr.ShubhGoel3 ай бұрын
hey dude, i was wondering if you could make setup video of VS CODE for the language C bcz i don't get my output under the OUTPUT bar rather i get it under the terminal bar i wish u would reply soon 😀...
@trithanh85363 ай бұрын
thank sir
@magnivvvvv2 ай бұрын
the all thing with the import sys isnt working to me. "no model named requests"
@DeadSoul26-o4q3 ай бұрын
Hello, I know this is a weird question but I have a problem with the random module; randit(); in the snake game. It says something about float can't be interpreted into an integer. Bro please help me solve this. Appropriate your work tho :)
@mohameddeeq-l2s3 ай бұрын
ask chatgpt
@DeadSoul26-o4q2 ай бұрын
@@mohameddeeq-l2s I did and he's not providing useful info
@mintz3473 ай бұрын
Do some Django,or spring boot project bro??
@QuantumSc26 күн бұрын
Yo bro can you explain what yield means?
@sayaadadurian3 ай бұрын
Do a lesson on Enums
@AbdulraheemAbdullah-e4w3 ай бұрын
vote for node js and mern stack course big fan plz upload mern stack course u already have upload php but i dont like php plz upload mern stack
@tarindell1873 ай бұрын
Can you please talk about qthreads
@faiza47693 ай бұрын
Bro do pytorch course please
@rajushah87483 ай бұрын
❤❤
@kavitarattan-jo7qb3 ай бұрын
Do a Face Reval Bro
@abdallahaltozeri38973 ай бұрын
No more Java projects tutorials ?
@BenChoke3 ай бұрын
first comment! ur vids are cool!
@Blockify-13 ай бұрын
Bro "Brake youtube algoritm"like and write random comments
@nimportqoi4 күн бұрын
hello bro code
@rafflewitz3 ай бұрын
Import Cutie 🤯
@vaibhavkumar2366Ай бұрын
Naming the package QtPy would've been so much better
@FlorianBini28 күн бұрын
Weich Engine
@aDevBilly3 ай бұрын
what a real chad
@nimportqoi4 күн бұрын
ff
@m0rph_6993 ай бұрын
bro pleasee do a face rev
@Thezdring116 күн бұрын
nah bro is such a gigachad we will probobly get blind just from seeing his face