获取http状态码, 如果返回状态码不是200,则会每隔5秒重新获取一次,但是不超过3次

#!/bin/env python
# -*- coding: UTF-8 -*-
# Author: 刘小懒
# example: python http_status.py ota_list

import requests
import time
import sys
from threading import Thread

def http_status(arg):
    try:
        html = requests.get(arg)
        codes = html.status_code
        a = 0
        while True:
            if codes == 200:
                print("t0", codes)
                return codes
            else:
                a = a+1
                time.sleep(5)
                if a >= 3:
                    print(codes)
                    return codes
    except:
        sys.exit(0)

if __name__ == "__main__":
    code = sys.argv[1]
    http_url = {
        "baidu": "www.baidu.com",
        "tmail": "https://www.tmail.com"
    }
    for i in http_url.keys():
        if code in i:
            http_url = http_url.get(i)
            t = Thread(target=http_status, args=(http_url,))
            t.start()