Skip to content

Instantly share code, notes, and snippets.

@smzn
Created July 17, 2024 00:16
Show Gist options
  • Save smzn/5b65f00d69f50c4b462237831630da9c to your computer and use it in GitHub Desktop.
Save smzn/5b65f00d69f50c4b462237831630da9c to your computer and use it in GitHub Desktop.
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