import codecs
sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
-sys.stderr = codecs.getwriter('utf_8')(sys.stderr)
+sys.stderr = codecs.getwriter('cp932')(sys.stderr)
+input_codec = "cp932"
+output_codec = "cp932"
try:
ga_data_path = sys.argv[1]
otp_data_path = sys.argv[2]
+ output_path = sys.argv[3]
except IndexError:
- sys.exit(sys.argv[0] + " <ga file> <otp file>")
+ sys.exit(sys.argv[0] + " <ga file> <otp file> <output_file>")
-ga_file = codecs.open(ga_data_path, "r", "utf_8")
+ga_file = codecs.open(ga_data_path, "r", input_codec)
+output_file = codecs.open(output_path, "w", output_codec)
ga_dict = {}
ga_titles = []
# print title
ga_file.close()
-otp_file = codecs.open(otp_data_path, "r", "utf_8")
+otp_file = codecs.open(otp_data_path, "r", input_codec)
updated_dict = {}
ga_notfounds = []
for row in otp_file:
otp_file.close()
for title in updated_dict:
- print title, ",", ",".join( updated_dict[title] )
+ print >> output_file, title, ",", ",".join( updated_dict[title] )
for title in ga_dict:
- print title, ",", ",".join( ga_dict[title] )
+ print >> output_file, title, ",", ",".join( ga_dict[title] )
+
+output_file.close()
sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
+usage = sys.argv[0] + " start end <output_file>"
+output_encoding = "utf_8"
+output_encoding = "cp932"
try:
start = sys.argv[1]
end = sys.argv[2]
+ file = sys.argv[3]
except IndexError:
uname = ""
- sys.exit(sys.argv[0] + " start end")
+ sys.exit(usage)
if (not start.isdigit()) or (not start.isdigit()):
- sys.exit(sys.argv[0] + " start end")
-
+ sys.exit(usage)
+output_file = codecs.open(file, "w", output_encoding)
uname = ""
for url in sort_keys:
for item in story_infos[url]:
str =story_infos[url][item]
- print "%(url)s,%(title)s,%(editor)s,%(page_views)s,%(comments)s,%(datetime)s,%(tags)s" % story_infos[url]
+ output_file.write("%(url)s,%(title)s,%(editor)s,%(page_views)s,%(comments)s,%(datetime)s,%(tags)s" % story_infos[url] + "\n")
+output_file.close()
sys.stderr.write( "done.\n" )