Created
October 3, 2012 00:03
-
-
Save pingswept/3824121 to your computer and use it in GitHub Desktop.
Conversion of badge IDs for Fastenal vending machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# fastenal_convert.py | |
# Copyright 2008 Brandon Stafford | |
# | |
# This file is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This file is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License along | |
# with this file. If not, see <http://www.gnu.org/licenses/>. | |
# Usage: | |
# python fastenal_convert.py /path/to/input | |
import datetime, sys | |
lines = open(sys.argv[1], 'r') | |
outname = 'asylum-badges-' + datetime.date.today().strftime('%Y-%m-%d') + '.csv' | |
outfile = open(outname, 'w') | |
linecount = 0 | |
for line in lines: | |
badge = int(bin(int(line.split(',')[-1], 16))[-17:-1], 2) | |
print(line.strip() + ',' + str(badge).zfill(5)) | |
outfile.write(line.strip() + ',' + str(badge).zfill(5) + '\n') | |
linecount += 1 | |
outfile.close() | |
print('\nWrote ' + str(linecount) + ' lines to ' + outname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment