-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw2csv.py
56 lines (50 loc) · 1.92 KB
/
raw2csv.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
52
53
54
55
56
#================================================================================
#
# Reading copy-paste results from pawn shop search and create a csv file
#
#================================================================================
def createPawnshopcsv(rawfilename):
'''
Reads rawfilename and create a clean csv file
WARNING: some are missing because the adresses are incomplete...
'''
csvfname = 'pawnmtl.csv'
fcsv = open(csvfname, 'w')
fcsv.write('streetnum,streetname,city,province,postalcode\n' )
fraw = open(rawfilename)
for iline in fraw.readlines():
isplit = iline.split(',')
if len(isplit)!=4:
continue
#print iline
istrnum, istrname, icity, irest = isplit
irestsplit = irest.split()
iprov = irestsplit[0]
ipostal = irestsplit[1] + irestsplit[2]
fcsv.write('{},{},{},{},{}\n'.format(istrnum, istrname, icity, iprov, ipostal) )
#fcsv.write(iline)
print '\n\n Done creating csv file {}\n'.format(csvfname)
def createBankcsv(rawfilename):
'''
Reads rawfilename and create a clean csv file
WARNING: some are missing because the adresses are incomplete...
'''
csvfname = 'banksmtl.csv'
fcsv = open(csvfname, 'w')
fcsv.write('streetnum,streetname,city,province,postalcode\n' )
fraw = open(rawfilename)
for iline in fraw.readlines():
isplit = iline.split(',')
if len(isplit)!=4:
continue
#print iline
istrnum, istrname, icity, irest = isplit
irestsplit = irest.split()
iprov = irestsplit[0]
ipostal = irestsplit[1] + irestsplit[2]
fcsv.write('{},{},{},{},{}\n'.format(istrnum, istrname, icity, iprov, ipostal) )
#fcsv.write(iline)
print '\n\n Done creating csv file {}\n'.format(csvfname)
if __name__=='__main__':
#createPawnshopcsv('pawnmtl.txt')
createBankcsv('banksraw.txt')