Example #1
0
	def post(self):
		#intialization of variables
		self.session = Session()
		if 'user' in self.session:
			user = self.session['user']		
			error=''
			
			formatter = StringFormatter()
			company = formatter.getCompany(user)
			profileName = formatter.getCompanyProfileName(user)
			
			#retrieving content from form fields		
			title = self.request.get('txtTitle')
			id = formatter.formatID(title)
			content = self.request.get('txtContent')
			btnClicked = formatter.getButtonType(self.request.body)
				
			if title<>'':

				response = ''
				if (btnClicked == 'Post'):
				
					params = (self.request.url).split('?')[1].split('&')
					twitterAccounts = datastore.getTwitterAccounts(profileName)
					twitter = twitterAccounts
					for name in twitter:
						if name == params[1].split('=')[1]:
							client = OAuthClient('twitter', self, name)
							response = client.post('/statuses/update', status = title, in_reply_to_status_id = params[0].split('=')[1])
				
				if response == "SynapSync could not post to Twitter. The server could not be contacted at this time. Please try again later.":
					self.response.out.write(response)
					return
				
			else:
				error = 'Please fill the Title and Content fields below!' 
			self.redirect('controlpanel.html')
Example #2
0
	def post(self):
		#intialization of variables
		self.session = Session()
		if 'user' in self.session:
			user = self.session['user']		
			error=''
			
			formatter = StringFormatter()
			company = formatter.getCompany(user)
			profileName = formatter.getCompanyProfileName(user)
			
			#retrieving content from form fields		
			title = self.request.get('txtTitle')
			id = formatter.formatID(title)
			content = self.request.get('txtContent')
			btnClicked = formatter.getButtonType(self.request.body)
				
			if title<>'':

				response = ''
				if (btnClicked == 'Post'):
				
					params = (self.request.url).split('?')[1].split('&')
					facebookAccounts = datastore.getFacebookAccounts(profileName)
					for fb in facebookAccounts:
						if fb.dbUid == params[1].split('=')[1]:
							fb = facebook.Facebook(API_KEY, SECRET_KEY)
							response = fb.__call__('Stream.addComment', {'post_id':params[0].split('=')[1], 'comment':title, 'uid':params[1].split('=')[1]})
				
				if response == "SynapSync could not post to Facebook. The server could not be contacted at this time. Please try again later.":
					self.response.out.write(response)
					return
				
			else:
				error = 'Please fill the Title and Content fields below!' 
			self.redirect('controlpanel.html')
Example #3
0
	def post (self):
		#intialization of variables
		self.session = Session()
		user = self.session['user']		
		datastore = DataStoreInterface()
		status = ''
		error=''
		message=''
			
		#formatting of user cached account
		formatter = StringFormatter()
		company = formatter.getCompany(user)
		profileName = formatter.getCompanyProfileName(user)
		email = formatter.getEmail(user)
		
		#retrieving content from form fields		
		title = self.request.get('txtTitle')
		id = formatter.formatID(title)
		content = self.request.get('txtContent')
		file = self.request.get("file")
		btnClicked = formatter.getButtonType(self.request.body)
			
		if title<>'':
			
			postLink = ('synapsync.com/update.html?company=%s/id=%s'%(profileName, id))


			bitly = BitLy(BITLY_USER, BITLY_KEY)
			postLink = bitly.shorten(postLink)
			
			#self.response.out.write(postLink)
			#return	

			postAttributes = [company, profileName, email, title, content, id]
			
			#if no file attached then just place type None else use attached file
			if file == '':
				postAttributes.append(None)
			else:
				postAttributes.append(file)
				
			postAttributes.append(postLink)
			
			response = ''
			if (btnClicked == 'Post'):
				status = 'Posted'
				postAttributes.append(status)
				emailObj = EmailProcessor()
			
				
				emails =  []

				emails = datastore.getEmailSubscriber(profileName)
				
				for e in emails:
					if (e <> None and e <> ''):				
						emailObj.sendAnnounceEmail(company, e.strip() , title, content + ' ' + postLink)
			
				#twitter
				#twitterAccounts = datastore.getTwitterAccounts(profileName)
			
				facebookAccounts = datastore.getFacebookAccounts(profileName)
				twitterAccounts = datastore.getTwitterAccounts(profileName)
				twitter = twitterAccounts
				for name in twitter:
					client = OAuthClient('twitter', self, name)
					response = client.post('/statuses/update', status = title + '\n' + postLink)
				for name in facebookAccounts:
					fb = facebook.Facebook(API_KEY, SECRET_KEY)
					fbResponse = fb.__call__('Stream.publish', {'session_key':name.dbSessionKey, 'message':title + '\n' + postLink, 'target_id':name.dbUid, 'uid':name.dbUid})

			elif (btnClicked == 'Save'):
				status = 'Saved'
				postAttributes.append(status)
		
			datastore.putPost(postAttributes)
			
			if response == "SynapSync could not post to Twitter. The server could not be contacted at this time. Please try again later.":
				self.response.out.write(response)
				return
			
		else:
			error = 'Please fill the Title and Content fields below!' 
		self.redirect('controlpanel.html')