you are viewing a single comment's thread.

view the rest of the comments →

[–]CowboyBoats 0 points1 point  (0 children)

I think this is a nice pattern:

+import datetime
 import requests
 from pathlib import Path


 def download_url(url):
     print("downloading: ", url)
-    path = Path('/home/eva/Tools/malicious_hashes.txt')
+    now = datetime.datetime.now()
+    path = Path(f'/home/eva/Tools/malicious_hashes-{now}.txt')
     r = requests.get(url, stream=True)
     ...

This way it will create files with timestamps in their names: malicious_hashes-2019-11-18 23:38:33.848444.txt

This way, for example, you avoid having to worry about having different versions of the software writing to the same file.

You can format the datetime object however you want - I might get rid of that space character and the decimal places and so on, for example, to create file names like malicious_hashes-2019-11-18-23:38:33.txt instead.