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

简介: 使用说明: 首先修改meetrice.sublime-settings中的配置   1.shift+f9 快速发布选中的内容 2.在弹出的对话框架填写"标题" 3.在弹出的对话框中填写"tag" 发布成功!   百度网盘下载     import os import threading from xmlrpc.

使用说明:

首先修改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)                                     
      

 

 

 

目录
相关文章
|
4月前
sublime和vscode 推荐安装的插件
sublime和vscode 推荐安装的插件
63 0
|
1月前
|
Python
Sublime Text Python 代码提示插件 Anaconda
Sublime Text Python 代码提示插件 Anaconda
59 1
|
4月前
|
数据安全/隐私保护
sublime 如何安装ftp插件
sublime 如何安装ftp插件
158 1
sublime 如何安装ftp插件
sublime text verilog-automatic插件使用方法
sublime text verilog-automatic插件使用方法
181 0
sublime text verilog-automatic插件使用方法
|
程序员
sublime实用插件
sublime实用插件
132 0
|
Python
Python编程:sublime编辑器python开发必装插件
Python编程:sublime编辑器python开发必装插件
275 0
Sublime Text - 修改插件的默认安装位置
Sublime Text - 修改插件的默认安装位置
304 0
|
JSON JavaScript 开发工具
sublime text 2插件
Sublime有好几种安装插件的方法,但是最好用也是最长用的是ctrl+shift+p。
给Sublime Text2安装GraphQL语法高亮插件
给Sublime Text2安装GraphQL语法高亮插件
131 0
给Sublime Text2安装GraphQL语法高亮插件
|
Web App开发 移动开发 Python
如何根据自己的实际需求开发属于自己的sublime text插件
如何根据自己的实际需求开发属于自己的sublime text插件
114 0
如何根据自己的实际需求开发属于自己的sublime text插件