def concatenate_query_and_dates(start_date, end_date): date_query = u"" if start_date: testa = datetime.datetime.strptime(start_date, u'%Y-%m-%d').date() testb = datetime.datetime.strptime(end_date, u'%Y-%m-%d').date() date_query = mc.publish_date_query(testa, testb, True, True) return date_query
def split_story_count(user_mc_key, q='*', last_n_days=None): start_date = None end_date = None if last_n_days is not None: start_date = datetime.datetime.today() - datetime.timedelta( last_n_days) end_date = YESTERDAY fq = mc.publish_date_query(start_date, end_date, True, True) else: fq = None results = _cached_split_story_counts(q, fq) if last_n_days is None: if len(results['counts']) > 0: # if we are getting ALL stories, make sure bad dates don't give us super old / future ones start_date = max( MC_START_DATE, datetime.datetime.strptime(results['counts'][0]['date'], mc.SENTENCE_PUBLISH_DATE_FORMAT)) end_date = min( YESTERDAY, datetime.datetime.strptime(results['counts'][-1]['date'], mc.SENTENCE_PUBLISH_DATE_FORMAT)) results['counts'] = add_missing_dates_to_split_story_counts( results['counts'], start_date, end_date) results['total_story_count'] = sum([r['count'] for r in results['counts']]) return results
def concatenate_query_and_dates(start_date, end_date): date_query = "" if start_date: testa = datetime.datetime.strptime(start_date, '%Y-%m-%d').date() testb = datetime.datetime.strptime(end_date, '%Y-%m-%d').date() date_query = mc.publish_date_query(testa, testb, True, True) return date_query
def dates_as_filter_query(start_date, end_date): date_query = "" if start_date: testa = datetime.datetime.strptime(start_date, '%Y-%m-%d').date() testb = datetime.datetime.strptime(end_date, '%Y-%m-%d').date() date_query = mc.publish_date_query(testa, testb, True, True) return date_query
def _cached_featured_collections(): featured_collections = [] for tags_id in FEATURED_COLLECTION_LIST: coll = mc.tag(tags_id) coll['id'] = tags_id source_count_estimate = _cached_media_with_tag_page(tags_id, 0) coll['media_count'] = len(source_count_estimate) how_lively_is_this_collection = 0 # story count for media in source_count_estimate: one_weeks_before_now = datetime.datetime.now() - datetime.timedelta(days=7) start_date = one_weeks_before_now end_date = datetime.datetime.now() publish_date = mc.publish_date_query(start_date, end_date, True, True) media_query = "(media_id:{})".format(media['media_id']) + " AND (+" + publish_date + ")" how_lively_is_this_collection += _cached_source_story_count(user_mediacloud_key(), media_query) # approximate liveliness - if there are more stories than 100, we know this is a reasonably active source/collection if how_lively_is_this_collection > 100: break coll['story_count'] = how_lively_is_this_collection featured_collections.append(coll) return featured_collections
def concatenate_query_and_dates(start_date, end_date): testa = datetime.datetime.strptime(start_date, '%Y-%m-%d').date() testb = datetime.datetime.strptime(end_date, '%Y-%m-%d').date() publish_date = mc.publish_date_query(testa, testb, True, True) return publish_date