maintaince tools for sfjp magazine
Revision | a29d230f341c57d8c633d59860f696654c24a854 (tree) |
---|---|
Time | 2016-11-01 18:25:16 |
Author | hylom <hylom@hylo...> |
Commiter | hylom |
Merge branch 'master' of https://pf.osdn.jp/gitroot/h/hy/hylom/sfjpmag2ools
Conflicts:
sfjpmagclient/sfjpmagclient.py
@@ -42,9 +42,12 @@ class CookieTransport(xmlrpclib.SafeTransport): | ||
42 | 42 | return self.parse_response(response) |
43 | 43 | |
44 | 44 | class MagClient(object): |
45 | - def __init__(self, username, password, auth_user="", auth_pass=""): | |
45 | + def __init__(self, username, password, auth_user="", auth_pass="", endpoint=None): | |
46 | 46 | self.username = username |
47 | 47 | self.password = password |
48 | + if endpoint == None: | |
49 | + endpoint = HOST_PATH | |
50 | + | |
48 | 51 | if auth_user and auth_pass: |
49 | 52 | # self.uri = "http://{username}:{password}@{url}".format(username=auth_user, password=auth_pass, url=HOST_PATH) |
50 | 53 | self.uri = "https://%s:%s@%s" % (auth_user, auth_pass, HOST_PATH) |
@@ -80,6 +83,23 @@ class MagClient(object): | ||
80 | 83 | self.password, |
81 | 84 | content) |
82 | 85 | |
86 | + def upload_media(self, filename, data, mimetype, overwrite=True, parent=None): | |
87 | + proxy = self._get_proxy() | |
88 | + post_data = { | |
89 | + "name": filename, | |
90 | + "type": mimetype, | |
91 | + "bits": xmlrpclib.Binary(data), | |
92 | + "overwrite": overwrite | |
93 | + } | |
94 | + | |
95 | + if parent != None: | |
96 | + post_data["post_id"] = parent | |
97 | + | |
98 | + return proxy.wp.uploadFile(self._get_blog_id(), | |
99 | + self.username, | |
100 | + self.password, | |
101 | + post_data) | |
102 | + | |
83 | 103 | def get_users_blogs(self): |
84 | 104 | proxy = self._get_proxy() |
85 | 105 | return proxy.wp.getUsersBlogs(self.username, self.password) |
@@ -9,10 +9,11 @@ from sfjpmagclient import MagClient | ||
9 | 9 | |
10 | 10 | username = config["username"] |
11 | 11 | password = config["password"] |
12 | -auth_user = config["auth_user"] | |
13 | -auth_pass = config["auth_pass"] | |
12 | +auth_user = config.get("auth_user", "") | |
13 | +auth_pass = config.get("auth_pass", "") | |
14 | +endpoint = config["endpoint"] | |
14 | 15 | |
15 | -c = MagClient(username, password, auth_user, auth_pass) | |
16 | +c = MagClient(username, password, auth_user, auth_pass, endpoint) | |
16 | 17 | ret = c.get_users_blogs() |
17 | 18 | print ret |
18 | 19 |
@@ -0,0 +1,36 @@ | ||
1 | +#!/usr/bin/python | |
2 | +# -*- coding: utf-8 -*- | |
3 | + | |
4 | +import json | |
5 | +import sys | |
6 | +import xmlrpclib | |
7 | +sys.path.append('.') | |
8 | + | |
9 | +from testconfig import config | |
10 | +from sfjpmagclient import MagClient | |
11 | + | |
12 | +username = config["username"] | |
13 | +password = config["password"] | |
14 | +auth_user = config.get("auth_user", "") | |
15 | +auth_pass = config.get("auth_pass", "") | |
16 | +endpoint = config["endpoint"] | |
17 | + | |
18 | +POST_ID = 1 | |
19 | +TEST_FILE = "test/sample.png" | |
20 | + | |
21 | +c = MagClient(username, password, auth_user, auth_pass, endpoint) | |
22 | + | |
23 | +f = open(TEST_FILE, "r") | |
24 | +test_data = f.read() | |
25 | +f.close() | |
26 | + | |
27 | +try: | |
28 | + ret = c.upload_media("This_is_test.png", test_data, "image/png", | |
29 | + True, 1) | |
30 | +except xmlrpclib.Fault, e: | |
31 | + for k in e.__dict__: | |
32 | + print k, e.__getattribute__(k) | |
33 | + sys.exit(-1) | |
34 | +print ret | |
35 | + | |
36 | + |