2 # -*- coding: utf-8 -*-
7 sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
8 sys.stderr = codecs.getwriter('cp932')(sys.stderr)
10 output_codec = "cp932"
13 ga_data_path = sys.argv[1]
14 otp_data_path = sys.argv[2]
15 output_path = sys.argv[3]
17 sys.exit(sys.argv[0] + " <ga file> <otp file> <output_file>")
19 ga_file = codecs.open(ga_data_path, "r", input_codec)
20 output_file = codecs.open(output_path, "w", output_codec)
25 #Page Title,Pageviews,Unique Pageviews,Avg. Time on Page,Bounce Rate,% Exit,$ Index
27 items = row.strip().split( "," )
29 ga_dict[title] = items
30 ga_titles.append(title)
34 otp_file = codecs.open(otp_data_path, "r", input_codec)
39 #url,title,editor,PVs,comments,date,tags
40 items = row.strip().split( "," )
42 for ga_title in ga_titles:
43 if ga_title.find( items[1] ) != -1:
44 ga_info = ga_dict.pop(ga_title)
45 ga_info.append( items[5] )
46 ga_info.append( items[6] )
47 updated_dict[ga_title] = ga_info
50 sys.stderr.write( "! %s - %s\n" % (items[1],items[5]) )
53 for title in updated_dict:
54 print >> output_file, title, ",", ",".join( updated_dict[title] )
57 print >> output_file, title, ",", ",".join( ga_dict[title] )