parameters: (days=7, ntags=14)
return_statement: return results[:ntags]
docstring: Returns a list of trending topics plus sheet count and author count modified in the last `days`.
docstring_summary: Returns a list of trending topics plus sheet count and author count modified in the last `days`.
docstring_tokens: Returns a list of trending topics plus sheet count and author count modified in the last days .
function: def trending_topics(days=7, ntags=14):
  	"""
  	Returns a list of trending topics plus sheet count and author count modified in the last `days`.
  	"""
  	cutoff = datetime.now() - timedelta(days=days)
  	query = {
  		"status": "public",
  		"dateModified": {"$gt": cutoff.isoformat()},
  		"viaOwner": {"$exists": 0},
  		"assignment_id": {"$exists": 0}
  	}
  
  	topics = db.sheets.aggregate([
  			{"$match": query},
  			{"$unwind": "$topics"},
  			{"$group": {"_id": "$topics.slug", "sheet_count": {"$sum": 1}, "authors": {"$addToSet": "$owner"}}},
  			{"$project": {"_id": 0, "slug": "$_id", "sheet_count": "$sheet_count", "authors": "$authors"}}], cursor={})
  
  	results = add_langs_to_topics([{
  		"slug": topic['slug'],
  		"count": topic['sheet_count'],
  		"author_count": len(topic['authors']),
  	} for topic in filter(lambda x: len(x["authors"]) > 1, topics)], use_as_typed=False, backwards_compat_lang_fields={'en': 'tag', 'he': 'he_tag'})
  	results = sorted(results, key=lambda x: -x["author_count"])
  
  
  	# For testing purposes: if nothing is trennding in specified number of days, 
  	# (because local data is stale) look at a bigger window
  	# ------
  	# Updated to return an empty array on 7/29/21 b/c it was causing a recursion error due to stale data on sandboxes
  	# or local and for folks who only had the public dump.
  	# -----------
  	if len(results) == 0:
  		return[]
  		#return trending_topics(days=180, ntags=ntags)
  
  	return results[:ntags]
function_tokens: def trending_topics ( days = 7 , ntags = 14 ) : cutoff = datetime . now ( ) - timedelta ( days = days ) query = { "status" : "public" , "dateModified" : { "$gt" : cutoff . isoformat ( ) } , "viaOwner" : { "$exists" : 0 } , "assignment_id" : { "$exists" : 0 } } topics = db . sheets . aggregate ( [ { "$match" : query } , { "$unwind" : "$topics" } , { "$group" : { "_id" : "$topics.slug" , "sheet_count" : { "$sum" : 1 } , "authors" : { "$addToSet" : "$owner" } } } , { "$project" : { "_id" : 0 , "slug" : "$_id" , "sheet_count" : "$sheet_count" , "authors" : "$authors" } } ] , cursor = { } ) results = add_langs_to_topics ( [ { "slug" : topic [ 'slug' ] , "count" : topic [ 'sheet_count' ] , "author_count" : len ( topic [ 'authors' ] ) , } for topic in filter ( lambda x : len ( x [ "authors" ] ) > 1 , topics ) ] , use_as_typed = False , backwards_compat_lang_fields = { 'en' : 'tag' , 'he' : 'he_tag' } ) results = sorted ( results , key = lambda x : - x [ "author_count" ] ) # For testing purposes: if nothing is trennding in specified number of days,  # (because local data is stale) look at a bigger window # ------ # Updated to return an empty array on 7/29/21 b/c it was causing a recursion error due to stale data on sandboxes # or local and for folks who only had the public dump. # ----------- if len ( results ) == 0 : return [ ] #return trending_topics(days=180, ntags=ntags) return results [ : ntags ]