Created
June 3, 2016 12:52
-
-
Save campos-rafael/2376aea7b412924822e3fb9725def4b3 to your computer and use it in GitHub Desktop.
Create a 4-digit hash code for each guest loaded from a CSV file
This file contains hidden or 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
import csv | |
import base64 | |
import hashlib | |
f = open('guests.csv', "r", encoding='utf-8', errors='ignore') | |
csv_f = csv.reader(f) | |
for row in csv_f: | |
s = '' | |
for element in row: | |
s += element | |
coded_s = s.encode(encoding='utf-8') | |
mrHash = hashlib.sha1(coded_s) | |
code = base64.urlsafe_b64encode(mrHash.digest()[0:3]) | |
final_code = code.decode('utf-8') | |
final_code = final_code.replace('_', 'x') | |
final_code = final_code.replace('-', 'z') | |
print(final_code.upper()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment