-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_airline.py
36 lines (29 loc) · 1.01 KB
/
count_airline.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
# coding=utf-8
import os
file_direct = "/home/qings2329/airfareAnalyze/airlines/"
airline_dir = {}
for parent, dirnames, filenames in os.walk(file_direct):
for fn in filenames:
path = os.path.join(parent, fn)
file_handle = open(path, 'r')
lines = file_handle.readlines()
for ln in lines:
arr = ln.split(' ')
length = len(arr)
key = arr[length - 3] + ' ' + arr[length - 2] + ' ' + arr[length - 1][:2]
value = airline_dir.get(key)
if value:
value += int(arr[length - 4])
else:
value = int(arr[length - 4])
airline_dir[key] = value
file_name = "airline-list"
file_dir = "/home/qings2329/airfareAnalyze/airlines/" + file_name
file_handle = open(file_dir, 'w')
# rank_list = []
for key in airline_dir:
# rank_list.append(str(airline_dir.get(key)) + " " + key)
print >> file_handle, str(airline_dir.get(key)) + " " + key
# rank_list.sort()
# print rank_list
file_handle.close()