Add my latest download script
- ID
7cf8f35- date
2022-03-19 09:37:46+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
d720cf0- message
Add my latest download script- changed files
1 file, 33 additions
Changed files
latest_download (0) → latest_download (713)
diff --git a/latest_download b/latest_download
new file mode 100755
index 0000000..5b004e2
--- /dev/null
+++ b/latest_download
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+"""
+This script prints the path to the newest file in my Downloads folder.
+
+I use it when I've downloaded a file in my web browser, and I want
+to use that file immediately without checking what its filename is.
+"""
+
+import datetime
+import os
+
+
+def get_downloads():
+ downloads_dir = os.path.join(os.environ["HOME"], "Downloads")
+
+ for f in os.listdir(downloads_dir):
+ p = os.path.join(downloads_dir, f)
+
+ if not os.path.isfile(p):
+ continue
+
+ if f == ".DS_Store":
+ continue
+
+ yield p
+
+
+def downloaded_time(p):
+ return os.stat(p).st_mtime
+
+
+if __name__ == "__main__":
+ print(max(get_downloads(), key=lambda p: downloaded_time(p)))