Last active
May 24, 2016 03:15
-
-
Save thurask/6771674ddc06c2b6aced1b588a8becdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import datetime | |
from concurrent.futures import ThreadPoolExecutor | |
import requests | |
from bs4 import BeautifulSoup | |
def dateparse(datestring, format): | |
stamp = datetime.datetime.strptime(datestring, format) | |
return stamp.strftime("%Y %m %d") | |
def get_soup(url, splitter=None): | |
req = requests.get(url) | |
if splitter is not None: | |
data = req.text.split(splitter[0])[splitter[1]] | |
else: | |
data = req.text | |
soup = BeautifulSoup(data, "html.parser") | |
return soup | |
def scrape_merlin(): | |
soup = get_soup("https://asuswrt.lostrealm.ca") | |
for p in soup.findAll("p"): | |
if "Stable" in p.text: | |
info = p.text.replace("\xa0", "\bDate: ") | |
break | |
splits = info.split("Date: ") | |
return splits[1], dateparse(splits[2], "%d-%b-%Y") | |
def scrape_shibby(): | |
soup = get_soup("http://tomato.groov.pl/?page_id=12") | |
for p in soup.findAll("p"): | |
if p.find("strong"): | |
info = p.text.replace("\u2013", "-") | |
break | |
splits = info.split(" - ") | |
return splits[1], dateparse(splits[0], "%Y-%m-%d") | |
def scrape_ddwrt(): | |
split = ("</head>", 1) | |
soup = get_soup("https://www.dd-wrt.com/site/support/other-downloads?path=betas%2F2016%2F", | |
splitter=split) | |
latest = soup.findAll("tr")[-1] | |
info = latest.find("td").find("a").text | |
splits = info.split("-r") | |
return "r" + splits[1], dateparse(splits[0], "%m-%d-%Y") | |
def scrape_openwrt(): | |
soup = get_soup("https://downloads.openwrt.org") | |
latest = soup.findAll("li")[0] | |
info = latest.text | |
splits = info.split("\n") | |
splits[2] = splits[2].replace("Released: ", "") | |
return splits[1], dateparse(splits[2], "%a, %d %b %Y") | |
def get_results(): | |
possibles = {"ddw": scrape_ddwrt, | |
"mer": scrape_merlin, | |
"tsh": scrape_shibby, | |
"opw": scrape_openwrt} | |
results = {key: None for key in possibles.keys()} | |
with ThreadPoolExecutor(max_workers=len(results.keys())) as tpe: | |
for key in results: | |
results[key] = tpe.submit(possibles[key]).result() | |
return results | |
def result_printer(name, values): | |
print("{0}{1}".format(name.upper(), ":" if not name.endswith(":") else "")) | |
print("\t{0} released {1}\n".format(values[0], values[1])) | |
def main(): | |
print("~~~~ROUTERCHECKER~~~~\n") | |
print("GETTING RESULTS...\n") | |
results = get_results() | |
result_printer("ASUSWRT MERLIN", results["mer"]) | |
result_printer("DD-WRT BETA", results["ddw"]) | |
result_printer("OPENWRT", results["opw"]) | |
result_printer("TOMATO (SHIBBY)", results["tsh"]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment