blogit_passwd.diff

patch - Adam Schmalhofer, 06/17/2009 12:13 am

Download (6.2 KB)

 
b/plugin/blogit.vim
39 39
"   Display help
40 40
"
41 41
" Configuration :
42
"   Edit the "Settings" section
42
"   Create a file called passwords.vim somewhere in your 'runtimepath'
43
"   (prefered location is "~/.vim/"). Don't forget to set the permissions so 
44
"   only you can read it. This file should include:
45
"
46
"       let blogit_username='Your blog username'
47
"       let blogit_password='Your blog password. Not the API-key.'
48
"       let blogit_url='http://your.path.to/xmlrpc.php'
43 49
"
44 50
" Usage :
45 51
"   Just fill in the blanks, do not modify the highlighted parts and everything
......
47 53
"
48 54
" vim: set et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
49 55

  
56
runtime! passwords.vim
50 57
command! -nargs=+ Blogit exec('py blogit.command(<f-args>)')
51 58

  
52 59
python <<EOF
......
55 62
from xmlrpclib import DateTime, Fault
56 63
from types import MethodType
57 64

  
58
#####################
59
#      Settings     #
60
#####################
61

  
62
blog_username = 'user'
63
blog_password = 'passwd'
64
blog_url = 'http://example.com/xmlrpc.php'
65

  
66
#####################
67
# Do not edit below #
68
#####################
69

  
70 65
class BlogIt:
71 66

  
72 67
    def __init__(self):
73
        self.client = xmlrpclib.ServerProxy(blog_url)
68
        self.client = xmlrpclib.ServerProxy(self.blog_url())
74 69
        self.current_post = None
75 70

  
76 71
    def command(self, command, *args):
......
93 88

  
94 89
    def command_ls(self):
95 90
        try:
96
            allposts = self.client.metaWeblog.getRecentPosts('',blog_username, blog_password)
91
            allposts = self.client.metaWeblog.getRecentPosts('', 
92
                    self.blog_username(), self.blog_password())
97 93
            if not allposts:
98 94
                sys.stderr.write("There isn't any post")
99 95
                return
......
104 100
            self.current_post = None
105 101
            vim.current.buffer[0] = "ID\tDate             \tTitle"
106 102
            for p in allposts:
107
                vim.current.buffer.append(formatter % (int(p['postid']), p['dateCreated'], p['title'].encode('utf-8')))
103
                vim.current.buffer.append(formatter % (int(p['postid']), \
104
                        p['dateCreated'], p['title'].encode('utf-8')))
108 105
                vim.command('set nomodified')
109 106
            vim.current.window.cursor = (2, 0)
110 107
            vim.command('map <enter> :py blogit.list_edit()<cr>')
......
124 121
            return
125 122

  
126 123
        try:
127
            post = self.client.metaWeblog.getPost(id, blog_username, blog_password)
124
            post = self.client.metaWeblog.getPost(id, self.blog_username(), 
125
                                                  self.blog_password())
128 126
            self.display_post(post)
129 127
        except Fault, e:
130 128
            sys.stderr.write(e.faultString)
131 129

  
132 130
    def command_new(self):
133
        username = self.client.blogger.getUserInfo('', blog_username, blog_password)['firstname']
131
        username = self.client.blogger.getUserInfo(
132
                '', self.blog_username(), self.blog_password())['firstname']
134 133
        self.display_post({'wp_author_display_name': username,
135 134
                           'postid': '',
136 135
                           'title': '',
......
139 138
                           'dateCreated': '',
140 139
                           'description': '',
141 140
                           'post_status': 'draft',
142
                           })
141
                         })
143 142

  
144 143
    def display_post(self, post):
145 144
        vim.command("set ft=mail")
......
235 234
            strid = self.getMeta('Post-Id')
236 235

  
237 236
            if strid == '':
238
                strid = self.client.metaWeblog.newPost('', blog_username,
239
                                                       blog_password, post, push)
237
                strid = self.client.metaWeblog.newPost('', self.blog_username(),
238
                                                       self.blog_password(), 
239
                                                       post, push)
240 240

  
241 241
                vim.current.buffer[self.getLine('Post-Id')] = "Post-Id: %s" % strid
242 242
                vim.current.buffer[self.getLine('Date')] = "Date: %s" % post['dateCreated']
243 243
            else:
244
                self.client.metaWeblog.editPost(strid, blog_username,
245
                                                blog_password, post, push)
244
                self.client.metaWeblog.editPost(strid, self.blog_username(),
245
                                                self.blog_password(), post, 
246
                                                push)
246 247
        except Fault, e:
247 248
            sys.stderr.write(e.faultString)
248 249

  
......
254 255
            return
255 256

  
256 257
        try:
257
            self.client.metaWeblog.deletePost('', id, blog_username, blog_password)
258
            self.client.metaWeblog.deletePost('', id, self.blog_username(), 
259
                                              self.blog_password())
258 260
        except Fault, e:
259 261
            sys.stderr.write(e.faultString)
260 262
            return
......
264 266
            self.current_post = None
265 267

  
266 268
    def command_categories(self):
267
        cats = self.client.wp.getCategories('', blog_username, blog_password)
269
        cats = self.client.wp.getCategories('', self.blog_username(), 
270
                                            self.blog_password())
268 271
        sys.stdout.write('Categories:\n')
269 272
        for cat in cats:
270 273
            sys.stdout.write('  %s\n' % cat['categoryName'])
271 274

  
275
    def blog_username(self): 
276
        return vim.eval('blogit_username')
277

  
278
    def blog_password(self): 
279
        return vim.eval('blogit_password')
280

  
281
    def blog_url(self): 
282
        return vim.eval('blogit_url')
283

  
272 284
    def getMethods(self, prefix):
273 285
        services = {}
274 286
        for attrname in dir(self):
......
281 293
            services[name] = attr
282 294
        return services
283 295

  
296

  
284 297
blogit = BlogIt()