-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac_nolink.py
163 lines (106 loc) · 4.29 KB
/
ac_nolink.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: cp1251 -*-
# Ñêðèïò ïðîâåðêè àêòèâíûõ êàðò íà ïðåäìåò èõ âêëþ÷åíèÿ â r1
#0-OK (èëè OK-2 êîäà ïðèñâàåâàåòñÿ âòîðàÿ äåéñòâóþùàÿ êàðòà)+
#1-Íîìåð ïðèñâîåí êàðòó íåîáõîäèìî çàáëîêèðîâàòü+
#2-íîìåð êàðòû áûë ïðèñâîåí ðàíåå+
#3-ñîøëîñü ïî ÑÍÈËÑ íå ñîøëîñü ïî ÔÈÎ+äð-
#4-ñîøëîñü ïî ÔÈÎ+äð íå ñîøëîñü ïî ÑÍÈËÑ-
#5-Ëè÷íîå äåëî íå èäåíòèôèöèðîâàíî-
#6-Ïåðåâûïóñê êàðòû (ïðèñâîåí íîâûé íîìåð ñ äàòû âûäà÷è)+
# USAGE: ac_nolink.py [card_num]
import subprocess as sp
import fnmatch
import os
import sys
if len(sys.argv)==2:
ac_ls =[]
ac_ls.append(sys.argv[1])
mode = 'single'
else:
mode = 'list'
#ac_file=open('C:\\Share_transport\\autoscript\\ac.csv')
ac_file=open('C:\\Share_transport\\autoscript\\from_r4.csv')
#ac_file=open('C:\\Share_transport\\autoscript\\usedcard_.csv')
#ac_file=open('ac.csv')
#ac_text=ac_file.read()
#ac_ls=ac_text.split('\n')
ac_ls=[num.rstrip() for num in ac_file]
print (len(ac_ls))
#del ac_ls[ac_ls.index('')]
print (len(ac_ls))
SL = {}.fromkeys(ac_ls,[('-2','UnKnown','UnKnown')])#ñòðóêòóðà äàííûõ äëÿ èñòîðèè ñòàòóñîâ êàðòû
#print ('New SL:', SL)
#2. buld SET of linked cards
#lc_root_folder=r"/home/max_siz/Documents/LINK/YAD/MINSOC/R1"
lc_root_folder=r"C:\Share_transport\LINK\MINSOC\R1"
tree = os.walk(lc_root_folder) #äåðåâî ïàïîê è ôàéëîâ â îáúåêòå-ãåíåðàòîðå
for d in tree:
for f in d[2]:
#if fnmatch.fnmatch(f, 'Ans_r1_*.csv'): #ôèëüòð ôàéëîâ ïî ìàñêå - r1
if fnmatch.fnmatch(f, '*r1_*.csv'): #ôèëüòð ôàéëîâ ïî ìàñêå - r1
cur_file=open(os.path.join(d[0],f),'rb') #îòêðûâàåì îòîáðàíûé ôàéë
j = 0
k = 0
print (f, end='')
#cur_file_ls = [curr_str.decode('cp1251').rstrip() for curr_str in cur_file]
for curr_str in cur_file:
cur_str_ls = curr_str.decode('cp1251').rstrip().split(';') #öèêë ïî êàæäîé ñòðîêå
j +=1
#print(cur_str_ls, cur_str_ls[0])
#if cur_str_ls[0] in SL:
if f.upper()[:3]=='ANS' and cur_str_ls[0] in SL:
cur_str_ls.append(f)
#cur_str_ls.append(f.split('_')[3])
#cur_str_ls.extend([f,f.split('_')[3]])
#print (' for add:',tuple(cur_str_ls), ', SL[n before]:',SL[cur_str_ls[0]], ' SL full before',SL)
if SL[cur_str_ls[0]] == [('-2','UnKnown','UnKnown')]:
SL[cur_str_ls[0]] = list()
SL[cur_str_ls[0]].append(tuple(cur_str_ls[1:]))
else:
SL[cur_str_ls[0]].append(tuple(cur_str_ls[1:]))
#print (' SL[new]:',SL[cur_str_ls[0]])
#print ('SL full ',SL)
k +=1
if f.upper()[:3]=='R1_' and cur_str_ls[5] in SL:
#print (cur_str_ls,f)
cur_str_ls.append(f)
cur_str_ls = cur_str_ls[5:]
if SL[cur_str_ls[0]] == [('-2','UnKnown','UnKnown')]:
SL[cur_str_ls[0]] = list()
SL[cur_str_ls[0]].append(tuple(cur_str_ls))
else:
SL[cur_str_ls[0]].append(tuple(cur_str_ls))
k +=1
print ('..... îáðàáîòàíî ', str(j), ', äîáàâëåíî â ñëîâàðü: ', str(k))
#logfile = open('log_nolink.txt','w')
print ('Àíàëèç êàðò: ',len(SL))
#if len(SL) < 100: print(SL)
#âòîðîé ïðîõîä - ïîèñê íåçàâåðøåííûõ
i = 0
unlink = []
for cur_num_str in SL:#öèêë ïî êëþ÷àì ñëîâàðÿ
#print (cur_num_str)
for state_str in SL[cur_num_str]:
if mode =='single':
print (state_str)
else:
if int(state_str[0]) in [0,1,2,6]:#ïîäòâåðæäåí
#SL.pop(cur_num_str)
#print (cur_num_str, state_str[2])
break
else:
i +=1
unlink.append(cur_num_str+'\n')
#print (cur_num_str)
#print ('......... ', state_str)
unlink.sort()
#print(unlink)
if mode != 'single':
print ('Íåïîäòâåðæäåííûõ êàðò (unlinked.csv): ',str(i))
logfile = open('unlinked.csv','w')
logfile.writelines( unlink)
else:
logfile = open('unlinked.csv','w')
for state_str in SL[cur_num_str]:
logfile.write(str(state_str)+'\n')
#if len(SL) < 100: print(SL)