Press "Enter" to skip to content

Month: July 2019

WordPress post from xmlrpc

从Wordpress 3.5版本开始, xmlrpc默认开启, 更早期的版本可能在设置中手动开启. 以下是一个通过xmlrpc发布文章的脚本(python版本):

vim post.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

import datetime, xmlrpclib

wp_url = "http://www.example.net/xmlrpc.php"
wp_username = "USER"
wp_password = "passwd"
wp_blogid = ""
status_draft = 0
status_published = 1

server = xmlrpclib.ServerProxy(wp_url)

title = "article title"
content = "article content"
#date_created = xmlrpclib.DateTime(datetime.datetime.strptime("2011-10-20 21:08", "%Y-%m-%d %H:%M"))
categories = ["Beijing"]
tags = ["sometag", "othertag"]
data = {'title': title, 'description': content, 'categories': categories, 'mt_keywords': tags}

post_id = server.metaWeblog.newPost(wp_blogid, wp_username, wp_password, data, status_published)

请注意: 如果脚本里的categories不存在, 则会把文章post到默认分为中.

3 Comments

systemd service log check

systemd服务一般使用systemctl命令来启动, 那么如果服务启动不正常, 如何查看它的日志呢?

journalctl -u myapp.service

如果想查看实时日志输出( follow logs in real time ), 可以加一个-f参数:

journalctl -u -f myapp.service

另外2个有用的参数:

-e          直接打印到日志末尾;
--no-pager  打印全部日志(无需再翻页).

其实systemctl也是可以直接查看日志的:

systemctl -l status myapp.service
1 Comment