formatting update
This commit is contained in:
parent
eb6d32bd50
commit
74d3d9b338
|
@ -22,18 +22,20 @@ First column of csv file must be card format (copy/paste one format, matching ca
|
|||
28 bit format
|
||||
48 bit format
|
||||
```
|
||||
Each row represents card in following order - facility code;card number
|
||||
Second column is facility code
|
||||
Third column is card number
|
||||
|
||||
Example of 2 cards in cards.csv file
|
||||
|
||||
```
|
||||
32 bit format;
|
||||
0;1234567
|
||||
0;9876543
|
||||
CardFormat;FacilityCode;CardNumber
|
||||
28 bit format;4;1476269
|
||||
32 bit format;4;1476270
|
||||
```
|
||||
|
||||
Output file will be formatted hex number; card number
|
||||
```
|
||||
96B43F;9876543
|
||||
12D687;1234567
|
||||
CardFormat;FacilityCode;CardNumber;CardDATA
|
||||
28 bit format;4;1476269;12D0D5A
|
||||
32 bit format;4;1476270;1686AE
|
||||
```
|
||||
|
|
|
@ -2,24 +2,34 @@ import csv
|
|||
|
||||
card_formats = context.get_card_formats()
|
||||
|
||||
class Card(object):
|
||||
def __init__(self, card_format, facility_code, card_number, card_data):
|
||||
self.card_format = card_format
|
||||
self.facility_code = facility_code
|
||||
self.card_number = card_number
|
||||
self.card_data = card_data
|
||||
|
||||
|
||||
def read_file():
|
||||
formatted_cards = {}
|
||||
formatted_cards = []
|
||||
with open("cards.csv", "r") as csvFile:
|
||||
reader = csv.reader(csvFile, delimiter=';')
|
||||
card_format_csv = next(reader)
|
||||
for card_f in card_formats:
|
||||
if card_f.name == card_format_csv[0]:
|
||||
card_format_id = card_f.id
|
||||
header = next(reader)
|
||||
for row in reader:
|
||||
card_data = context.format_card_number(card_format_id, str(row[1]), str(row[0]))
|
||||
formatted_cards.update({card_data: row[1]})
|
||||
for card_f in card_formats:
|
||||
if card_f.name == row[0]:
|
||||
card_format_id = card_f.id
|
||||
card_data = context.format_card_number(card_format_id, str(row[2]), str(row[1]))
|
||||
_card = Card(row[0], row[1], row[2], card_data)
|
||||
formatted_cards.append([_card.card_format, _card.facility_code, _card.card_number, _card.card_data])
|
||||
|
||||
write_file(formatted_cards)
|
||||
|
||||
def write_file(dict_data):
|
||||
def write_file(card_data):
|
||||
with open("formated_cards.csv", "wb") as csvFile:
|
||||
writer = csv.writer(csvFile, delimiter=';')
|
||||
print dict_data
|
||||
writer.writerows(dict_data.items())
|
||||
writer.writerow(["CardFormat", "FacilityCode","CardNumber", "CardDATA" ])
|
||||
writer.writerows(card_data)
|
||||
|
||||
|
||||
read_file()
|
Loading…
Reference in New Issue