Skip to content

Instantly share code, notes, and snippets.

@rohan-molloy
Created October 20, 2023 12:41
Show Gist options
  • Save rohan-molloy/0f9a0ba0dfe7d211b9c902f05f73352f to your computer and use it in GitHub Desktop.
Save rohan-molloy/0f9a0ba0dfe7d211b9c902f05f73352f to your computer and use it in GitHub Desktop.
import requests
import os
import uuid
import hashlib
def download_file_hash(url, extension='txt'):
response = requests.get(url)
if response.status_code == 200:
sha256hash = hashlib.sha256(response.content).hexdigest()
filename = f'{sha256hash}.{extension}'
with open(filename, 'wb') as file:
file.write(response.content)
return filename
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment