Created
July 17, 2024 00:16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import datetime | |
import pytz | |
url = "http://api.open-notify.org/iss-now.json" | |
response = requests.get(url) | |
data = response.json() | |
# データの抽出 | |
timestamp = data['timestamp'] | |
latitude = data['iss_position']['latitude'] | |
longitude = data['iss_position']['longitude'] | |
# timestampをUTCからJSTに変換 | |
utc_time = datetime.datetime.utcfromtimestamp(timestamp) | |
jst = pytz.timezone('Asia/Tokyo') | |
jst_time = utc_time.replace(tzinfo=pytz.utc).astimezone(jst) | |
jst_date_time = jst_time.strftime('%Y-%m-%d %H:%M:%S') | |
# 結果を表示 | |
print(f"Date and Time (JST): {jst_date_time}") | |
print(f"Latitude: {latitude}") | |
print(f"Longitude: {longitude}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment