Пример #1
0
 def status(self, session):
     if 'snuggler' in session:
         return responses.success({
             'logged_in':
             True,
             'snuggler':
             session['snuggler'].serialize()
         })
     else:
         return responses.success({'logged_in': False})
Пример #2
0
    def log_out(self, session):
        if 'snuggler' in session:
            try:
                event = types.SnugglerLoggedOut(session['snuggler'])
                self.model.events.insert(event)
            except Exception as e:
                logger.error(traceback.format_exc())

            del session['snuggler']

            return responses.success(True)
        else:
            return responses.success("Not logged in.")
Пример #3
0
	def status(self):
		return responses.success(
			{
				'status': "online", 
				'up_time': time.time()-self.initialized
			}
		)
Пример #4
0
	def get(self, session, doc):
		try:
			user = types.User.deserialize(doc)
			start = time.time()
			user_doc = self.model.users.get(id=user.id, deserialize=False)
			end = time.time()
			return responses.success(user_doc)
		except KeyError:
			logger.warning("User %s not found." % user)
			return responses.unknown_user()
		except Exception:
			logger.error(traceback.format_exc())
			return responses.database_error("getting a set of users with query %s" % query)
		
		try:
			snuggler, data = user_data()
			event = types.UsersQueried(
				doc,
				end-start,
				1,
				snuggler,
				data
			)
			self.model.events.insert(event)
		except Exception as e:
			logger.error(traceback.format_exc())
Пример #5
0
	def query(self, session, query):
		try:
			start = time.time()
			users = list(self.model.users.query(deserialize=False, **query))
			for user in users:
				del user['desirability']['scores']
			end = time.time()
		except Exception:
			logger.error(traceback.format_exc())
			return responses.database_error("getting a set of users with query %s" % query)
		
		try:
			snuggler, data = user_data()
			event = types.UsersQueried(
				query,
				end-start,
				len(users),
				snuggler,
				data
			)
			self.model.events.insert(event)
		except Exception as e:
			logger.error(traceback.format_exc())
			
		
		return responses.success(users)
Пример #6
0
	def perform_action(self, session, doc):
		try:
			request = types.ActionRequest.deserialize(doc)
			results = self.user_actions.perform(request, session['snuggler'])
		except errors.MWAPIError as e:
			logger.error(traceback.format_exc())
			return responses.mediawiki_error("performing an action %r" % doc, e.code, e.info)
		except errors.ConnectionError as e:
			logger.error(traceback.format_exc())
			return responses.mediawiki_error("performing an action", "Connection Failed", e.info)
		except Exception as e:
			logger.error(traceback.format_exc())
			return responses.general_error("performing an action %r" % doc)
				
			
		try:
			event = types.UserActioned(
				request,
				session['snuggler'],
				results
			)
			self.model.events.insert(event)
		except Exception as e:
			logger.error(traceback.format_exc())
			
		return responses.success(True)
Пример #7
0
	def watch(self, session, doc):
		try:
			user = types.User.deserialize(doc)
			self.mwapi.pages.watch(
				"User:"******"User_talk:" + user.name,
				cookies=session['snuggler']['cookie']
			)
			
			try:
				event = types.UserWatched(
					user, 
					session['snuggler']
				)
				self.model.events.insert(event)
			except Exception as e:
				logger.error(traceback.format_exc())
			
			return responses.success(True)
			
		except errors.MWAPIError as e:
			logger.error(traceback.format_exc())
			return responses.mediawiki_error("Adding %r to watchlist " % user_name, e.code, e.info)
		except errors.ConnectionError as e:
			logger.error(traceback.format_exc())
			return responses.mediawiki_error("Adding %r to watchlist " % user_name, "Connection Failed", e.info)
		except Exception as e:
			logger.error(traceback.format_exc())
			return responses.general_error("Adding %r to watchlist " % user_name)
Пример #8
0
	def preview_action(self, session, doc):
		try:
			request = types.ActionRequest.deserialize(doc)
			results = self.user_actions.preview(request, session['snuggler'])
		except errors.MWAPIError as e:
			logger.error(traceback.format_exc())
			return responses.mediawiki_error("previewing an action %r" % doc, e.code, e.info)
		except errors.ConnectionError as e:
			logger.error(traceback.format_exc())
			return responses.mediawiki_error("previewing an action", "Connection Failed", e.info)
		except Exception as e:
			logger.error(traceback.format_exc())
			return responses.general_error("previewing an action %r" % doc)
			
		return responses.success([result.serialize() for result in results])
Пример #9
0
	def view(self, session, doc):
		try:
			self.model.users.add_view(doc['id'])
		except Exception:
			logger.error(traceback.format_exc())
			return responses.database_error("storing a view for user %s" % user_id)
		
		try:
			user = types.User(doc['id'], doc['name'])
			event = types.UserViewed(
				user, 
				session['snuggler']
			)
			self.model.events.insert(event)
		except Exception as e:
			logger.error(traceback.format_exc())
		
		return responses.success(True)
Пример #10
0
	def query(self, session, query):
		"""
		Queries for PUBLIC events and public event content only.
		"""
		try:
			start = time.time()
			event_docs = []
			for event in self.model.events.query(**query):
				if event.PUBLIC:
					doc = event.serialize()
					doc['id'] = None
					event_docs.append(doc)
				
			
			end = time.time()
		except Exception:
			logger.error(traceback.format_exc())
			return responses.database_error("getting a set of events with query %s" % query)
		
		query['after'] = max(
			query.get('after', 0), 
			time.time() - configuration.snuggle['changes_synchronizer']['max_age']
		)
		
		try:
			snuggler, data = user_data()
			event = types.EventsQueried(
				query,
				end-start,
				len(event_docs),
				snuggler,
				data
			)
			self.model.events.insert(event)
		except Exception as e:
			logger.error(traceback.format_exc())
			
		
		return responses.success(event_docs)
Пример #11
0
	def categorize(self, session, data):
		try:
			categorization = types.Categorization(session['snuggler'], data['category'], data['comment'])
			doc = self.model.users.categorize(
				data['id'], 
				types.Categorization(session['snuggler'], data['category'], data['comment'])
			)
			
			try:
				user = types.User(data['id'], data['name'])
				event = types.UserCategorized(
					user, 
					categorization
				)
				self.model.events.insert(event)
			except Exception as e:
				logger.error(traceback.format_exc())
			
			return responses.success(doc)
		except Exception:
			logger.error(traceback.format_exc())
			return responses.database_error("storing a categorization for user %s" % data)
Пример #12
0
	def reload_talk(self, session, doc):
		logger.debug("Reloading talk for %s" % doc)
		try:
			if 'id' in doc:
				user = self.model.users.get(id=doc['id'])
			else:
				user = self.model.users.get(name=doc['name'])
			
			rev_id, markup = self.mwapi.pages.get_markup(title="User_talk:" + user.name)
			talk = self.model.users.update_talk(user.id, rev_id, markup)
			if rev_id != None: self.model.users.set_talk_page(user.name)
			return responses.success(talk.serialize())
		except KeyError as e:
			logger.error(traceback.format_exc())
			return responses.general_error(
				"reloading the talk page for %s" % doc
			)
		except Exception as e:
			logger.error(traceback.format_exc())
			return responses.general_error(
				"reloading the talk page for %s" % doc
			)
Пример #13
0
	def help(self, data):
		path = os.path.join(self.static_dir, "help", "%(lang)s.html" % data)
		
		f = open(path)
		
		return responses.success(f.read())