I made a weather forecast bot-like with Python.

I made a weather forecast bot-like with Python.

As the title suggests, I made a weather forecast bot-like with Python (not a bot). I was thinking "I wish I could send it on LINE" because I was tired of checking the weather forecast, but my predecessors had already done it, so I made it with wisdom (almost plagiarism). Saw.

What i did

・ Get Yahoo weather information by scraping ・ Display the information obtained by scraping with LINE Notify

Preparation

Installation of required libraries

$pip install beautifulsoup4
$pip install requests

Get token

Issue a token with LINE Notify.

code

import urllib.request
import requests
from bs4 import BeautifulSoup

line_notify_token = 'xxxxxxxxxxxxxxxxxxxxx'#Use the issued token.
line_notify_api = 'https://notify-api.line.me/api/notify'

rssurl = "https://rss-weather.yahoo.co.jp/rss/days/3410.xml"#This code gets the weather information for Sendai.

URL = "https://weather.yahoo.co.jp/weather/jp/8/3410/8201.html"

tenki = []
detail = []


def Parser(rssurl):
   with urllib.request.urlopen(rssurl) as res:
      xml = res.read()
      soup = BeautifulSoup(xml, "html.parser")
      for item in soup.find_all("item"):
         title = item.find("title").string
         description = item.find("description").string
         if title.find("[ PR ]") == -1:
            tenki.append(title)
            detail.append(description)

def Otenki():
    Parser(rssurl)
    for i in range(0,2):
        message = tenki[i]
        payload = {'message': "\n" + message}
        headers = {'Authorization': 'Bearer ' + line_notify_token}
        line_notify = requests.post(line_notify_api, data=payload, headers=headers)

Otenki()

Execution result

IMG_8243.jpg It made me happy that it was sent firmly.

Impressions

Actually I wanted to do automation using AWS, Heroku, but I can not handle it if I jump in without any knowledge and receive a high bill, so I left it so far this time lol. You may try installing the schedule library. It was fun to be able to do various things without knowing when I tried to move it myself.

Also, I would like to update this article while acquiring skills.

Reference article

[Yahoo! Weather Replacement Version] How to get weather information with LINE Notify + Python LINE notification of weather forecast in Python

Recommended Posts

I made a weather forecast bot-like with Python.
I made a fortune with Python.
I made a daemon with Python
I made a character counter with Python
I made a Hex map with Python
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
I made a competitive programming glossary with Python
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made blackjack with python!
Scraping weather forecast with python
I made a python text
I made blackjack with Python.
I made wordcloud with Python.
I made a Twitter BOT with GAE (python) (with a reference)
I made a Christmas tree lighting game with Python
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
I made a Line-bot using Python!
I made a simple typing game with tkinter in Python
I made a package to filter time series with python
I made a simple book application with python + Flask ~ Introduction ~
I made a puzzle game (like) with Tkinter in Python
Tweet the weather forecast with a bot
I made a payroll program in Python!
I drew a heatmap with seaborn [Python]
I tried a functional language with Python
What I did with a Python array
I made a life game with Numpy
I made a stamp generator with GAN
After studying Python3, I made a Slackbot
I made a WEB application with Django
I made a simple circuit with Python (AND, OR, NOR, etc.)
I made a library to easily read config files with Python
I made a package that can compare morphological analyzers with Python
I made a Nyanko tweet form with Python, Flask and Heroku
I made a lot of files for RDP connection with Python
[Python] I made an image viewer with a simple sorting function.
I made a shuffle that can be reset (reverted) with Python
I made a poker game server chat-holdem using websocket with python
I made a segment tree with python, so I will introduce it
I made a stamp substitute bot with line
I made a python dictionary file for Neocomplete
Tweet the weather forecast with a bot Part 2
〇✕ I made a game
View today's weather forecast with a shell script
I made a tool to automatically browse multiple sites with Selenium (Python)
I want to make a game with Python
Procedure for creating a LineBot made with Python
I made a simple Bitcoin wallet with pycoin
I made a LINE Bot with Serverless Framework!
I tried to discriminate a 6-digit number with a number discrimination application made with python
I made a tool that makes decompression a little easier with CLI (Python3)
Let's do web scraping with Python (weather forecast)