Skip to content

Instantly share code, notes, and snippets.

@jehutymax
Created June 3, 2016 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jehutymax/2376aea7b412924822e3fb9725def4b3 to your computer and use it in GitHub Desktop.
Save jehutymax/2376aea7b412924822e3fb9725def4b3 to your computer and use it in GitHub Desktop.
Create a 4-digit hash code for each guest loaded from a CSV file
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