Take filename from command line arguments, add copyright and better readme text.
authorFabien Ninoles <fabien@tzone.org>
Sun, 26 Aug 2012 22:18:29 -0400
changeset 2 3675dd7daf59
parent 1 fb1ab147b2dd
child 3 478647351440
Take filename from command line arguments, add copyright and better readme text.
update-hib.py
--- a/update-hib.py	Sun Aug 26 22:03:23 2012 -0400
+++ b/update-hib.py	Sun Aug 26 22:18:29 2012 -0400
@@ -1,4 +1,21 @@
 #!/usr/bin/python3
+#
+# Update HIB - Scrapper for the HumbleBundle library page.
+# Copyright (C) 2012, Fabien Ninoles <- fabien - AT - tzone . org ->
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
 
 from html.parser import HTMLParser
 from pprint import pprint
@@ -247,35 +264,39 @@
     def __call__(self, dls):
         return self.chooseDownloads(dls)
 
-selector = FileSelector()
+def main(fn):
+    selector = FileSelector()
+    downloads = []
+    for game in parseGamesFromFile(fn):
+        for dls in game.downloads:
+            scores = selector(dls)
+            choosen = list(dl for score, dl in scores if score >= 0)[:1]
+            for score, dl in scores:
+                print("[%s] %2d | %-20s | %-10s | %-25s | %s " % (
+                        "*" if dl in choosen else " ",
+                        score,
+                        game.title, 
+                        dls.id,
+                        ", ".join(sorted(dl.attrs)),
+                        dl.torrent))
+                if dl in choosen:
+                    downloads.append(dl)
+            if not scores:
+                print("No download for",dls.id)
+            print("-" * 80)
 
-downloads = []
-for game in parseGamesFromFile("tidy_bundle.html"):
-    for dls in game.downloads:
-        scores = selector(dls)
-        choosen = list(dl for score, dl in scores if score >= 0)[:1]
-        for score, dl in scores:
-            print("[%s] %2d | %-20s | %-10s | %-25s | %s " % (
-                    "*" if dl in choosen else " ",
-                    score,
-                    game.title, 
-                    dls.id,
-                    ", ".join(sorted(dl.attrs)),
-                    dl.torrent))
-            if dl in choosen:
-                downloads.append(dl)
-        if not scores:
-            print("No download for",dls.id)
-        print("-" * 80)
+    import urllib.request
+    import urllib.parse
+    import os
+    opener = urllib.request.build_opener()
+    for dl in downloads:
+        fn = os.path.basename(urllib.parse.urlsplit(dl.torrent).path)
+        print("Saving",dl.torrent,"as",fn)
+        with opener.open(dl.torrent) as u:
+            with open(fn,"wb") as f:
+                f.write(u.read())
 
-import urllib.request
-import urllib.parse
-import os
-opener = urllib.request.build_opener()
-for dl in downloads:
-    fn = os.path.basename(urllib.parse.urlsplit(dl.torrent).path)
-    print("Saving",dl.torrent,"as",fn)
-    with opener.open(dl.torrent) as u:
-        with open(fn,"wb") as f:
-            f.write(u.read())
 
+if __name__ == '__main__':
+    import sys
+    main(sys.argv[1])