示例#1
0
def blog_posts(username):
    """
    Count number of posts on a student's
    blog.

    """

    student_data = None
    yaml_dir = 'scripts/people/'
    fname = os.path.join(yaml_dir, username + ".yaml")
    with open(fname) as student:
        contents = yaml.load(student)
        if not isinstance(contents, list):
            raise ValueError("%s's yaml file is broken." % fname)
        student_data = contents[0]

    num_posts = 0
    if 'feed' in student_data:
        print("Checking %s's blog feed." % username)
        num_posts = count_posts(student_data['feed'], COURSE_START)
    else:
        print("No feed listed for %s!" % username)
        raise NotFound()

    return jsonify(number=num_posts)
示例#2
0
文件: site.py 项目: dxa4481/hflossk
def blog_posts(username):
    """
    Count number of posts on a student's
    blog.

    """

    student_data = None

    fname = username

    for dirpath, dirnames, files in os.walk("scripts/people/"):
        for fname in files:
            if str(username + '.yaml').lower() in fname.lower():
                with open(dirpath + '/' + fname) as students:
                    contents = yaml.load(students)
                    student_data = contents

    num_posts = 0
    if 'feed' in student_data:
        print("Checking %s's blog feed." % username)
        num_posts = count_posts(student_data['feed'], COURSE_START)
    else:
        print("No feed listed for %s!" % username)
        raise NotFound()

    return jsonify(number=num_posts)
示例#3
0
def blog_posts(username):
    """
    Count number of posts on a student's
    blog.

    """

    student_data = None

    for dirpath, dirnames, files in os.walk(YAML_LOCATION):
        for fname in files:
            if (username + '.yaml').lower() == fname.lower():
                with open(os.path.join(dirpath, fname)) as student_file:
                    student_data = yaml.load(student_file)

    if 'feed' in student_data:
        print("Checking %s's blog feed." % username)
        return jsonify(number=count_posts(student_data['feed'], COURSE_START))
    else:
        print("No feed listed for %s!" % username)
        raise NotFound()
示例#4
0
def blog_posts(username):
    """
    Count number of posts on a student's
    blog.

    """

    student_data = None

    fname = username
    with open(fname) as student:
        contents = yaml.load(student)
        student_data = contents

    num_posts = 0
    if 'feed' in student_data:
        print("Checking %s's blog feed." % username)
        num_posts = count_posts(student_data['feed'], COURSE_START)
    else:
        print("No feed listed for %s!" % username)
        raise NotFound()

    return jsonify(number=num_posts)
示例#5
0
文件: site.py 项目: ryansb/hflossk
def blog_posts(username):
    """
    Count number of posts on a student's
    blog.

    """

    student_data = None

    fname = username
    with open(fname) as student:
        contents = yaml.load(student)
        student_data = contents

    num_posts = 0
    if 'feed' in student_data:
        print("Checking %s's blog feed." % username)
        num_posts = count_posts(student_data['feed'], COURSE_START)
    else:
        print("No feed listed for %s!" % username)
        raise NotFound()

    return jsonify(number=num_posts)