Created
May 4, 2020 11:21
-
-
Save NeuroWhAI/f2e7e3d36b4856a4b1a3ae635a69a869 to your computer and use it in GitHub Desktop.
기상청 실시간 지진 감시에서 관측소 진도 데이터만 얻는 예시
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 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
파이썬을 쓰는 사람 도와줄 용도로 만든 것이고 원래의 전체 코드는 C#으로 작성되어 있음.
https://gist.github.com/NeuroWhAI/08b548e7fe3e95f0046d50ea427b3c5c