Get posts of certain catid. In Json.

        根据分类ID（catid）获取 该分类下 post 的相关信息，返回Json格式
333361
def ajax_list_catalog(self, catid):
        '''
        
        '''
        out_arr = {}
        for catinfo in MPost2Catalog.query_postinfo_by_cat(catid):
            out_arr[catinfo.uid] = catinfo.title

        json.dump(out_arr, self)
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()
        )
1156306
def query_by_postid(postid, limit=5):
        '''
        
        '''
        recs = TabPostHist.select().where(
            TabPostHist.post_id == postid
        ).order_by(
            TabPostHist.time_update.desc()
        ).limit(limit)
        return recs
860020
def count_of_certain_category(cat_id, tag=''):
        '''
        
        '''

        if cat_id.endswith('00'):
            # The first level category, using the code bellow.
            cat_con = TabPost2Tag.par_id == cat_id
        else:
            cat_con = TabPost2Tag.tag_id == cat_id

        if tag:
            condition = {
                'def_tag_arr': [tag]
            }
            recs = TabPost2Tag.select().join(
                TabPost,
                on=((TabPost2Tag.post_id == TabPost.uid) & (TabPost.valid == 1))
            ).where(
                cat_con & TabPost.extinfo.contains(condition)
            )
        else:
            recs = TabPost2Tag.select().where(
                cat_con
            )

        return recs.count()
977414
function postSetTags(post_id, tags, cb) {
  var ids = _.pluck(tags, 'id')
    , q1 = 'DELETE FROM posts_tags WHERE post_id = $1'
    , q2 = 'INSERT INTO posts_tags (post_id, tag_id) VALUES ' +
    ids.map(function(id) {
      return '(' + post_id + ',' + id + ')';
    }).join(', ');

  db.getClient(function(err, client, done) {
    client.query(q1, [post_id], function(err, r) {
      if(err) { return cb(err); }
      client.query(q2, function(err, r) {
        if(err) {
          cb(err);
          done(err);
        } else {
          cb(null, r.rowCount);
          done();
        }
      });
    });
  });
}
947197
def fromid(self, item_id):
        
        if not item_id:
            raise Exception('Need an item_id for a story')
        # get details about a particular story
        soup = get_item_soup(item_id)

        # this post has not been scraped, so we explititly get all info
        story_id = item_id
        rank = -1

        # to extract meta information about the post
        info_table = soup.findChildren('table')[2]
        # [0] = title, domain, [1] = points, user, time, comments
        info_rows = info_table.findChildren('tr')

        # title, domain
        title_row = info_rows[0].findChildren('td')[1]
        title = title_row.find('a').text
        try:
            domain = title_row.find('span').string[2:-2]
            # domain found
            is_self = False
            link = title_row.find('a').get('href')
        except AttributeError:
            # self post
            domain = BASE_URL
            is_self = True
            link = '%s/item?id=%s' % (BASE_URL, item_id)

        # points, user, time, comments
        meta_row = info_rows[1].findChildren('td')[1].contents
        # [<span id="score_7024626">789 points</span>, u' by ', <a href="user?id=endianswap">endianswap</a>,
        # u' 8 hours ago  | ', <a href="item?id=7024626">238 comments</a>]

        points = int(re.match(r'^(\d+)\spoint.*', meta_row[0].text).groups()[0])
        submitter = meta_row[2].text
        submitter_profile = '%s/%s' % (BASE_URL, meta_row[2].get('href'))
        published_time = ' '.join(meta_row[3].strip().split()[:3])
        comments_link = '%s/item?id=%s' % (BASE_URL, item_id)
        try:
            num_comments = int(re.match(r'(\d+)\s.*', meta_row[
                4].text).groups()[0])
        except AttributeError:
            num_comments = 0
        story = Story(rank, story_id, title, link, domain, points, submitter,
                      published_time, submitter_profile, num_comments,
                      comments_link, is_self)
        return story
1141856
def get_by_uid(post_id):
        '''
        
        '''
        return TabPost2Tag.select(
            TabPost2Tag,
            TabTag.name.alias('tag_name'),
            TabTag.uid.alias('tag_uid')
        ).join(
            TabTag, on=(TabPost2Tag.tag_id == TabTag.uid)
        ).where(
            (TabPost2Tag.post_id == post_id) & (TabTag.kind == 'z')
        )
47819
def fetch_related(self, ids):
        
        if not ids:
            return []
        meta = '&id='.join(id['Id'] for id in ids)
        url = ('{url}/meta/any?id={meta}'
               '&include=bundle-metadata&include=stats'
               '&include=supported-series&include=extra-info'
               '&include=bundle-unit-count&include=owner').format(
                   url=self.url, meta=meta)
        data = self._get(url)
        return data.json().values()
454779
def get_netid_categories(netid, category_codes):
    
    url = _netid_category_url(netid, category_codes)
    response = get_resource(url)
    return _json_to_categories(response)
