0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

40代おじさんPythonならXで1Post分で天気予報が取得できる気がした

Last updated at Posted at 2025-06-14

プログラミング面白いよねって初心者がいっても伝わらなくてどうやったら初心者やこれからやりたい人に伝わるかなって思って、色々考えたんだけど

Xで1ポストするぐらいなら1つツールができるよっていう例があったら面白いかなと思って考えてみた

OpenWeatherAPIを使って都市の天気予報を取ってみる

import requests

api="your_key"
def get_weather(city):
    url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api}&units=metric&lang=ja"
    res = requests.get(url)
    data = res.json()
    print(f"{data['name']}の気温は {data['main']['temp']}℃ です")

get_weather("Tokyo")

これツイートできて結構文字数余裕があった APIキー入れても1ポスト分だった

image.png

image.png

ちなみにこんな感じに取れました。

Open Weather APIでAPIキーを取得する必要はあるけれど、何作ろうかなとか、作っていいものわからないとか、壮大なものを考えて作るよりもとりあえず

Xで10回ポストするうちに1つぐらいはツールができると思うので、簡単なことからやってみたら楽しいと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?