Query recent posts of catalog.
513887
def query_by_tag(cat_id, kind='1'):
        '''
        
        '''

        return TabPost.select().join(
            TabPost2Tag,
            on=(TabPost.uid == TabPost2Tag.post_id)
        ).where(
            (TabPost.kind == kind) &
            (TabPost2Tag.tag_id == cat_id)
        ).order_by(
            TabPost.time_create.desc()
        )
866029
def query_all(current_page_num=1):
        '''
        
        '''
        return TabLog.select().where(TabLog.user_id == 'None').order_by(TabLog.time_out.desc()).paginate(
            current_page_num, CMS_CFG['list_num']
        )
1343514
def get_recent_matches(session, init_url, from_timestamp, limit):
    """"""
    if not from_timestamp:
        from_timestamp = datetime.datetime.now() - datetime.timedelta(days=1)
    matches = []
    page_id = 0
    done = False
    while not done and page_id < MAX_MATCH_PAGE_ID:
        url = '{}/{}'.format(init_url, page_id)
        parsed = make_scrape_request(session, url)
        for row in parsed.find('table').find_all('tr')[1:]:
            cols = row.find_all('td')
            played_at = dateparser.parse(cols[2].text)
            match_id = int(cols[5].find('a').text[1:])
            has_rec = cols[6].find('a').find('img')
            if played_at < from_timestamp or (limit and len(matches) == limit):
                done = True
                break
            if not has_rec:
                continue
            matches.append({
                'timestamp': played_at,
                'match_id': match_id
            })
        if not matches:
            break
        page_id += 1
    return matches
324631
def lastmod(self, category):
        """"""
        lastitems = EntryModel.objects.published().order_by('-modification_date').filter(categories=category).only('modification_date')
        return lastitems[0].modification_date
1155716
def posts(self):
        """"""
        rev = int(self.db.get('site:rev'))
        if rev != self.revision:
            self.reload_site()

        return self._posts
406005
def recent_articles(limit=10, exclude=None):
    """"""
    queryset = Article.objects.filter(published=True).order_by('-modified')
    if exclude:
        if hasattr(exclude, '__iter__'):
            queryset = queryset.exclude(pk__in=exclude)
        else:
            queryset = queryset.exclude(pk=exclude)
    return queryset
442660
def prev_listing(self, limit=None):
        
        if self.before:
            return self._reddit._limit_get(self._path, eparams={'before': self.before}, limit=limit or self._limit)
        else:
            raise NoMoreError('no previous items')
827109
def get_queryset(self):
        
        self.topic = self.get_topic()
        qs = (
            self.topic.posts
            .all()
            .exclude(approved=False)
            .select_related('poster', 'updated_by')
            .prefetch_related('attachments', 'poster__forum_profile')
        )
        return qs
898561
def __get_diff_recent():
    '''
    
    '''
    diff_str = ''

    for key in router_post:
        recent_posts = MPost.query_recent_edited(tools.timestamp() - TIME_LIMIT, kind=key)
        for recent_post in recent_posts:
            hist_rec = MPostHist.get_last(recent_post.uid)
            if hist_rec:
                raw_title = hist_rec.title
                new_title = recent_post.title

                infobox = diff_table(raw_title, new_title)

                diff_str = diff_str + '''
                <h2 style="color:red;font-size:larger;font-weight:70;">TITLE: {0}</h2>
                '''.format(recent_post.title) + infobox

                infobox = diff_table(hist_rec.cnt_md, recent_post.cnt_md)

                diff_str = diff_str + '<h3>CONTENT:{0}</h3>'.format(
                    recent_post.title
                ) + infobox + '</hr>'
            else:
                continue
    return diff_str
691827
def refresh_cache(self, cat_id):
        '''
        
        '''        
        self.cache[cat_id] = most_recent_25_posts_by_category(cat_id)
        self.last_refresh[cat_id] = datetime.now()
        print ('Cache refresh at...', str(self.last_refresh[cat_id]))
