import hashlib import csv import io import datetime import time import sys import os DEFINED_EXAMPLE_HASH = '264e53d93759bde067fd01ef2698f98d1253c730d12f021116f02eebcfa9ace6' TODAY = datetime.datetime.today() def hash_string_256(string): new_hash = hashlib.sha256(string) hashed_version = new_hash.hexdigest() return hashed_version def scrub(string): return string.strip().lower() def main(): BUF_SIZE = 96000*1024 #a little below 100 MB to avoid just meeting the 100MB limit user_file_name = raw_input('Enter the csv file name: ') csv_file = csv.reader(open(user_file_name, 'rU')) cur_time = time.strftime("%Y%m%d-%H%M%S") filenum = 0 new_file_name = 'hashed_output_' + str(filenum) + '_' + cur_time + '.csv' new_csv = open(new_file_name, 'w') for line in csv_file: email = line[0] scrubbed_email = scrub(email) current_email_hashed = hash_string_256(scrubbed_email) new_csv.write(current_email_hashed + '\n') new_csv.flush() if os.stat(new_file_name).st_size >= BUF_SIZE: new_csv.close() print 'Finished writing to \"' + new_file_name + '\"' filenum += 1 new_file_name = 'hashed_output_' + str(filenum) + '_' + cur_time + '.csv' new_csv = open(new_file_name, 'w') pass new_csv.close() print 'Finished writing to \"' + new_file_name + '\"' pass if __name__ == '__main__': main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question