<commit_before>#!/usr/bin/env python
#Written for Pyhon 2.7.5
#Written by: <NAME>
#Written on 7/6/14
#Maintained @ https://github.com/walshie4/Ultimate-Blocklist

import requests
from bs4 import BeautifulSoup as mksoup
import gzip

BASE = "https://www.iblocklist.com"

def get_value_from(url):
    soup = mksoup(requests.get(BASE + url).text)
    return str(soup.find_all("input")[-1]).split("\"")[-2]

def process(url):
    contents = requests.get(url).text
    f = open("blocklist.txt", "a+")
    f.write(contents.encode("ascii", "replace"))
    f.close()

if __name__=="__main__":
    print("Getting list page")
    soup = mksoup(requests.get("https://www.iblocklist.com/lists.php").text)
    links = {}#dict of name of list -> its url
    for row in soup.find_all("tr")[1:]:#for each table row
        section = str(list(row.children)[0])
        pieces = section.split("\"")
        links[pieces[2].split("<")[0][1:]] = pieces[1]

    for link in links:#download and combine files
        print "Downloading " + link + " blocklist."
        value = get_value_from(links[link])
        if value == "subscription":
            print "Blocklist is not available for free download D:"
        else:#download and add this sucker
            process(value)
<commit_msg>Added check for if url field value returns string unavailabe<commit_after>#!/usr/bin/env python
#Written for Pyhon 2.7.5
#Written by: <NAME>
#Written on 7/6/14
#Maintained @ https://github.com/walshie4/Ultimate-Blocklist

import requests
from bs4 import BeautifulSoup as mksoup
import gzip

BASE = "https://www.iblocklist.com"

def get_value_from(url):
    soup = mksoup(requests.get(BASE + url).text)
    return str(soup.find_all("input")[-1]).split("\"")[-2]

def process(url):
    contents = requests.get(url).text
    f = open("blocklist.txt", "a+")#TODO add check for if it exists
    f.write(contents.encode("ascii", "replace"))
    f.close()

if __name__=="__main__":
    print("Getting list page")
    soup = mksoup(requests.get("https://www.iblocklist.com/lists.php").text)
    links = {}#dict of name of list -> its url
    for row in soup.find_all("tr")[1:]:#for each table row
        section = str(list(row.children)[0])
        pieces = section.split("\"")
        links[pieces[2].split("<")[0][1:]] = pieces[1]

    for link in links:#download and combine files
        print "Downloading " + link + " blocklist."
        value = get_value_from(links[link])
        if value == "subscription":
            print "Blocklist is not available for free download D:"
        elif value == "unavailable":
            print "URL is unavailable"
        else:#download and add this sucker
            process(value)

{'fraction_non_alphanumeric': 0.1508732813080639, 'fraction_numerical': 0.0126347082868822, 'mean_word_length': 3.2460567823343847, 'pattern_counts': {'":': 5, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3583005', 'n_tokens_mistral': 902, 'n_tokens_neox': 878, 'n_words': 226}