Skip to content

Instantly share code, notes, and snippets.

@marsam
Created July 17, 2012 05:30
Show Gist options
  • Select an option

  • Save marsam/3127409 to your computer and use it in GitHub Desktop.

Select an option

Save marsam/3127409 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Sismos
======
Ultimos sismos reportados por el `Instituto Geofísico del Perú
<http://www.igp.gob.pe/sismologia/sismo/IGPSIS/sismos_reportados.htm>`_
DEPRECADO: El IGP ya no actualiza su página web
"""
import csv
from ast import literal_eval
from lxml.html import parse
def get_sismos():
url = 'http://www.igp.gob.pe/sismologia/sismo/IGPSIS/sismos_reportados.htm'
root = parse(url).getroot()
sismos = [clean_info(m.get('onmouseover')) for m in root.xpath("//area")]
return sismos
def clean_info(word):
"""
>>> clean_info("popup('14-08-2011','05:06:14','-71.96','-13.48',' 10 km','3.7 Richter')")
('14-08-2011', '05:06:14', '-71.96', '-13.48', ' 10 km', '3.7 Richter')
"""
return literal_eval(word.replace('popup', ''))
def main():
sismos = get_sismos()
with open('sismos.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerow(['fecha', 'hora', 'latitud', 'longitud', 'profundidad', 'magnitud'])
writer.writerows(sismos)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment