• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

maintaince tools for sfjp magazine


Commit MetaInfo

修订版9579b9d6420c0773156393efa4116d1de6958c4c (tree)
时间2016-11-01 18:20:38
作者hylom <hylom@hylo...>
Commiterhylom

Log Message

support new osdn magazine

更改概述

差异

--- a/sfjpmagclient/sfjpmagclient.py
+++ b/sfjpmagclient/sfjpmagclient.py
@@ -3,8 +3,43 @@
33
44 import xmlrpclib
55 import sys
6+import ssl
67
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)
843
944 class MagClient(object):
1045 def __init__(self, username, password, auth_user="", auth_pass=""):
@@ -12,9 +47,9 @@ class MagClient(object):
1247 self.password = password
1348 if auth_user and auth_pass:
1449 # 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)
1651 else:
17- self.uri = "http://" + HOST_PATH
52+ self.uri = "https://" + HOST_PATH
1853
1954 def _get_blog_id(self):
2055 try:
@@ -25,7 +60,10 @@ class MagClient(object):
2560 return self._blog_id
2661
2762 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)
2967
3068 def get_user(self, user_id, fields=[]):
3169 proxy = self._get_proxy()
@@ -49,7 +87,8 @@ class MagClient(object):
4987 def get_posts(self, filter={}):
5088 proxy = self._get_proxy()
5189 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,
5392 self.username,
5493 self.password,
5594 filter)