Skip to content

Instantly share code, notes, and snippets.

@vinzBad

vinzBad/archnews.py

Last active Nov 16, 2017
Embed
What would you like to do?
Quick and dirty snippet to get the latest ArchLinux - News
#!/usr/bin/python
"""
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2017 Vinzenz Johann Sinapius <vinzenz.sinapius@gmail.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
"""
import requests
from lxml import html
SITE = "https://www.archlinux.org/news/"
TBODY_XPATH = "/html/body/div[2]/div[2]/table/tbody"
NEWS_COUNT = 4
if __name__ == "__main__":
page = requests.get(SITE)
tree = html.fromstring(page.content)
table = tree.xpath(TBODY_XPATH)[0]
count = 0
for element in table.getchildren():
tds = element.getchildren()
timestamp = tds[0].text
title = tds[1].getchildren()[0].text.strip()
print("%s\t%s" % (timestamp, title))
count += 1
if count >= NEWS_COUNT:
break
@vinzBad

This comment has been minimized.

Copy link
Owner Author

@vinzBad vinzBad commented Nov 16, 2017

added license

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment