diff --git a/Awesome-Scripts/.DS_Store b/Awesome-Scripts/.DS_Store deleted file mode 100644 index e92482c..0000000 Binary files a/Awesome-Scripts/.DS_Store and /dev/null differ diff --git a/Awesome-Scripts/hackernews.py b/Awesome-Scripts/hackernews.py index 5f1c8d9..7efa906 100755 --- a/Awesome-Scripts/hackernews.py +++ b/Awesome-Scripts/hackernews.py @@ -1,20 +1,27 @@ #!/usr/bin/env python from __future__ import print_function +import argparse import requests from bs4 import BeautifulSoup +# check to see if a number was passed in +parser = argparse.ArgumentParser() +parser.add_argument( + 'news_count', metavar='int', type=int, choices=range(1,31), + nargs='?', default=10, + help='Then number of news items to return, from 1 to 30') + +args = parser.parse_args() + # get the front page from hacker news response = requests.request("GET", "https://news.ycombinator.com/") # convert the response to soup soup = BeautifulSoup(response.text, "lxml") -# count the things that get processed -count = 0 - # process all of the things! :D -for things in soup("tr", { "class" : "athing" }): +for things in soup("tr", { "class" : "athing" })[:args.news_count]: # get at the rank of each thing for rank in things("span", { "class" : "rank" }): print( rank.text, end=' ' ) @@ -24,7 +31,3 @@ print( title.text ) print( title['href'] ) print( " " ) - - count = count + 1 - - if count == 10: break