-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathGetSiteCode950.py
41 lines (32 loc) · 1012 Bytes
/
GetSiteCode950.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
# -*- coding: utf-8 -*-
#透過分公司進出表,取得分公司對照表
import os
import csv
import re
import pandas as pd
from pandas import Series, DataFrame
if __name__ == '__main__' :
siteDict = {}
for dirPath, dirNames, fileNames in os.walk('BSR'):
for f in fileNames:
if f[0] == '.':
continue
else:
fullfile = os.path.join(dirPath, f)
#print fullfile
with open(fullfile, 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='|')
#print spamreader
for row in spamreader:
lstSite = row[1].split()
if re.findall('^[\d{4}]',lstSite[0]):
if siteDict.has_key(lstSite[0]):
pass
else:
siteDict[lstSite[0]] = row[1][4:].rstrip().lstrip()
lstSite = [ [k,v] for k,v in siteDict.items() ]
lstSite = sorted(lstSite,key = lambda x : x[0])
#output csv wiht big5 encoding for excel
with open('SiteCode.csv','wb') as siteCsvFile:
csvWriter = csv.writer(siteCsvFile)
csvWriter.writerows(lstSite)