หน้าเว็บ USGS : http://earthquake.usgs.gov/
หน้า API ของ USGS : http://earthquake.usgs.gov/fdsnws/event/1/
บทความนี้ผมใช้โมดูล quakefeeds ในการช่วยดึงข้อมูล GeoJSON API จาก USGS (โมดูลนี้รองรับเฉพาะ Python 3 และใช้ License: MIT)
สามารถติดตั้งได้โดยใช้คำสั่ง pip :
pip3 install quakefeeds
การใช้งาน
โมดูลนี้สามารถรายงานแผ่นดินไหวในรูปแบบไฟล์ html โดยใช้ Google maps ได้
การดึงข้อมูล
QuakeFeed("ระดับความรุนแรง", "ช่วงที่เกิด")- ระดับความรุนแรง มีดังนี้ "significant", "4.5", "2.5", "1.0", "all
- ช่วงที่เกิด มีดังนี้ "hour", "day", "week", "month"
ที่เหลือสามารถศึกษาได้จากตัวอย่างการใช้งาน
ตัวอย่างการใช้งาน
>>> from quakefeeds import QuakeFeed
>>> feed = QuakeFeed("1.0", "day")
>>> feed.title
'USGS Magnitude 1.0+ Earthquakes, Past Day'
>>> feed.time # datetime.datetime(...)
>>> len(feed)
123
>>> feed[0]
{'properties': {'cdi': 1, 'tsunami': 0, 'alert': None, ...}
# full JSON data for first event in feed
>>> feed.location(0)
[26.8608, 35.135]
>>> feed.magnitude(0)
6.1
>>> feed.event_title(0)
'M 6.1 - 47km SW of Karpathos, Greece'
>>> feed.depth(0)
20.86
>>> feed.depths
>>> list(feed.depths)
[20.86, 46.35, 76.54, 48.69, 10, 28.64]
>>> map1 = feed.create_google_map()
>>> map2 = feed.create_google_map(style="titled")
>>> feed.write_google_map("map.html", style="titled")
ผลลัพธ์ไฟล์ map.html

หน้าหลักโมดูล quakefeeds : https://github.com/python33r/quakefeeds
ติดตามบทความต่อไปนะครับ
ขอบคุณครับ

0 ความคิดเห็น:
แสดงความคิดเห็น
แสดงความคิดเห็นได้ครับ :)