Python
- 4 ответа
- 0 вопросов
4
Вклад в тег
import pyowm
import telebot
# от блокировок
# from telebot import apihelper
# apihelper.proxy = {'https':'socks5://127.0.0.1:9050'}
owm=pyowm.OWM('df1....51', language = 'ru')
bot = telebot.TeleBot('106...ilQ')
@bot.message_handler(content_types=['text'])
def send_echo(message):
try:
observation = owm.weather_at_place(message.text)
w = observation.get_weather()
temp=w.get_temperature('celsius')['temp']
answer = f"В городе {message.text} сейчас {w.get_detailed_status()} \n"
answer += f"Температура в районе {round(temp)} градусов\n\n"
if temp<10:
answer += 'Очень холодно, оденься потеплее))'
elif temp<17:
answer += 'Прохладно, лучше оденься:)'
else:
answer += 'Не холодно, хоть в трусах иди:)'
bot.send_message(message.chat.id, answer)
except pyowm.exceptions.api_response_error.NotFoundError:
bot.send_message(message.chat.id, 'Город не найден :(')
bot.polling(none_stop = True)
from bs4 import BeautifulSoup
import requests
url='https://jut.su/jojo-bizarre-adventure/season-1/episode-16.html'
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0'
}
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.content, 'html.parser')
sources = soup.find_all('source', src=True)
with requests.get(sources[0]['src'], headers=headers, stream=True) as r:
r.raise_for_status()
with open("JOJO.mp4", 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)