Code Monkey home page Code Monkey logo

python_dz9's Introduction

дз к 9 семинару

import requests, json
import telebot

bot = telebot.TeleBot("5546915632:AAFqq0aFHKnNNQ2vFJq00YaGlajSwzTe0ic")
api_key = "198bc5428912d5ba95d5ca90a6f13b3c"

@bot.message_handler(func=lambda message: True)
def send_welcome(message):
    global current_temperature
    base_url = "http://api.openweathermap.org/data/2.5/weather?"
    complete_url = base_url + "appid=" + api_key + "&q=" + str(message.text)
    response = requests.get(complete_url)
    x = response.json()
    if x["cod"] != "404":
        y = x["main"]
        current_temperature = y["temp"]
        current_pressure = y["pressure"]
        current_humidity = y["humidity"]
        z = x["weather"]
        weather_description = z[0]["description"]
    else:
        print(" City Not Found ")
    answer = " Температура (in kelvin unit) = " + str(current_temperature) +"\n Атмосферное давление (in hPa unit) = " + str(current_pressure) +"\n Влажность (in percentage) = " + str(current_humidity) + "\n Описание = " + str(weather_description)
    bot.send_message(message.chat.id, answer)
bot.infinity_polling(none_stop=True)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.