From: hylom Date: Mon, 6 Apr 2009 10:01:03 +0000 (+0900) Subject: change argument of merge_csv and retrive_storylist, and use cp932 as output encoding. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=72e19abed57360ef47d1127d805877d1dbf64b52;p=otptools%2Fotptools.git change argument of merge_csv and retrive_storylist, and use cp932 as output encoding. --- diff --git a/merge_csv.py b/merge_csv.py index b4afb9d..1065928 100755 --- a/merge_csv.py +++ b/merge_csv.py @@ -5,15 +5,19 @@ import os, sys 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] + " ") + sys.exit(sys.argv[0] + " ") -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 = [] @@ -27,7 +31,7 @@ for row in ga_file: # 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: @@ -47,7 +51,9 @@ 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() diff --git a/retrive_storylist.py b/retrive_storylist.py index f7b4e77..3768ebb 100755 --- a/retrive_storylist.py +++ b/retrive_storylist.py @@ -8,17 +8,21 @@ import codecs sys.stdout = codecs.getwriter('utf_8')(sys.stdout) +usage = sys.argv[0] + " start end " +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 = "" @@ -66,6 +70,7 @@ for url in sort_keys: 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" )