-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathblogpost.py
44 lines (35 loc) · 1.24 KB
/
blogpost.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 26 10:36:16 2016
@author: ngreeney
"""
#pip install python_wordpress_xmlrpc
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
#from wordpress_xmlrpc.methods.users import GetUserInfo
from wordpress_xmlrpc.methods import media
from wordpress_xmlrpc.compat import xmlrpc_client
class BlogPost:
def __init__(self,user,password):
self.wp = Client("http://dataslant.xyz/xmlrpc.php",user,password)
def postDraft(self, title, body):
'''
Creates a draft with title and graph
Currently both title and graph are just strings
'''
post = WordPressPost()
post.title = title
post.content = body
# post,terms_names = {
# 'post_tag': ['test'],
# 'category': ['testCat']}
self.wp.call(NewPost(post))
def uploadJPG(self, filePath):
data = {
'name': filePath.split('/')[-1],
'type': 'image/jpeg',
}
with open(filePath, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = self.wp.call(media.UploadFile(data))
return response['id']