def delete(self, postid=''): if not postid: index = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED) if index == -1: common.showmessage(self.mainframe, tr('You should select on entry first!')) return filename = self.data[index] tree = Tree() tree.read_from_xml(file(filename).read()) data = tree['entry'] postid = data['postid'] common.setmessage(self.mainframe, tr('Deleting entry...')) site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]] try: server = xmlrpclib.ServerProxy(site['url']) result = server.blogger.deletePost('', postid, site['user'], site['password'], False) if result: common.showmessage(self.mainframe, tr('Delete is successful!')) self.list.DeleteItem(index) else: common.showerror(self.mainframe, tr('Delete error!')) except Exception, msg: error.traceback() common.showerror(self.mainframe, msg)
def getposts(self, number=1, postid=''): common.setmessage(self.mainframe, tr('Getting entries...')) site = self.pref.blog_sites_info[self.pref.blog_sites[ self.cmbSite.GetSelection()]] try: server = xmlrpclib.ServerProxy(site['url']) if not postid: result = server.metaWeblog.getRecentPosts( '', site['user'], site['password'], number) else: result = [ server.metaWeblog.getPost(postid, site['user'], site['password']) ] self.list.DeleteAllItems() self.data = [] for i, entry in enumerate(result): tree = Tree() data = {} data['title'] = entry['title'] data['dateCreated'] = getDateTime(entry['dateCreated']) data['guid'] = entry.get('guid', '') data['postid'] = entry.get('postid', '') data['permalink'] = entry['permaLink'] data['description'] = entry['description'] data['author'] = entry.get('author', '') data['categories'] = entry['categories'] if not data['postid']: pos = data['guid'].rfind('#') data['postid'] = data['guid'] tree['entry'] = data path = self.getpath(site['datapath'], site['name']) if path: filename = os.path.join(path, data['dateCreated'] + '.xml') file(filename, 'wb').write(tree.write_to_xml()) categories = self.mapCategories(data['categories']) #write list self.data.append(filename) self.list.InsertStringItem(i, ','.join(categories)) self.list.SetStringItem(i, 1, data['title']) self.list.SetStringItem(i, 2, formatDate(data['dateCreated'])) self.list.SetStringItem(i, 3, data['postid']) except Exception, msg: error.traceback() common.showerror(self.mainframe, msg)
def getposts(self, number=1, postid=''): common.setmessage(self.mainframe, tr('Getting entries...')) site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]] try: server = xmlrpclib.ServerProxy(site['url']) if not postid: result = server.metaWeblog.getRecentPosts('', site['user'], site['password'], number) else: result = [server.metaWeblog.getPost(postid, site['user'], site['password'])] self.list.DeleteAllItems() self.data = [] for i, entry in enumerate(result): tree = Tree() data = {} data['title'] = entry['title'] data['dateCreated'] = getDateTime(entry['dateCreated']) data['guid'] = entry.get('guid', '') data['postid'] = entry.get('postid', '') data['permalink'] = entry['permaLink'] data['description'] = entry['description'] data['author'] = entry.get('author', '') data['categories'] = entry['categories'] if not data['postid']: pos = data['guid'].rfind('#') data['postid'] = data['guid'] tree['entry'] = data path = self.getpath(site['datapath'], site['name']) if path: filename = os.path.join(path, data['dateCreated']+'.xml') file(filename, 'wb').write(tree.write_to_xml()) categories = self.mapCategories(data['categories']) #write list self.data.append(filename) self.list.InsertStringItem(i , ','.join(categories)) self.list.SetStringItem(i, 1, data['title']) self.list.SetStringItem(i, 2, formatDate(data['dateCreated'])) self.list.SetStringItem(i, 3, data['postid']) except Exception, msg: error.traceback() common.showerror(self.mainframe, msg)
def OnCache(self, event): site = self.pref.blog_sites_info[self.pref.blog_sites[self.cmbSite.GetSelection()]] self.list.DeleteAllItems() self.data = [] path = self.getpath(site['datapath'], site['name']) if path: files = glob.glob(os.path.join(path, '*.xml')) files.reverse() for i, f in enumerate(files): tree = Tree() tree.read_from_xml(file(f).read()) data = tree['entry'] self.data.append(f) categories = self.mapCategories(data['categories']) self.list.InsertStringItem(i , ','.join(categories)) self.list.SetStringItem(i, 1, data['title']) self.list.SetStringItem(i, 2, formatDate(data['dateCreated'])) self.list.SetStringItem(i, 3, data['postid'])