808447
function query_posts()
   	{
   		// vars
   		$r = array(
   			'next_page_exists' => 1,
   			'html' => ''
   		);
   		
   		
   		// options
		$options = array(
			'post_type'					=>	'all',
			'taxonomy'					=>	'all',
			'posts_per_page'			=>	10,
			'paged'						=>	1,
			'orderby'					=>	'title',
			'order'						=>	'ASC',
			'post_status'				=>	'any',
			'suppress_filters'			=>	false,
			's'							=>	'',
			'lang'						=>	false,
			'update_post_meta_cache'	=>	false,
			'field_key'					=>	'',
			'nonce'						=>	'',
			'ancestor'					=>	false,
		);
		
		$options = array_merge( $options, $_POST );
		
		
		// validate
		if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') )
		{
			die();
		}
		
		
		// WPML
		if( $options['lang'] )
		{
			global $sitepress;
			
			if( !empty($sitepress) )
			{
				$sitepress->switch_lang( $options['lang'] );
			}
		}
		
		
		// convert types
		$options['post_type'] = explode(',', $options['post_type']);
		$options['taxonomy'] = explode(',', $options['taxonomy']);
		
		
		// load all post types by default
		if( in_array('all', $options['post_type']) )
		{
			$options['post_type'] = apply_filters('acf/get_post_types', array());
		}
		
		
		// attachment doesn't work if it is the only item in an array???
		if( is_array($options['post_type']) && count($options['post_type']) == 1 )
		{
			$options['post_type'] = $options['post_type'][0];
		}
		
		
		// create tax queries
		if( ! in_array('all', $options['taxonomy']) )
		{
			// vars
			$taxonomies = array();
			$options['tax_query'] = array();
			
			foreach( $options['taxonomy'] as $v )
			{
				
				// find term (find taxonomy!)
				// $term = array( 0 => $taxonomy, 1 => $term_id )
				$term = explode(':', $v); 
				
				
				// validate
				if( !is_array($term) || !isset($term[1]) )
				{
					continue;
				}
				
				
				// add to tax array
				$taxonomies[ $term[0] ][] = $term[1];
				
			}
			
			
			// now create the tax queries
			foreach( $taxonomies as $k => $v )
			{
				$options['tax_query'][] = array(
					'taxonomy' => $k,
					'field' => 'id',
					'terms' => $v,
				);
			}
		}
		
		unset( $options['taxonomy'] );
		
		
		// load field
		$field = array();
		if( $options['ancestor'] )
		{
			$ancestor = apply_filters('acf/load_field', array(), $options['ancestor'] );
			$field = acf_get_child_field_from_parent_field( $options['field_key'], $ancestor );
		}
		else
		{
			$field = apply_filters('acf/load_field', array(), $options['field_key'] );
		}
		
		
		// get the post from which this field is rendered on
		$the_post = get_post( $options['post_id'] );
		
		
		// filters
		$options = apply_filters('acf/fields/relationship/query', $options, $field, $the_post);
		$options = apply_filters('acf/fields/relationship/query/name=' . $field['_name'], $options, $field, $the_post );
		$options = apply_filters('acf/fields/relationship/query/key=' . $field['key'], $options, $field, $the_post );
		
		
		// query
		$wp_query = new WP_Query( $options );

		
		// global
		global $post;
		
		
		// loop
		while( $wp_query->have_posts() ) {
			
			$wp_query->the_post();
			
			
			// get title
			$title = $this->get_result($post, $field, $the_post, $options);
			
			
			// update html
			$r['html'] .= '<li><a href="' . get_permalink($post->ID) . '" data-post_id="' . $post->ID . '">' . $title .  '<span class="acf-button-add"></span></a></li>';
				
		}
		
		
		// next page
		if( (int)$options['paged'] >= $wp_query->max_num_pages ) {
			
			$r['next_page_exists'] = 0;
			
		}
		
		
		// reset
		wp_reset_postdata();
		
		
		// return JSON
		echo json_encode( $r );
		
		die();
			
	}
266549
def advanced_search(pattern):
    
    query_parsed = QUERY.parseString(pattern)
    return Entry.published.filter(query_parsed[0]).distinct()
200861
def recent(self, check_language=True, language=None, limit=3, exclude=None,
               kwargs=None, category=None):
        
        if category:
            if not kwargs:
                kwargs = {}
            kwargs['categories__in'] = [category]
        qs = self.published(check_language=check_language, language=language,
                            kwargs=kwargs)
        if exclude:
            qs = qs.exclude(pk=exclude.pk)
        return qs[:limit]
290545
def items(self):
        
        return Topic.objects.filter(forum__in=self.forums, approved=True).order_by('-last_post_on')
563452
def query(name):
    """"""
    collection = Collection.query.filter_by(name=name).one()
    click.echo(collection.dbquery)
238917
def get_posts(self, count=10, offset=0, recent=True, tag=None,
                  user_id=None, include_draft=False):
        
        query = self._client.query(kind='Post')

        if tag:
            norm_tag = self.normalize_tag(tag)
            posts_ids = self._filter_posts_by_tag(norm_tag)

            if posts_ids:
                keys = [self._client.key('Post', id) for id in posts_ids]
                posts = self._client.get_multi(keys)
            else:
                posts = []
        else:
            if user_id:
                query.add_filter('user_id', '=', user_id)
            if include_draft:
                query.add_filter('draft', '=', include_draft)
            if recent:
                query.order = ['-post_date']
            posts = list(query.fetch(offset=offset, limit=count))

        if not posts:
            return []

        res = []
        for post in posts:
            p = dict(post)
            res.append(p)

        if tag and recent:
            res = sorted(res, key=itemgetter('post_date'), reverse=True)
        elif tag and not recent:
            res = sorted(res, key=itemgetter('post_date'))

        if tag:
            res = res[offset:offset+count]

        return res
1167441
def view_entries(search_query=None):
    """"""
    if search_query:
        expr = Entry.content.search(search_query)
    else:
        expr = None

    query = Entry.query(expr, order_by=Entry.timestamp.desc())
    for entry in query:
        timestamp = entry.timestamp.strftime('%A %B %d, %Y %I:%M%p')
        print(timestamp)
        print('=' * len(timestamp))
        print(entry.content)
        print('n) next entry')
        print('d) delete entry')
        print('q) return to main menu')
        choice = raw_input('Choice? (Ndq) ').lower().strip()
        if choice == 'q':
            break
        elif choice == 'd':
            entry.delete()
            print('Entry deleted successfully.')
            break