maintaince tools for sfjp magazine
リビジョン | 9579b9d6420c0773156393efa4116d1de6958c4c (tree) |
---|---|
日時 | 2016-11-01 18:20:38 |
作者 | hylom <hylom@hylo...> |
コミッター | hylom |
support new osdn magazine
@@ -3,8 +3,43 @@ | ||
3 | 3 | |
4 | 4 | import xmlrpclib |
5 | 5 | import sys |
6 | +import ssl | |
6 | 7 | |
7 | -HOST_PATH = 'magazine-admin.sourceforge.jp/magazine/xmlrpc.php' | |
8 | +HOST_PATH = 'mag.osdn.jp/xmlrpc.php' | |
9 | +#HOST_PATH = 'osdn.jp/magazine/xmlrpc.php' | |
10 | + | |
11 | +import xmlrpclib | |
12 | + | |
13 | +class CookieTransport(xmlrpclib.SafeTransport): | |
14 | + cookies = [] | |
15 | + | |
16 | + def send_cookies(self, connection): | |
17 | + if self.cookies: | |
18 | + for cookie in self.cookies: | |
19 | + connection.putheader("Cookie", cookie) | |
20 | + | |
21 | + def request(self, host, handler, request_body, verbose=0): | |
22 | + self.verbose = verbose | |
23 | + h = self.make_connection(host) | |
24 | + | |
25 | + self.send_request(h, handler, request_body) | |
26 | + self.send_host(h, host) | |
27 | + self.send_cookies(h) | |
28 | + self.send_user_agent(h) | |
29 | + self.send_content(h, request_body) | |
30 | + | |
31 | + response = h.getresponse() | |
32 | + | |
33 | + print response.status | |
34 | + for hv in response.getheaders(): | |
35 | + print hv[0] + ": " + hv[1] | |
36 | + #print response.read() | |
37 | + for header in response.msg.getallmatchingheaders("Set-Cookie"): | |
38 | + val = header.split(": ", 1)[1] | |
39 | + cookie = val.split(";", 1)[0] | |
40 | + self.cookies.append(cookie) | |
41 | + | |
42 | + return self.parse_response(response) | |
8 | 43 | |
9 | 44 | class MagClient(object): |
10 | 45 | def __init__(self, username, password, auth_user="", auth_pass=""): |
@@ -12,9 +47,9 @@ class MagClient(object): | ||
12 | 47 | self.password = password |
13 | 48 | if auth_user and auth_pass: |
14 | 49 | # self.uri = "http://{username}:{password}@{url}".format(username=auth_user, password=auth_pass, url=HOST_PATH) |
15 | - self.uri = "http://%s:%s@%s" % (auth_user, auth_pass, HOST_PATH) | |
50 | + self.uri = "https://%s:%s@%s" % (auth_user, auth_pass, HOST_PATH) | |
16 | 51 | else: |
17 | - self.uri = "http://" + HOST_PATH | |
52 | + self.uri = "https://" + HOST_PATH | |
18 | 53 | |
19 | 54 | def _get_blog_id(self): |
20 | 55 | try: |
@@ -25,7 +60,10 @@ class MagClient(object): | ||
25 | 60 | return self._blog_id |
26 | 61 | |
27 | 62 | def _get_proxy(self): |
28 | - return xmlrpclib.ServerProxy(self.uri) | |
63 | + c = CookieTransport(); | |
64 | + #c.cookies.append("proxy_pass=1") | |
65 | + c.cookies.append("wordpress_logged_in=1") | |
66 | + return xmlrpclib.ServerProxy(self.uri, transport=c) | |
29 | 67 | |
30 | 68 | def get_user(self, user_id, fields=[]): |
31 | 69 | proxy = self._get_proxy() |
@@ -49,7 +87,8 @@ class MagClient(object): | ||
49 | 87 | def get_posts(self, filter={}): |
50 | 88 | proxy = self._get_proxy() |
51 | 89 | try: |
52 | - return proxy.wp.getPosts(self._get_blog_id(), | |
90 | + #return proxy.wp.getPosts(self._get_blog_id(), | |
91 | + return proxy.wp.getPosts(1, | |
53 | 92 | self.username, |
54 | 93 | self.password, |
55 | 94 | filter) |