def refreshPosts(self, widget): selected_iter = self.tvBlogs.get_selection().get_selected()[1] accountName = self.model.get_value(selected_iter, 0) for account in self.accountArray: if account['name'] == accountName: thisAccount = account self.appbar.push(_('Getting posts')) # Make it so the user cannot hit Refresh again while refresh is cylcling. self.tbtnRefresh.set_sensitive(False) gtk.gdk.threads_enter() self.timeout_handler_id = gobject.timeout_add(100, self.update_progress_bar, 'live', 0) gtk.gdk.threads_leave() # SYSTEM DEPENDENT try: if thisAccount['api'] == "mt": mt = mtapi.movabletype(thisAccount['endpoint'], thisAccount['username'], thisAccount['password']) posts = mt.getPostsAsAtomFeed(thisAccount['id'], thisAccount['pullcount']) self.savePostsToCache(posts) # We also refresh the categories here cats = mt.getCategoryList(thisAccount['id']) self.configWriter.writeCategoryArray(thisAccount['name'], cats) elif thisAccount['api'] == 'mtatom': mtatom = atomapi.MTAtom(thisAccount['endpoint'], thisAccount['username'], thisAccount['password']) mtatom = mt.getPostsAsAtomFeed(thisAccount['id'], thisAccount['pullcount']) elif thisAccount['api'] == 'gdata': bloggergdata = bloggeratom.BloggerAtom(thisAccount['username'], thisAccount['password']) posts = bloggergdata.getPostsAsAtomFeed(thisAccount['id'], thisAccount['pullcount']) self.savePostsToCache(posts) elif thisAccount['api'] == 'metaweblog': mw = metaweblog.metaWeblog(thisAccount['endpoint'], thisAccount['username'], thisAccount['password']) posts = mw.getPostsAsAtomFeed(thisAccount['id'], thisAccount['pullcount']) self.savePostsToCache(posts) # We also refresh the categories here try: cats = mw.getCategoryList(thisAccount['id']) self.configWriter.writeCategoryArray(thisAccount['name'], cats) except Exception, e: print Exception, str(e) elif thisAccount['api'] == 'blogger': bloggerapi = blogger.Blogger(thisAccount['endpoint'], thisAccount['username'], thisAccount['password']) posts = bloggerapi.getPostsAsAtomFeed(thisAccount['id'], thisAccount['pullcount']) self.savePostsToCache(posts)
def getPostMetaweblog(self, account, postID): mw = metaweblog.metaWeblog(account['endpoint'], account['username'], account['password']) post = mw.getPost(postID) try: cats = mw.getCategoryList(account['id']) for cat in cats: self.tsCats.append(None, (cat['categoryName'], None, cat['categoryId'])) except Exception, e: print Exception, str(e)
def deletePost(self, widget, data=None): selected_iter = self.tvBlogs.get_selection().get_selected()[1] accountName = self.model.get_value(selected_iter, 0) try: selected_iter2 = self.tvPosts.get_selection().get_selected()[1] postID = self.tvPosts.get_model().get_value(selected_iter2, 0) postName = self.tvPosts.get_model().get_value(selected_iter2, 1) for account in self.accountArray: if account['name'] == accountName: thisAccount = account msgtext = _("Are you sure you wish to delete the\n post '%s'?") % postName msgbox = gtk.MessageDialog(parent = self.winMain, buttons = gtk.BUTTONS_OK_CANCEL, flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_WARNING, message_format = msgtext) msgbox.set_title(_('Confirm deletion')) msgbox.format_secondary_text(_('All information in this post will be deleted and cannot be restored.')) result = msgbox.run() msgbox.destroy() if result == gtk.RESPONSE_OK: if thisAccount['api'] == 'mt': mt = mtapi.movabletype(thisAccount['endpoint'], thisAccount['username'], thisAccount['password']) posts = mt.deletePost(postID) self.refreshPosts(None) self.appbar.push('Deleted post ' + postID) if thisAccount['api'] == 'gdata': bloggergdata = bloggeratom.BloggerAtom(thisAccount['username'], thisAccount['password']) bloggergdata.deletePost(thisAccount['id'], postID) self.refreshPosts(None) if thisAccount['api'] == 'metaweblog': mw = metaweblog.metaWeblog(thisAccount['endpoint'], thisAccount['username'], thisAccount['password']) mw.deletePost(postID) self.refreshPosts(None) else: return False except TypeError, e: self.appbar.push(_('Please select a post to delete.')) print str(e)
def publishPostMetaWeblog(self): gtk.gdk.threads_enter() self.timeout_handler_id = gobject.timeout_add(100, self.update_progress_bar, 'live', 0) gtk.gdk.threads_leave() # Assemble the necessary elements title = self.tePostTitle.get_text() mainEntry = self.sbMain.get_text(self.sbMain.get_start_iter(), self.sbMain.get_end_iter()) extendedEntry = self.sbExtended.get_text(self.sbExtended.get_start_iter(), self.sbExtended.get_end_iter()) keywords = self.teTags.get_text() # Prepare our list of categories self.activeCats = [] self.tsCats.foreach(self.getActiveCats) # We will set the first category as the default try: self.activeCats[0]['isPrimary'] = True except: print 'No categories selected' if self.cbComments.get_active() == True: comments = 1 elif self.cbComments.get_active() == False: comments = 0 if self.cbTrackbacks.get_active() == True: trackbacks = 1 elif self.cbTrackbacks.get_active() == False: trackbacks = 0 if self.cbPublish.get_active() == True: publish = False else: publish = True # Create our post object postObject = {} postObject['title'] = title postObject['description'] = mainEntry if self.timestamp: postObject['dateCreated'] = self.timestamp else: postObject['dateCreated'] = time.strftime( "%Y%m%dT%H:%M:%SZ", time.gmtime()) postObject['mt_excerpt'] = '' postObject['mt_text_more'] = extendedEntry postObject['mt_keywords'] = keywords postObject['mt_allow_comments'] = comments postObject['mt_allow_pings'] = trackbacks postObject['mt_convert_breaks'] = 1 postObject['categories'] = self.activeCats mw = metaweblog.metaWeblog(self.account['endpoint'], self.account['username'], self.account['password']) # Is this a new post or an edit? if self.postID == '': try: post = mw.createPost(self.account['id'], postObject, publish) # Now any edits will be made as a repost self.postID = post self.timeout_handler_id2 = gobject.timeout_add(100, self.update_progress_bar, 'die', 0) self.statEdit.push(1, _('Created new entry with ID %s' % post)) self.tbtnPublish.set_sensitive(True) self.mainInstance.refreshPosts(None) except Exception, e: print Exception, str(e) self.tbtnPublish.set_sensitive(True)