[gimp-web] gimp-check-mirrors: switch from urllib.request to the requests module



commit 4cf506ae5242427b68c93c128a03a59aa5dea591
Author: Michael Schumacher <schumaml gmx de>
Date:   Fri Dec 11 17:13:19 2020 +0100

    gimp-check-mirrors: switch from urllib.request to the requests module

 tools/downloads/gimp-check-mirrors.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/tools/downloads/gimp-check-mirrors.py b/tools/downloads/gimp-check-mirrors.py
old mode 100644
new mode 100755
index 6522ab9a..b569a936
--- a/tools/downloads/gimp-check-mirrors.py
+++ b/tools/downloads/gimp-check-mirrors.py
@@ -1,9 +1,9 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import os
 import argparse
 import fileinput
-import urllib.request
+import requests
 from urllib.error import HTTPError, URLError
 import concurrent.futures
 
@@ -23,8 +23,8 @@ dgo_uri_local = dgo_uri.replace('https://download.gimp.org/pub/gimp/', '')
 dgo_uri_local = dgo_uri_local.replace('https://download.gimp.org/mirror/pub/gimp/', '')
 
 def load_url(url, timeout):
-    with urllib.request.urlopen(url, timeout=timeout) as conn:
-        return conn.read()
+    with requests.head(url, timeout=timeout) as conn:
+        return conn
 
 # read mirrors file
 # fileinput.
@@ -32,16 +32,17 @@ def load_url(url, timeout):
 with fileinput.input(files=(args.mirrorsfile), mode='r') as f: 
     for line in f:
         mirror_uri = line.strip() + dgo_uri_local      
-        request = urllib.request.Request(url=mirror_uri, method='HEAD')
         
         # future_to_url = executor.submit(load_url, request, 60)
 
         #    for future in concurrent.futures.as_completed(future_to_url):          
         try:
             #data= future.result()
-            response = urllib.request.urlopen(url=request, timeout=10)
-            print(str(response.status) + ' : ' + mirror_uri)
+            response = requests.head(url=mirror_uri, timeout=10)
+            print(str(response.status_code) + ' : ' + mirror_uri)
         except HTTPError as error:
             print(str(error.code) + ' : ' + mirror_uri)
         except URLError as error:
             print(str(error.reason) + ' : ' + mirror_uri)
+        except OSError as error:
+            print(str(error.strerror) + ' : ' + mirror_uri)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]