Non-initialized variable fix. master
authorRoman Bazalevskiy <rvb@rvb.name>
Mon, 20 Sep 2021 15:50:01 +0000 (18:50 +0300)
committerRoman Bazalevskiy <rvb@rvb.name>
Mon, 20 Sep 2021 15:50:01 +0000 (18:50 +0300)
get_flibusta.py

index 64098473bba78122d023f2f6ec2aff990651db9b..fa320b2f3756c1e5847d54de0a943fa40eadc485 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 
-from BeautifulSoup import BeautifulSoup
-import urllib
+from bs4 import BeautifulSoup
+import urllib3
 import db
 import re
 import os
@@ -12,34 +12,38 @@ os.environ['no_proxy']='localhost,127.0.0.1'
 proxies = {'http': 'http://localhost:3128'}
 
 
-for host in ['flibusta.lib','flibustahezeous3.onion','flibusta.i2p']:
+for host in ['flibustahezeous3.onion','flibusta.i2p']:
 
+  matched = False 
   try:
-    print "Trying %s" % (host)
-    html_page = urllib.urlopen("http://%s/daily/" % (host))
-    html = BeautifulSoup(html_page)
-
-    os_command = "wget -c -q -P \"%s\" http://%s/daily/%s" % (db.upload_files,host,'%s')
-    matched = False 
-
-    for link in html.findAll('a'):
-      file = link.get("href")
-      print file
-      if pattern.match(file):
-        print "Pattern matched"
-        matched = True
-        if not db.TestArchive(file):
-          print "Processing %s" % file
-          if os.system(os_command % file) == 0:
-            db.MarkArchive(file)  
-            db.Commit()
+    print("Trying %s" % (host))
+    http = urllib3.PoolManager()
+    resp = http.request('GET', "http://%s/daily/" % (host))
+    if resp.status == 200:
+      html_page = resp.data.decode('utf-8')
+      html = BeautifulSoup(html_page,"html.parser")
+
+      os_command = "wget -c -q -P \"%s\" http://%s/daily/%s" % (db.upload_files,host,'%s')
+
+      for link in html.findAll('a'):
+        file = link.get("href")
+        print(file)
+        if pattern.match(file):
+          print("Pattern matched")
+          matched = True
+          if not db.TestArchive(file):
+            print("Processing %s" % file)
+            if os.system(os_command % file) == 0:
+              db.MarkArchive(file)  
+              db.Commit()
   except:
+    raise
     matched = False
 
   if matched:
     break
 
 if matched:
-  print "Got from %s" % host
+  print("Got from %s" % host)
 else:
-  print "Failed to get"
+  print("Failed to get")