forked from gpx0214/train-schedule-to-svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequip.py
95 lines (83 loc) · 2.14 KB
/
equip.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
# -*- coding: utf-8 -*-
from view_train_list import *
yyyymmdd = re.sub(
r'(\d\d)(\d\d)-(\d+)-(\d+)',
r"\1\2\3\4",
nowdate()
)
maxlen = 90000
train_map = [[] for i in range(maxlen)]
seq_map = [0 for i in range(maxlen)]
c = readcsv('js/train%s.csv'%(base_yymmdd()))
idx = 0
# for i in range(idx, len(c), 1):
for i in range(idx, len(c), 1):
if len(c[i]) < 5:
continue
if len(c[i]) < 7:
c[i].append('')
c[i].append('')
if c[i][3] not in c[i][0]: # 复车次查不到
idx = i
continue
if is_a_day(c[i][6], yyyymmdd):
train_map[hash_no(re.sub(r'^0+', '', c[i][0][5:-2]))-1].append(c[i])
#print(c[i][0])
rows = []
for key in range(40000, 80000): # range(len(train_map))
if key / 10 in [7060,7061,7090,7091]: # S6 S9
continue
if key / 100 in [507,508]: # D7xx D8xx
continue
if key / 1000 in [60]: # Cxxx
continue
if len(train_map[key]) == 0:
continue
for retry in range(3):
row, ret = getequip(train_map[key][0][0], yyyymmdd)
if ret >= 0:
break
rows.append(row)
'''
#local
import json
rows = []
for key in range(40000, 80000): # range(len(train_map))
if len(train_map[key]) == 0:
continue
no = train_map[key][0][0]
date = yyyymmdd
try:
j = json.loads(readbyte('equip/equip_' + date + '_' + no + '.json'))
ret = [
j['data'][0]['trainsetType'],
j['data'][0]['trainsetName'],
j['data'][0]['bureaName'],
j['data'][0]['deploydepotName'],
j['data'][0]['depotName'],
j['data'][0]['trainsetStatus'],
no,
j['data'][0]['date'],
str(j['data'][0]['eId']),
]
except:
print('equip %s no data' % (no))
ret = [
u'',
u'',
u'',
u'',
u'',
u'',
no,
u'',
u'',
]
rows.append(ret)
time.sleep(0.1)
'''
writecsv(
'emu/equip%s.csv' % (yyyymmdd),
[[x.encode('utf-8') for x in row] for row in rows]
)