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)
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)
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()
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)