-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_post_raw_insert.py
More file actions
75 lines (53 loc) · 1.96 KB
/
generate_post_raw_insert.py
File metadata and controls
75 lines (53 loc) · 1.96 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import socket
import sys
from termcolor import colored
from xml.parsers.expat import *
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc.exceptions import *
class wp_analysis(object):
source = None
target = None
def __init__(self, url='', username='', password = ''):
"""
:param config:
"""
self.wp = Client(url, username, password)
def error(self, _type, _error):
"""
WP Post Error
:param _type string
:param _error string
"""
print colored(str.format('{}: {}', _type, _error), 'red')
source = {
'url': 'http://192.168.33.33/xmlrpc.php',
'username': 'pbeltran',
'password': 'LBA8510*%!)LBA'
}
post_id = int(sys.argv[1])
if post_id == 0:
raise Exception('Expected post id.\n $python posts.py :id')
analytics = wp_analysis(source['url'], source['username'], source['password'])
try:
post = analytics.wp.call(posts.GetPost(post_id))
sql = "INSERT INTO `wp_posts`(`post_author`\n, `post_content`\n, `post_title`\n, `post_status`\n, `comment_status`\n,"
sql += " `ping_status`\n, `post_name`\n, `post_parent`\n, `guid`\n, `menu_order`\n, `post_type`)\n "
sql += " VALUES \n('{}'\n, '{}'\n, '{}'\n, '{}'\n, '{}'\n, '{}'\n, '{}'\n, '{}'\n, '{}'\n, '{}'\n, '{}'\n )"\
.format(
post.user, post.content, post.title, post.post_status,
post.comment_status, post.ping_status, post.title,
str(post.parent_id), post.guid, str(post.menu_order), str(post.post_type))
print(colored(sql, 'blue'))
except ExpatError as e:
# Invalid XML
analytics.error('XML Error', e)
except ServerConnectionError as e:
# Unexpected or invalid response
analytics.error('Server ERROR', e.message)
except socket.gaierror as e:
# Unreachable host
analytics.error('Server ERROR', e)
except AttributeError as e:
# Unreachable host
analytics.error('Attribute ERROR', e)