博园客的sublime插件-直接在sublime中发表博客( ST3 插件)

本文介绍了一个Sublime Text插件,该插件能够帮助用户快速将选定的内容发布为博客文章。通过简单的几步操作,即可完成从内容选择到发布的全过程。文章详细解释了如何配置插件设置文件,并提供了具体的使用步骤。

使用说明:

首先修改meetrice.sublime-settings中的配置

 

1.shift+f9 快速发布选中的内容

2.在弹出的对话框架填写"标题"

3.在弹出的对话框中填写"tag"

发布成功!

 

百度网盘下载

 

 

import os
import threading
from xmlrpc.client import ServerProxy, Error
import html.parser
from itertools import groupby
from operator import itemgetter
import xmlrpc.client
import urllib.request, urllib.parse, urllib.error

import sublime
import sublime_plugin


def status(msg, thread=False):
    if not thread:
        sublime.status_message(msg)
    else:
        sublime.set_timeout(lambda: status(msg), 0)


def handle_thread(thread, msg=None, cb=None, i=0, direction=1, width=8):
    if thread.is_alive():
        next = i + direction
        if next > width:
            direction = -1
        elif next < 0:
            direction = 1
        bar = [' '] * (width + 1)
        bar[i] = '='
        i += direction
        status('%s [%s]' % (msg, ''.join(bar)))
        sublime.set_timeout(lambda: handle_thread(thread, msg, cb, i,
                            direction, width), 100)
    else:
        cb()

def get_login_name():
    settings = sublime.load_settings('meetrice.sublime-settings')
    login_name = settings.get('login_name')

    if not login_name:
        sublime.error_message("No Login name found in settings")

    return login_name

def get_login_password():
    settings = sublime.load_settings('meetrice.sublime-settings')
    login_password = settings.get('login_password')

    if not login_password:
        sublime.error_message("No login_password found in settings")

    return login_password

def get_xml_rpc_url():
    settings = sublime.load_settings('meetrice.sublime-settings')
    xml_rpc_url = settings.get('xml_rpc_url')

    if not xml_rpc_url:
        sublime.error_message("No login_password found in settings")

    return xml_rpc_url

class NewPostCommand(sublime_plugin.TextCommand):

    def run(self, edit):

        self.login_name = get_login_name()
        print(self.login_name);
        self.login_password = get_login_password()
        self.url = get_xml_rpc_url()

        regions = self.view.sel()
        if not (len(regions) > 0) or (regions[0].empty()):
            status("发生错误: 没有选中要发表的内容!")
            return

        self.server = ServerProxy(self.url)

        self.post = {'title':'sublime默认标题',
                'description':self.view.substr(regions[0]),
                'link':'',
                'author':'meetrice@gmail.com',
                'mt_keywords':'测试标签',
                'category':''
            }

        self.title_prompt()

    def title_prompt(self):
        self.view.window().show_input_panel("请输入文章标题:", "", 
                                            self.title_cb, None, None)

    def title_cb(self, title):
        self.post['title'] = title
        self.tags_prompt()

    def tags_prompt(self):
        self.view.window().show_input_panel("标签 (多个逗号隔开):", "",
                                            self.tags_cb, None, None)   
    def tags_cb(self, tags):
        self.post['mt_keywords'] = tags    
        t = threading.Thread(target=self.new_post)
        t.start()
        handle_thread(t, '文章发布中...')        


    def new_post(self):
        try:
            result = self.server.metaWeblog.newPost("", self.login_name,self.login_password, self.post,True)

            if len(result) > 0:
                status('文章发布成功', True)
            else:
                status('错误: 文章发布失败', True)
        except Error:
            status('错误: 发生错误,文章未发布', True)                                     
      

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值