Let's code a WEATHER APP in Python! ☀️

Поделиться
HTML-код
  • Опубликовано: 10 фев 2025

Комментарии • 74

  • @BroCodez
    @BroCodez  6 месяцев назад +16

    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

  • @ZaeNonQ
    @ZaeNonQ 6 месяцев назад +41

    this will be good for my non-existent portofolio!

  • @LouOllivier-Hostin
    @LouOllivier-Hostin 4 месяца назад +6

    You are an incredible human being, congratulations buddy !

  • @_ba0_
    @_ba0_ 5 месяцев назад +5

    Bro is here to save the day again. Thanks to you now I can make guis that don't suck😀

  • @jjdifsjdfinsd
    @jjdifsjdfinsd 3 месяца назад +3

    Nice video ima doing GCSEs in python at my school so doing this as extra at home really helps thank you for theses videos! ❤

  • @gameios992
    @gameios992 6 месяцев назад +6

    Hello Bro, i am studying your course and that is amazing. Thank you. Hope i can become a freelancer by your lessons

  • @শখেরবাড়ি৯৯০
    @শখেরবাড়ি৯৯০ 6 месяцев назад +12

    Thanks for all your videos as a 12 year old i learned a lot . You are pure programming gigachad...

    • @rohlualalrohluaralte
      @rohlualalrohluaralte 6 месяцев назад +8

      He really is a good teacher..I enjoyed this a lot...I'm 9 btw

    • @felixiyy
      @felixiyy 6 месяцев назад +4

      Yea he's an amazing teacher , I'm 7 yrs old , I understood everything❤

    • @axelgallo8361
      @axelgallo8361 6 месяцев назад +9

      yeah he great i`m 4 yer old thank bro code

    • @heyimrith
      @heyimrith 6 месяцев назад +10

      Yea that right as a 11 month old I agree that, I use my brother account

    • @felixiyy
      @felixiyy 6 месяцев назад +9

      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

  • @yokochannn
    @yokochannn 6 месяцев назад +1

    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

  • @Hlmg-hw6om
    @Hlmg-hw6om 2 месяца назад +2

    Great Tutorial. Thank you very much :)

  • @wrightsolution
    @wrightsolution 6 месяцев назад +1

    plz bro make a playlist on javascript projects. You're the only channel in which i could understand and enjoy programming

  • @mistron176
    @mistron176 6 месяцев назад +1

    You are a legend man

  • @sergeikalabanov7067
    @sergeikalabanov7067 6 месяцев назад +1

    Thank you!! Perfect!!

  • @zyn_rgy
    @zyn_rgy 6 месяцев назад

    The best Tech Giga-Chad i've ever seen

  • @Krishna-kk5xx
    @Krishna-kk5xx 6 месяцев назад

    Thanks for this master piece bro

  • @nkproduction5570
    @nkproduction5570 6 месяцев назад

    Bro Code is THE GOAT

  • @larry8287
    @larry8287 Месяц назад

    thank you !

  • @AliRozy
    @AliRozy 2 месяца назад

    bro thank you so much

  • @meowmeowzza
    @meowmeowzza 6 месяцев назад

    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!

  • @kingfares1371
    @kingfares1371 6 месяцев назад +2

    which should I watch this playlist or the 12 hours video??

  • @Invidoe-1
    @Invidoe-1 Месяц назад

    thanks bro

  • @BeanBagGaming59
    @BeanBagGaming59 6 месяцев назад

    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.
    @NSA. 6 месяцев назад

    Great

  • @fallenkafiel42
    @fallenkafiel42 4 месяца назад

    How I learn coding with Python by watching coding videos and following along with bro code.

  • @trithanh8536
    @trithanh8536 6 месяцев назад

    thank sir

  • @Mr.ShubhGoel
    @Mr.ShubhGoel 6 месяцев назад +1

    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 😀...

  • @flioink
    @flioink 19 дней назад

    Excellent tutorial!
    Btw I typed "Narnia" to test the error message but the API returned 200 😳

  • @BenChoke
    @BenChoke 6 месяцев назад +3

    first comment! ur vids are cool!

  • @DeadSoul26-o4q
    @DeadSoul26-o4q 6 месяцев назад +2

    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-l2s
      @mohameddeeq-l2s 6 месяцев назад +1

      ask chatgpt

    • @DeadSoul26-o4q
      @DeadSoul26-o4q 5 месяцев назад

      @@mohameddeeq-l2s I did and he's not providing useful info

  • @rajushah8748
    @rajushah8748 6 месяцев назад

    ❤❤

  • @mintz347
    @mintz347 6 месяцев назад

    Do some Django,or spring boot project bro??

  • @sayaadadurian
    @sayaadadurian 6 месяцев назад

    Do a lesson on Enums

  • @rafflewitz
    @rafflewitz 5 месяцев назад

    Import Cutie 🤯

    • @Vincent_lyf
      @Vincent_lyf 4 месяца назад

      Naming the package QtPy would've been so much better

  • @QuantumSc
    @QuantumSc 3 месяца назад

    Yo bro can you explain what yield means?

  • @linuxeducation4058
    @linuxeducation4058 Месяц назад

    Now you can created a widget on your desktop for Windows, Linux, Mac OSX ;)

  • @tarindell187
    @tarindell187 6 месяцев назад

    Can you please talk about qthreads

  • @faiza4769
    @faiza4769 5 месяцев назад

    Bro do pytorch course please

  • @magnivvvvv
    @magnivvvvv 4 месяца назад +2

    the all thing with the import sys isnt working to me. "no model named requests"

    • @dhiyanabdurazack5257
      @dhiyanabdurazack5257 2 месяца назад

      import

    • @YLMisHim
      @YLMisHim 23 дня назад

      i know im late, but same thing happened to me, turn out you have to go to the terminal and the type in "pip install requests" and it should work

    • @magnivvvvv
      @magnivvvvv 23 дня назад

      @@YLMisHim I don't remember what I was talking about, but thx

  • @AbdulraheemAbdullah-e4w
    @AbdulraheemAbdullah-e4w 6 месяцев назад

    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

  • @Blockify-1
    @Blockify-1 6 месяцев назад

    Bro "Brake youtube algoritm"like and write random comments

  • @abdallahaltozeri3897
    @abdallahaltozeri3897 6 месяцев назад

    No more Java projects tutorials ?

  • @aDevBilly
    @aDevBilly 6 месяцев назад +2

    what a real chad

  • @M.usfirah_
    @M.usfirah_ Месяц назад

    31:55

  • @nimportqoi
    @nimportqoi 2 месяца назад +1

    hello bro code

  • @m0rph_699
    @m0rph_699 6 месяцев назад

    bro pleasee do a face rev

    • @Thezdring1
      @Thezdring1 3 месяца назад

      nah bro is such a gigachad we will probobly get blind just from seeing his face

  • @FlorianBini
    @FlorianBini 3 месяца назад

    Weich Engine

  • @nimportqoi
    @nimportqoi 2 месяца назад +1

    ff