1 #!/usr/bin/env python
\r
2 # -*- coding: utf-8 -*-
\r
4 otptools base module - retain session/login info
\r
7 OTP_LOGIN_URL = "http://slashdot.jp/login.pl"
\r
8 OTP_LOGIN_HOST = "slashdot.jp"
\r
9 OTP_LOGIN_PATH = "/login.pl"
\r
14 "returnto":"http://slashdot.jp",
\r
20 OTP_LIST_PATH = "/admin.pl"
\r
22 BROWSER = "Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729) "
\r
27 import urllib, urllib2
\r
30 class otptools(object):
\r
32 Open Tech Press management library core module.
\r
35 def __init__(self, path_cookie, login_name="", login_password=""):
\r
37 @param path_cookie: path of file which cookie's information stored.
\r
38 @type path_cookie: stinrg
\r
40 @param login_name: OTP's login name for use.
\r
41 @type login_name: string
\r
43 @param login_password: OTP's login password.
\r
44 @type login_password: string
\r
46 self.path_cookie = path_cookie
\r
47 self.unickname = login_name
\r
48 self.upasswd = login_password
\r
55 login_param = copy.deepcopy(OTP_LOGIN_PARAM)
\r
56 login_param["unickname"] = self.unickname
\r
57 login_param["upasswd"] = self.upasswd
\r
59 for item in login_param:
\r
60 print "%s > %s" % (item, login_param[item])
\r
62 encoded_data = urllib.urlencode(login_param)
\r
66 "User-Agent": BROWSER,
\r
67 "Content-type": "application/x-www-form-urlencoded",
\r
68 "Accept": "text/plain",
\r
71 # obj = urllib.urlopen(OTP_LOGIN_URL, encoded_data)
\r
74 obj = httplib.HTTPConnection(OTP_LOGIN_HOST)
\r
75 obj.request("POST", OTP_LOGIN_PATH, encoded_data, headers)
\r
76 resp = obj.getresponse()
\r
77 headers = resp.getheaders()
\r
79 for item in headers:
\r
82 # for header in headers:
\r
83 # if header[0] == "set-cookie":
\r
84 # str_cookie = header[1]
\r
89 # self.cookie = str_cookie
\r
92 def save_cookie(self):
\r
93 file_obj = open(self.path_cookie, "w")
\r
94 file_obj.write(self.cookie)
\r
97 def load_cookie(self):
\r
99 load session cookie from file.
\r
101 file_obj = open(self.path_cookie, "r")
\r
102 self.cookie = file_obj.readline()
\r
105 def get_list(self):
\r
107 Access admin.pl and retrieve stories list.
\r
110 "User-Agent": BROWSER,
\r
111 "Content-type": "application/x-www-form-urlencoded",
\r
112 "Accept": "text/plain",
\r
113 "Cookie": self.cookie,
\r
115 obj = httplib.HTTPConnection(OTP_LOGIN_HOST)
\r
116 obj.request("POST", OTP_LIST_PATH, "", headers)
\r
117 resp = obj.getresponse()
\r
118 headers = resp.getheaders()
\r