Last active
May 28, 2018 09:34
-
-
Save perforb/45c72ad43aa8ca5987bcacbbbde1c13e to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import csv | |
def make_dictionary(source_path): | |
with open(source_path, encoding='utf-8') as fh: | |
tuples = [] | |
for line in fh: | |
tuples.append(line.strip().split('\t')) | |
return dict(tuples) | |
def combine(fin_path, fout_path, code_dict): | |
with open(fin_path, encoding='utf-8') as fin, \ | |
open(fout_path, mode='wt', encoding='utf-8', newline='') as fout: | |
cin = csv.DictReader(fin, fieldnames=['UID', 'COIN', 'FREE_COIN']) | |
cout = csv.DictWriter(fout, ['CODE', 'UID', 'COIN', 'FREE_COIN']) | |
cout.writeheader() | |
for row in cin: | |
row['CODE'] = code_dict[row['UID']] | |
cout.writerow(row) | |
def main(): | |
code_dict = make_dictionary('uid_map.txt') | |
combine('source.csv', 'result.csv', code_dict) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment