Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Awesome-Scripts/.DS_Store
Binary file not shown.
19 changes: 11 additions & 8 deletions Awesome-Scripts/hackernews.py
Original file line number Diff line number Diff line change
@@ -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=' ' )
Expand All @@ -24,7 +31,3 @@
print( title.text )
print( title['href'] )
print( " " )

count = count + 1

if count == 10: break