2 # -*- coding: utf-8 -*-
9 sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
11 usage = sys.argv[0] + " start end <output_file>"
12 output_encoding = "utf_8"
13 output_encoding = "cp932"
22 if (not start.isdigit()) or (not start.isdigit()):
25 output_file = codecs.open(file, "w", output_encoding)
29 otp = otptools.otptools("./cookies.txt", uname)
33 sys.stderr.write("cannot use cookie file. create.\n")
35 if otp.get_cookie() == "":
38 uname = raw_input("user: ")
39 except KeyboardInterrupt:
42 passwd = getpass.getpass("login password:")
43 except KeyboardInterrupt:
45 if otp.login(uname, passwd) != 1:
46 sys.exit("login error!")
50 start_index = int(start)
53 sys.stderr.write( "retrieving lists..." )
55 for index in range(start_index, max_index, 40):
56 html = otp.get_list(index)
57 story_infos = otp.parse_list( html, story_infos )
59 sys.stderr.write( "sorting..." )
60 sort_keys = story_infos.keys()
61 sort_keys.sort(lambda x,y: cmp(story_infos[y], story_infos[x]))
63 sys.stderr.write( "retrieving tags..." )
65 tags = otp.get_tags( "http:" + url )
67 story_infos[url]["tags"] = unicode( "|".join(tags), "utf_8" )
71 for item in story_infos[url]:
72 str =story_infos[url][item]
73 output_file.write("%(url)s,%(title)s,%(editor)s,%(page_views)s,%(comments)s,%(datetime)s,%(tags)s" % story_infos[url] + "\n")
76 sys.stderr.write( "done.\n" )