from operator import itemgetter
from itertools import chain

import os

import yaml
import requests

yaml.load_all

directory = "_companies"

flat = chain.from_iterable

def link_status_company(filename):
    (name, _) = filename.rsplit(".", 1);
    print("==== {name} ====".format(name=name))
    docs = filter(None, yaml.load_all(open(os.path.join(directory, filename))))
    positions = flat(map(itemgetter("positions"), filter(lambda doc: "positions" in doc, docs)))

    def link_status_position(position):
        title = position["title"]
        url = position["url"]

        print("{title} [ {url} ]".format(title=title, url=url))
        response = requests.get(url)

        status_code_description = requests.status_codes._codes.get(response.status_code, '-')

        print("{} {} {}".format(response.status_code, status_code_description, response.history))

        print()

    list(map(link_status_position, positions))

list(map(link_status_company, sorted(os.listdir(directory))))

@@ -634,16 +634,33 @@
 l=url))%0A
+        try:%0A    
         
@@ -686,19 +686,35 @@
 .get(url
-)%0A%0A
+, timeout=10)%0A%0A    
         
@@ -800,32 +800,36 @@
 , '-')%0A%0A        
+ 
+   
 print(%22%7B%7D %7B%7D %7B%7D%22
@@ -901,16 +901,68 @@
 istory))
+%0A        except Exception as e:%0A            print(e)
 %0A%0A      

Add timeout to dead links script