|
|
|
|
|
by a3n
3755 days ago
|
|
Python 2. It works in FF on linuxmint at least. Save to hnlatest.py and run it from the command line, giving the url of a comment thread. It opens a new tab in your browser, latest comments at the bottom. "Tested" by inspection. :) It would have been cooler to make a bookmarklet in javascript, but I didn't want to learn javascript for this. import re
import sys
import tempfile
import urllib2
import webbrowser
try:
url = sys.argv[1]
page = urllib2.urlopen(url)
except Exception as e:
print 'How to run: python hnlatest.py url'
sys.exit(2)
items = re.findall('<a href="item[^>]+>', page.read())
items = sorted(set([x.split('=')[2].split('"')[0] for x in items]))
items = ['https://news.ycombinator.com/item?id=' + x for x in items]
with tempfile.NamedTemporaryFile(delete=False, suffix='.html') as tfile:
for i in items:
tfile.write('<a href="' + i + '">' + i + '</a>' + '<br/>\n')
webbrowser.open_new_tab('file://' + tfile.name)
|
|