I want Python to print out strings while a process is happening, such as the download in the script below. However, I'm finding it difficult. For example, maybe I want Python to say after 10 seconds of download, "Hey, it's been 10 secs." I can put the start time only before the process, and the end time only after the process, which means I can't track while the download is happening.
import requests, re, time
link = "https://web.archive.org/cdx/search/cdx?url=twitter.com/realdonaldtrump/status&matchType=prefix&filter=statuscode:200"
response = requests.head(link).text
urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', response)
for url in urls:
start = time.time()
data2.append(f"{url}")
end = time.time()
time_elapsed = end - start
if time_elapsed >= 10:
print("It's been 10 seconds.")