110347
function fetchPosts({state, actions, opts: {api}}, reddit) {
	let posts = state.postsByReddit[reddit]

	if (_shouldFetchPosts(posts)) {
		api.fetchPosts(reddit)
			.then(json => actions.postsFetched(reddit, json))

		return {
			...state,
			postsByReddit: {
				...state.postsByReddit,
				[reddit]: Object.assign({}, posts, {
					isFetching: true, 
					didInvalidate: false, 
					posts: []
				})
			}
		}

	}

	return state
}
455109
def (cat_id, label=None, num=8, kind='1', order=False):
        '''
        
        '''
        if order:
            sort_criteria = TabPost.order.asc()
        else:
            sort_criteria = TabPost.time_create.desc()

        return TabPost.select().join(
            TabPost2Tag,
            on=(TabPost.uid == TabPost2Tag.post_id)
        ).where(
            (TabPost.kind == kind) &
            (TabPost2Tag.tag_id == cat_id) &
            (TabPost.extinfo['def_tag_arr'].contains(label))
        ).order_by(
            sort_criteria
        ).limit(num)
1256012
private function get_json_for_post_request($body, $contextid, $typeid) {
        global $CFG, $DB;

        $json = json_decode($body);
        if (empty($json) ||
                !isset($json->scoreMaximum) ||
                !isset($json->label)) {
            throw new \Exception(null, 400);
        }
        if (is_numeric($json->scoreMaximum)) {
            $max = $json->scoreMaximum;
        } else {
            throw new \Exception(null, 400);
        }
        require_once($CFG->libdir.'/gradelib.php');
        $resourceid = (isset($json->resourceId)) ? $json->resourceId : '';
        $ltilinkid = (isset($json->ltiLinkId)) ? $json->ltiLinkId : null;
        if ($ltilinkid != null) {
            if (is_null($typeid)) {
                if (!gradebookservices::check_lti_id($ltilinkid, $contextid, $this->get_service()->get_tool_proxy()->id)) {
                    throw new \Exception(null, 403);
                }
            } else {
                if (!gradebookservices::check_lti_1x_id($ltilinkid, $contextid, $typeid)) {
                    throw new \Exception(null, 403);
                }
            }
        }
        $tag = (isset($json->tag)) ? $json->tag : '';
        if (is_null($typeid)) {
            $toolproxyid = $this->get_service()->get_tool_proxy()->id;
            $baseurl = null;
        } else {
            $toolproxyid = null;
            $baseurl = lti_get_type_type_config($typeid)->lti_toolurl;
        }
        $params = array();
        $params['itemname'] = $json->label;
        $params['gradetype'] = GRADE_TYPE_VALUE;
        $params['grademax']  = $max;
        $params['grademin']  = 0;
        $item = new \grade_item(array('id' => 0, 'courseid' => $contextid));
        \grade_item::set_properties($item, $params);
        $item->itemtype = 'manual';
        $item->idnumber = $resourceid;
        $item->grademax = $max;
        $id = $item->insert('mod/ltiservice_gradebookservices');
        $DB->insert_record('ltiservice_gradebookservices', (object)array(
                'gradeitemid' => $id,
                'courseid' => $contextid,
                'toolproxyid' => $toolproxyid,
                'typeid' => $typeid,
                'baseurl' => $baseurl,
                'ltilinkid' => $ltilinkid,
                'tag' => $tag
        ));
        if (is_null($typeid)) {
            $json->id = parent::get_endpoint() . "/{$id}/lineitem";
        } else {
            $json->id = parent::get_endpoint() . "/{$id}/lineitem?type_id={$typeid}";
        }
        return json_encode($json, JSON_UNESCAPED_SLASHES);

    }
213372
public function find($postId, $columns = ['*'])
    {
        $cache_key = (is_array($columns) && $columns[ 0 ] == '*') ? 'post_' . $postId : 'post_' . md5($postId . http_build_query($columns));

        // See if we've the post cached earlier in this request and return it if it's available
        if (Cache::tags(['posts', 'post_' . $postId])->has($cache_key)) {
            return Cache::tags(['posts', 'post_' . $postId])->get($cache_key);
        } else {
            // Eventually we try to fetch the post from the database or return an error
            try {
                $post = $this->postRepository->findOrFail($postId, $columns);
                // Cache it using the caching system
                Cache::tags(['posts', 'post_' . $postId])
                     ->put($cache_key, $post, \Option::get('posts_cache_expires', 60));

                return $post;
            } catch (\Exception $e) {
                return null;
            }
        }
    }
371034
def loadCats(self, ids=[]):
        
        if _isArrayLike(ids):
            return [self.cats[id] for id in ids]
        elif type(ids) == int:
            return [self.cats[ids]]
123390
def get_explore_posts(self) -> Iterator[Post]:
        
        data = self.context.get_json('explore/', {})
        yield from (Post(self.context, node)
                    for node in self.context.graphql_node_list("df0dcc250c2b18d9fd27c5581ef33c7c",
                                                               {}, 'https://www.instagram.com/explore/',
                                                               lambda d: d['data']['user']['edge_web_discover_media'],
                                                               data['rhx_gis']))
489837
function getPostQuery(body) {
  if (!body) return {};

  let result = {};
  let commentReg = /^\[(\w+)\]\:([\s|\S]+)/;
  body.split('\r\n').every((item) => {
    let itemMatch = item.match(commentReg);
    if (itemMatch && itemMatch.length == 3) {
      let queryKey = itemMatch[1],
        queryVal = itemMatch[2];
      result[queryKey] = queryVal && queryVal.trim();
      return true;
    } else {
      return false;
    }
  })

  return result;
}
81864
def post(self, path, data, is_json=True):
        ''''''
        post_data = {
            'client_id': self.client_id,
            'secret': self.secret,
        }
        post_data.update(data)
        return self._post(path, post_data, is_json)