Exemplo n.º 1
0
    def get(self):

        self.session = Session()
        formatter = StringFormatter()
        client = OAuthClient('twitter', self, 'noName')
    
        token_info = client.getAccessToken(self.request.query_string.split('=')[1])
        error = ''
        company = ''
        
        if 'user' not in self.session:
            error = 'Unauthorized User Error'
        else:
            user = self.session['user']
            company = formatter.getCompanyProfileName(user)
        values = formatter.getValues(token_info)
        
        #Must use dbInterface
        query = db.Query(UserToken)
        query = query.filter('dbTwitterName=', values[3])
        results = query.fetch(limit = 1)
        
        if len(results) > 0:
            for r in results:
                db.delete(r)
                
        if error == '':
            token = UserToken(dbProfileName = company, dbTwitterName = values[3], dbToken = values[0], dbTokenSecret = values[1])
            token.put();
        self.redirect('settings.html')       		
Exemplo n.º 2
0
 def findIntegralXIntercept_SIF_NonZeroM(self, numChoices, points):
     m = 0
     while (m == 0):
         m = random.randint(-20, 20)
     multiplier = 0
     while (multiplier == 0):
         multiplier = random.randint(-10, 10)
     b = m * multiplier
     x_intercept = -1 * b // m
     d = {}
     problemStatement = StringFormatter().format("Question Statement.")
     d["problemStatement"] = problemStatement.format(m, b)
     d["correctAnswer"] = x_intercept
     d["correctAnswerIdx"] = utility.getCorrectAnswerIndex(numChoices)
     d["wrongAnswers"] = utility.generateWrongAnswers(
         numChoices, x_intercept, "ints")
     d["points"] = points
     d["solution"] = [
         ("y = {}x + {}".format(m, b),
          StringFormatter().format("Find the x intercept.")),
         ("0 = {}x + {}".format(m, b),
          StringFormatter().format("Set y to zero.")),
         ("0 - {} = {}x + {} - {}".format(b, m, b, b),
          StringFormatter().format("Subtract b from both sides.")),
         ("{} = {}x".format(-b, m), StringFormatter().format("Simplify.")),
         ("{} / {} = x".format(-b, m),
          StringFormatter().format("Divide both sides by m.")),
         ("{}".format(-b // m), StringFormatter().format("Simplify."))
     ]
     return d
Exemplo n.º 3
0
	def get(self):
	
		fb = facebook.Facebook(API_KEY, SECRET_KEY)
		url = self.request.url
		params = url.split('&')
		
		userID = params[0].split('?')[1]
		token = params[1].split('?')[1]
		fname = params[2].split('?')[1]
		lname = params[3].split('?')[1]
		
		newSessionKey = fb.__call__('Auth.getSession', {'auth_token':token})
		
		self.session = Session()
		formatter = StringFormatter()
		
		error = ''
		company = ''
        
		if 'user' not in self.session:
			error = 'Unauthorized User Error'
		else:
			user = self.session['user']
			company = formatter.getCompanyProfileName(user)
		
		if fb.__call__('Users.hasAppPermission', {'uid':userID, 'call_id':time(), 'ext_perm':'offline_access'}) == 0:
			error = 'Permissions Ungranted Error'
		
		if fb.__call__('Users.hasAppPermission', {'uid':userID, 'call_id':time(), 'ext_perm':'publish_stream'}) == 0:
			error = 'Permissions Ungranted Error'
		
		if fb.__call__('Users.hasAppPermission', {'uid':userID, 'call_id':time(), 'ext_perm':'read_stream'}) == 0:
			error = 'Permissions Ungranted Error'
		 
		query = db.Query(FbSession)
		query = query.filter('dbUid =', userID)
		results = query.fetch(limit = 1)
		
		if len(results) > 0:
			for r in results:
				if error == '':
					db.delete(r)
			
		if error == '':
			token = FbSession(dbProfileName = company, dbSessionKey = newSessionKey['session_key'], dbUserName = fname + ' ' + lname, dbUid = userID)
			token.put();
			self.response.out.write("Account added to SynapSync successfully! You may now return to the application.")
		else:
			self.response.out.write(error + ". Please try authenticating again.")
Exemplo n.º 4
0
 def get(self):
     datastore = DataStoreInterface()
     formatter = StringFormatter()
     
     path = self.request.query_string
     params =  path.split('/')
     company = params[0].replace('company=','')
     postId = params[1].replace('id=','')
     
     post = datastore.getPost(company, postId)
     
     for p in post:
         update = formatter.formatPost(p, company)
     
     render.doRender(self, 'update.html', {'update' : update})
     
Exemplo n.º 5
0
 def get(self):
     formatter = StringFormatter()
     datastore = DataStoreInterface()
     
     queries = []
     queries = formatter.getValues(self.request.query_string)
     
     if len(queries) == 1:
         if (datastore.companyProfileExists(queries[0]) == 1):                
             posts = datastore.getPosts(queries[0], 5)
             
             for p in posts:
                 self.response.out.write(p.dbTitle + ' - ' + p.dbBody + '<br>')
         else:
             self.response.out.write('Company Not Found')
 
     else:
         self.response.out.write("unknown query")
Exemplo n.º 6
0
	def get(self):
	
		datastore = DataStoreInterface()
		formatter = StringFormatter()
		
		path = self.request.query_string.replace('company=', '')
		posts = datastore.getPosts(path, 25)
		companies = datastore.getCompanyInfo(path) 
		company = datastore.getCompanyName(path)
		
		info=''
		for c in companies:
			info = formatter.formatCompanyInfo(c)
				
		postList=[]
		for p in posts:
			postList.append(formatter.formatPost(p, p.dbProfileName))
		render.doRender(self, 'profiles.html', {'posts': postList, 'company': company , 'info': info, 'profileName' : path})
Exemplo n.º 7
0
	def get(self):
		self.session = Session()

		if 'user' in self.session:
			formatter = StringFormatter()
			user = self.session['user']	
			company = formatter.getCompanyProfileName(user)
			email = formatter.getEmail(user)

			datastore = DataStoreInterface()
			twitterAccounts = datastore.getTwitterAccounts(company)
			facebookAccounts = datastore.getFacebookAccounts(company)
			
			uInfo = datastore.getUserInfo(email)
			
			for u in uInfo:
				firstName = u.dbFirstName 
				lastName = u.dbLastName
				
				
			
			cInfo = datastore.getCompanyInfo(company)
			
			for c in cInfo:
				cname = c.dbCompanyName
				stAddress = c.dbStreetAddress
				city = c.dbCity
				state = c.dbState
				zip = c.dbPostalCode
				country = c.dbCountry
				number = c.dbPhoneNumber
				cemail = c.dbAdministrator
				website = c.dbUrl

			if datastore.isAdmin(company, email) == 1:
				render.doRender(self, 'settings.html', {'isAdmin':email,'email':email,'firstName':firstName, 'lastName':lastName, 'socialAccounts' : twitterAccounts
													    ,'facebookAccounts':facebookAccounts, 'cname':cname, 'stAddress':stAddress, 'city':city, 'state':state, 'zip':zip
													    ,'country':country, 'number':number, 'cemail':cemail, 'website':website })
			else:
				render.doRender(self, 'settings.html', {'email':email})
		else:
			render.doRender(self, 'main.html', {})
Exemplo n.º 8
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')
Exemplo n.º 9
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')
Exemplo n.º 10
0
 def findIntegralXIntercept_SIF_NonZeroFracM(self, numChoices, points):
     m_numerator = 0
     while (m_numerator == 0):
         m_numerator = random.randint(-30, 30)
     m_denominator = 0
     while ((m_denominator == 0) or (m_denominator == m_numerator)):
         m_denominator = random.randint(-30, 30)
     multiplier = 0
     while (multiplier == 0):
         multiplier = random.randint(-10, 10)
     b = m_numerator * multiplier
     x_intercept = -1 * m_denominator * b // m_numerator
     d = {}
     d["problemStatement"] = StringFormatter().format(
         "Question Statement 2.").format(m_numerator, m_denominator, b)
     d["correctAnswer"] = x_intercept
     d["correctAnswerIdx"] = utility.getCorrectAnswerIndex(numChoices)
     d["wrongAnswers"] = utility.generateWrongAnswers(
         numChoices, x_intercept, "ints")
     d["points"] = points
     d["solution"] = [
         ("y = \\frac{{{}}}{{{}}}x + {}".format(m_numerator,
                                                m_denominator, b),
          StringFormatter().format("Find the x intercept.")),
         ("0 = \\frac{{{}}}{{{}}}x + {}".format(m_numerator,
                                                m_denominator, b),
          StringFormatter().format("Set y to zero.")),
         ("0 - {} = \\frac{{{}}}{{{}}}x + {} - {}".format(
             b, m_numerator, m_denominator, b,
             b), StringFormatter().format("Subtract b from both sides.")),
         ("{} = \\frac{{{}}}{{{}}}x ".format(-b, m_numerator,
                                             m_denominator),
          StringFormatter().format("Simplify.")),
         ("{} \\times \\frac{{{}}}{{{}}} = x".format(
             -b, m_denominator, m_numerator),
          StringFormatter().format("Divide both sides by m.")),
         ("{}".format(-1 * m_denominator * b // m_numerator),
          StringFormatter().format("Simplify."))
     ]
     return d
Exemplo n.º 11
0
	def get(self):		
		self.session = Session()	
		if 'user' in self.session:
			user = self.session['user']	
			datastore = DataStoreInterface()
		
			formatter = StringFormatter()
			company = formatter.getCompanyProfileName(user)
			email = formatter.getEmail(user)
			
			twitter_oauth_handler.setTwitterAccounts(company)
			twitterAccounts = twitter_oauth_handler.getTwitterAccounts()
			
			facebookAccounts = datastore.getFacebookAccounts(company)
			
			#TWITTER MENTIONS QUERIED			
			mentions = []
			
			for name in twitterAccounts:
				numMention = 0
				client = OAuthClient('twitter', self, name)
				statuses = client.get('/statuses/mentions')
				if statuses == "Could not retrieve from social networks. The server could not be contacted at this time. Please try again later.":
					self.response.out.write(statuses)
					return
				for iteration in statuses:
					numMention += 1
					mention = Mentions()
					mention.dbCreatedTime = iteration['created_at']
					mention.dbMessage = iteration['text']
					mention.dbName = iteration['user']['screen_name']
					mention.dbPostID = str(iteration['id'])
					mention.dbReceiverName = iteration['in_reply_to_screen_name']
					mention.dbLink = 'From: <a href="http://twitter.com/'  + iteration['user']['screen_name']+'" target="_blank">'+ iteration['user']['name'] + '</a>'
					mentions.append(mention)
					if numMention == 5:
						break
		
			comments = []
			
			for name in facebookAccounts:
				fb = facebook.Facebook(API_KEY, SECRET_KEY)
				stream = fb.__call__('Stream.get', {'session_key':name.dbSessionKey, 'source_ids':[name.dbUid], 'limit':5})
				for post in stream['posts']:				
					replies = post['comments']['comment_list']
					numComment = 0
					for reply in replies:
						userInfo = fb.__call__('Users.getInfo', {'session_key':name.dbSessionKey, 'call_id':time(), 'uids':reply['fromid'], 'fields':['first_name', 'last_name']})
						username = userInfo[0]['first_name'] + ' ' + userInfo[0]['last_name']
						status = Comments()
						status.dbUserID = name.dbUid
						status.dbPostID = post['post_id']
						status.dbMessage = reply['text']
						status.dbLink = 'From: <a href="http://www.facebook.com/profile.php?ref=profile&id=' + str(reply['fromid']) + '" target="_blank">' + username + '</a>'
						status.dbReplyTo = 'In reply to: ' + post['message']
						comments.append(status)
						numComment += 1
						if numComment == 3:
							break
					if len(comments) == 10:
						break
						
			#getting saved posts 
			datastore = DataStoreInterface()
			formatter = StringFormatter()
			
			profileName = formatter.getCompanyProfileName(user)
		
			posts = datastore.getSavedPosts(profileName, 25)
			savedPosts = ''
			
			for r in posts:
				savedPosts += formatter.formatSavedPost(r, formatter.formatPost(r, profileName))
			
			#upload_url = blobstore.create_upload_url('/upload')	
			render.doRender(self, 'controlpanel.html', {'user': user, 'mentions': mentions, 'comments':comments, 'savedPosts': savedPosts, 'socialAccounts': twitterAccounts, 'facebookAccounts':facebookAccounts})
		else:
			self.redirect('main.html')
Exemplo n.º 12
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')