コード例 #1
0
ファイル: main.py プロジェクト: Ryuno-Ki/BloGTK3
	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)
コード例 #2
0
ファイル: editor.py プロジェクト: Ryuno-Ki/BloGTK3
	def getPostMT(self, account, postID):

		mt = mtapi.movabletype(account['endpoint'], account['username'], account['password'])
		cats = mt.getCategoryList(account['id'])

		for cat in cats:
			self.tsCats.append(None, (cat['categoryName'], None, cat['categoryId']))

		post = mt.getPost(postID)

		# Take the post data and fill our editing fields
		self.tePostTitle.set_text(post['title'])

		self.sbMain.set_text(post['description'])
		self.sbExtended.set_text(post['mt_text_more'])
		try:
			self.teTags.set_text(post['mt_keywords'])
		except:
			# If no keywords support, remove the option
			self.teTags.set_sensitive(False)

		try:
			if post['mt_allow_comments'] == 1:
				self.cbComments.set_active(True)
			elif post['mt_allow_comments'] == 0:
				self.cbComments.set_active(False)
		except:
			self.cbComments.set_active(False)
			self.cbComments.set_sensitive(False)

		try:
			if post['mt_allow_pings'] == 1:
				self.cbTrackbacks.set_active(True)
			elif post['mt_allow_pings'] == 0:
				self.cbTrackbacks.set_active(False)
		except:
				self.cbTrackbacks.set_active(False)
				self.cbTrackbacks.set_sensitive(False)

		# Set categories
		self.setPostCats(post['categories'])


		# We need to make sure other routines can see our account data
		self.account = account
		self.postID = postID
		self.timestamp = time.strptime(str(post['dateCreated']), '%Y%m%dT%H:%M:%S')

		self.winEditor.show()
		
		# Reset our change flags.
		self.changeFlag = False
		self.mainInstance.changeFlag = False
コード例 #3
0
ファイル: main.py プロジェクト: Ryuno-Ki/BloGTK3
	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)
コード例 #4
0
ファイル: editor.py プロジェクト: Ryuno-Ki/BloGTK3
	def publishPostMT(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()

		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		

		# 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:
			pass

		# Do we want to publish the post? (Default is to publish)
		if self.cbPublish.get_active() == True:
			publish = 0
		else:
			publish = 1

		# Create our post object
		postObject = {}
		postObject['title'] = title
		postObject['description'] = mainEntry
		if self.timestamp != None:
			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['publish'] = publish

		mt = mtapi.movabletype(self.account['endpoint'], self.account['username'], self.account['password'])

		# Is this a new post or an edit?

		if self.postID == '':
			try:
				post = mt.createPostWithCats(self.account['id'], postObject, True, self.activeCats)
				# 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)