-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathearthquake.py
51 lines (46 loc) · 1.67 KB
/
earthquake.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/python
# -*- coding: utf-8 -*-
'''Earthquake class which can save the basic information of an earthquake'''
__author__ = 'Junwei Deng'
import csv,re
class Earthquake():
def __init__(self):
self.date=['1970','01','01']
self.time_zero=['00','00','30']
self.magnitude=0
self.depth=0
self.epi=[0,0]#long,lati
self.place=''
def initfrom(self,filename,linenum):
with open(filename) as f:
reader=csv.reader(f)
rows=[row for row in reader]
row=rows[linenum]
m=re.match(r'(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})',row[0])
if m:
self.date=[m[1],m[2],m[3]]
self.magnitude=float(row[4])
self.depth=row[3]
self.epi=[float(row[2]),float(row[1])]
self.time_zero=[m[4],m[5],m[6]]
self.place=row[13]
#print(self.time_zero)
else:
pass
def printall(self,filename):
with open(filename) as f:
reader=csv.reader(f)
a=1
for row in reader:
m=re.match(r'(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})',row[0])
if m:
if a<10:
print(a,' :',"On",m[1],m[2],m[3],"at",m[4],':',m[5],":",m[6],"in",row[13])
a=a+1
else:
print(a,':',"On",m[1],m[2],m[3],"at",m[4],':',m[5],":",m[6],"in",row[13])
a=a+1
else:
pass
#earthquake=Earthquake()
#earthquake.initfrom('./cache/earthquake.csv',1)