فهرست منبع

Updated: Don't look by hours, look by days.

Steve Thielemann 5 سال پیش
والد
کامیت
1b984b72ec
1فایلهای تغییر یافته به همراه8 افزوده شده و 11 حذف شده
  1. 8 11
      ubuntu_load.py

+ 8 - 11
ubuntu_load.py

@@ -22,7 +22,7 @@ import argparse
 parser = argparse.ArgumentParser()
 parser.add_argument("-e", "--expire", type=int, help="Expire files after this many days.", default=7)
 parser.add_argument("-f", "--fresh", help="Download fresh copy of RSS feed.", action="store_true")
-parser.add_argument("--hours", type=int, help="Number of hours (range) we consider to be new.", default=12)
+parser.add_argument("-n", "--new", type=int, help="Number of Days (range) we consider to be new.", default=2)
 parser.add_argument("-v", "--verbose", help="Display more verbose information.", action="store_true")
 args = parser.parse_args()
 
@@ -34,11 +34,11 @@ for f in os.listdir():
         age = now-created
         if age.in_days() >= args.expire:
             # Older then 7 days
+            print("Removing old file {0} ({1} >= {2}).".format(f, age.in_days(), args.expire))
             os.unlink(f)
-            print("Removed {}".format(f))
         else:
             if args.verbose:
-                print("{0} is {1} day(s) old.".format(f, age.in_days()))
+                print("Keep {0} is {1} day(s) old.".format(f, age.in_days()))
 
 
 url = 'https://usn.ubuntu.com/rss.xml'
@@ -68,18 +68,15 @@ for entry in data['entries']:
     when = pendulum.from_format(entry['published'], "ddd, D MMM YYYY HH:mm:ss ZZ")
     title = entry['title']
     age = now - when 
-    if args.verbose:
-        print("Age (in days):", age.in_days())
 
-    if age.in_hours() > args.hours:
+    if age.in_days() > args.new:
         # Skip over this old record!
         if args.verbose:
-            print("Skipping {0} : {1} hours old. {2}".format(title, age.in_hours(), when))
+            # print("Skipping {0} : {1} days old. {2}".format(title, age.in_days(), when))
+            print("Skipping {0} : {1} days old.".format(title, age.in_days()))
         continue
 
-    print("Age in hours:", age.in_hours())
-
-    print("New record:", when.to_datetime_string(), "Title:", title)
+    print("Possible:", when.to_datetime_string(), "Title:", title)
     # print(when.to_datetime_string(), title)
 
     filename = "{0}.html".format(title)
@@ -87,7 +84,7 @@ for entry in data['entries']:
     textname = textname.replace(':', '').replace(' ', '_')
 
     if not os.path.exists(filename):
-        print("Missing:", entry['published'], title)
+        print("Missing/TO Display:", entry['published'], title)
         with open(filename, "wb") as fp:
             fp.write(entry['summary'].encode('utf-8'))
         # Ok, convert into text