OSDN Git Service

change argument of merge_csv and retrive_storylist, and use cp932 as output encoding.
authorhylom <hylom@users.sourceforge.jp>
Mon, 6 Apr 2009 10:01:03 +0000 (19:01 +0900)
committerhylom <hylom@users.sourceforge.jp>
Mon, 6 Apr 2009 10:01:03 +0000 (19:01 +0900)
merge_csv.py
retrive_storylist.py

index b4afb9d..1065928 100755 (executable)
@@ -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] + " <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 = []
@@ -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()
index f7b4e77..3768ebb 100755 (executable)
@@ -8,17 +8,21 @@ import codecs
 
 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 = ""
 
@@ -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" )