def show_popular_authors(): try: print("2. Who are the most popular article authors of all time?\n") authors = newsdb.get_popular_authors() for author in authors: print(author[0] + " - " + str(author[1]) + " Views.") except BaseException: print("Error occurred showing popular authors")
def main(): '''Main page of the forum.''' # posts = "".join(POST % (title, popularity) for title, popularity in get_popular_articles()) # html = HTML_WRAP % posts # return html posts1 = "".join(POST1 % (name, popularity) for name, popularity in get_popular_authors()) html1 = HTML_WRAP % posts1 return html1
def get_popular_authors_report(): """ This method gets a list of popular authors from newsdb module and sends it to a method for writing a file along with the file name. """ filename = "popularAuthors.text" authors = newsdb.get_popular_authors() print(authors) if len(authors) != 0: write_file(filename, authors) else: print("Sorry, No record found!!!")
def main(argv): print("-----%s Most Popular Articles-----\n" % argv[0]) articles = "\r\n".join(VIEW_TEMPLATE % (article, views) for article, views in get_popular_articles(argv[0])) print(articles) print("\n-----%s Most Popular Authors-----\n" % argv[1]) authors = "\r\n".join(VIEW_TEMPLATE % (author, views) for author, views in get_popular_authors(argv[1])) print(authors) pct = float(argv[2]) / 100.0 print( "\n-----Days HTTP Error Status Exceeded %3.2f%%-----\n" % (pct * 100)) days = "\r\n".join(ERR_TEMPLATE % (day.strftime("%B %d, %Y"), percentage) for day, percentage in get_errs_day_pct(pct)) print(days) return
output_file.write(content) output_file.close() return output_file # What are the most popular three articles of all time? popular_articles = get_popular_articles() popular_articles1 = (popular_articles[0][0] + " -- " + str(popular_articles[0][1]) + " views") popular_articles2 = (popular_articles[1][0] + " -- " + str(popular_articles[1][1]) + " views") popular_articles3 = (popular_articles[2][0] + " -- " + str(popular_articles[2][1]) + " views") # Who are the most popular article authors of all time? popular_authors = get_popular_authors() most_popular_authors = "" for author in popular_authors: most_popular_authors += ("<li>" + author[0] + " -- " + str(author[1]) + " views</li>") # On which days did more than 1% of requests lead to errors? status_result = get_status_result() not_found_result = get_not_found_result() result = {} for i in range(len(status_result)): if status_result[i][0] == not_found_result[i][0]: error = float(not_found_result[i][1]) / float(status_result[i][1]) if error > 0.01: result[status_result[i][0]] = error