Created
March 11, 2011 22:28
-
-
Save ohe/866693 to your computer and use it in GitHub Desktop.
EarthQuake in Japan ...
This file contains hidden or 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
| """ | |
| Dirty Scraping Around USGS website to be informed of japan quake replica. | |
| """ | |
| from BeautifulSoup import BeautifulSoup | |
| from urllib import urlopen | |
| from time import sleep | |
| def get_usgs_info(): | |
| return BeautifulSoup(urlopen("http://earthquake.usgs.gov/earthquakes/recenteqsww/Maps/region/Asia_eqs.php")) | |
| QUAKES = [] | |
| while True: | |
| try: | |
| soup = [BeautifulSoup(str(e)).findAll("td", nowrap="nowrap") for e in get_usgs_info().findAll("tr")] | |
| quakes = [[a.getText() for a in e] for e in soup] | |
| quakes.reverse() | |
| for q in quakes: | |
| q = [e.replace(" ", "") for e in q] | |
| if len(q) > 5: | |
| l1 = q.pop(3).strip() | |
| l2 = q.pop(3).strip() | |
| q.append("http://maps.google.fr/maps?geocode=&q=%s+%s"%(l1, l2)) | |
| q.pop(0) | |
| q[1] = u"Date:" + q[1][0:10] + u" " + q[1][11:] | |
| q[0] = u"Mag:" + q[0] | |
| q.pop(2) | |
| if q not in QUAKES : | |
| print "--> ", " | ".join(q) | |
| QUAKES.append(q) | |
| print "No More Earthquakes \o/ .. New check in 1 minute!" | |
| sleep(60); | |
| except KeyboardInterrupt: | |
| with open("/tmp/quakes.txt", "w") as _f: | |
| for elem in QUAKES: | |
| _f.write(" | ".join(elem) + '\n') | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment