Skip to content

Instantly share code, notes, and snippets.

@yatt
Created April 10, 2011 10:04
Show Gist options
  • Save yatt/912209 to your computer and use it in GitHub Desktop.
Save yatt/912209 to your computer and use it in GitHub Desktop.
東北大学の「福島第一原子力発電所事故に係る放射線モニタリング情報」http://www.bureau.tohoku.ac.jp/anzen/monitoring/から情報を取得します。
# coding: utf-8
import urllib
import decimal
import re
import time
from BeautifulSoup import BeautifulSoup as BS
class SievertPerHour(object):
def __init__(self, sv):
if isinstance(sv, decimal.Decimal):
self.sv = sv
else:
self.sv = decimal.Decimal(str(sv))
def asMicro(self):
return self.sv * 10**6
def asMilli(self):
return self.sv * 10**3
def __repr__(self):
return '<%s Sv/h>' % self.sv
class LatLng(object):
__slots__ = ['lati', 'long']
def __init__(self, lati, long):
self.lati = lati
self.long = long
class Info(object):
def __init__(self, svh, note, timeat, latlng, additional=None):
self.svh = svh
self.note = note
self.latlng = latlng
self.timeat = timeat
self.additional = additional
@classmethod
def listFromTohokuUniv(cls):
ENCODING = 'utf-8'
URL = 'http://www.bureau.tohoku.ac.jp/anzen/monitoring/'
PLACE = LatLng(38.26066, 140.841873) # http://bit.ly/gbOAog
# fetch html document from web
html = urllib.urlopen(URL).read()
unihtml = html.decode(ENCODING)
# and drop it into soup
soup = BS(unihtml)
lst = soup.findAll('h5')
infolist = []
for n in lst:
detail = n.nextSibling.nextSibling
s,u = unicode(detail.next.next.next.next).split()
m = {u'マイクロシーベルト/時間': 10**6,
u'ミリシーベルト/時間': 10**3,
u'シーベルト/時間': 1}
sph = SievertPerHour(float(s) / m[u])
note = unicode(detail.next.next.next.next.next.next.next.next.next)
lst = map(int, re.findall('\d+', n.contents[0]))
timeat = '%02d-%02d %02d:%02d' % (lst[0], lst[1], lst[-2], lst[-1])
additional = None
infolist.append(Info(sph, note, timeat, PLACE, additional))
return infolist
def main():
lst = Info.listFromTohokuUniv()
for n in lst:
print '%s uSv/h on %s, <<%s>>' % (n.svh.asMicro(), n.timeat, n.note)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment