forked from shibing624/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_user_info.py
More file actions
32 lines (26 loc) · 863 Bytes
/
add_user_info.py
File metadata and controls
32 lines (26 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
# Author: XuMing <[email protected]>
# Data: 17/8/30
# Brief:
import sys
path_user_cdc_client = sys.argv[1]
path_file = sys.argv[2]
path_output = sys.argv[3]
userid_map = {}
with open(path_user_cdc_client, "r")as f:
for line in f:
userid = line.strip().split("\t")[0]
userid = userid.decode("gb18030")
userid_map[userid] = line.strip().decode("gb18030")
content = set()
with open(path_file, "r") as f:
for line in f:
# parts = (line.strip()).decode("utf-8").split("\t")
# userid = parts[0]
userid = (line.strip()).decode("utf8")
if userid in userid_map:
content.add((line.strip()).decode("utf-8") + "\t" + userid_map[userid])
with open(path_output, "w") as f:
for line in content:
f.write((line.strip()).encode("utf-8"))
f.write("\n")