Skip to content

Instantly share code, notes, and snippets.

@NeuroWhAI
Created May 4, 2020 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeuroWhAI/f2e7e3d36b4856a4b1a3ae635a69a869 to your computer and use it in GitHub Desktop.
Save NeuroWhAI/f2e7e3d36b4856a4b1a3ae635a69a869 to your computer and use it in GitHub Desktop.
기상청 실시간 지진 감시에서 관측소 진도 데이터만 얻는 예시
import requests
import datetime
head_len = 4
station_cnt = 265 # 원래는 s 파일에서 얻어와야할 정보.
time_offset = 1000
time = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(milliseconds=time_offset)
bin_time = time.strftime('%Y%m%d%H%M%S')
response = requests.get(f"https://www.weather.go.kr/pews/data/{bin_time}.b")
print("Response Code:", response.status_code)
print("Response Size", len(response.content))
data = list(response.content)
body = data[head_len:]
split_idx = body.index('\xff') if '\xff' in body else len(body)
mmi_body = body[:split_idx]
mmi_data = []
for val in mmi_body:
mmi_data.append(val >> 4)
mmi_data.append(val & 0xf)
mmi_data = mmi_data[:station_cnt]
print("len(MMI):", len(mmi_data))
print("MMI:", mmi_data)
@NeuroWhAI
Copy link
Author

파이썬을 쓰는 사람 도와줄 용도로 만든 것이고 원래의 전체 코드는 C#으로 작성되어 있음.
https://gist.github.com/NeuroWhAI/08b548e7fe3e95f0046d50ea427b3c5c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment