-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.2.py
92 lines (75 loc) · 2.74 KB
/
timer.2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import cronus.beat as beat
import time
import datetime
import wget
def getTime():
x = datetime.datetime.now()
xs = x.strftime("%X %x")
datestring = str(xs)
datestring = datestring.replace(":", "-")
datestring = datestring.replace("/", "-")
datestring = datestring.replace(" ", "--")
#print(datestring)
return datestring
def download(url, filefolder):
print(url)
print(filefolder)
import sys
import requests
def download(url, filename):
with open(filename, 'wb') as f:
response = requests.get(url, stream=True)
total = response.headers.get('content-length')
if total is None:
f.write(response.content)
else:
downloaded = 0
total = int(total)
for data in response.iter_content(chunk_size=max(int(total/1000), 1024*1024)):
downloaded += len(data)
f.write(data)
done = int(50*downloaded/total)
sys.stdout.write('\r[{}{}]'.format('█' * done, '.' * (50-done)))
sys.stdout.flush()
sys.stdout.write('\n')
print('[*] Download started')
#download('https://speed.hetzner.de/100MB.bin', '100MB.bin')
download(url, filefolder)
print('[*] Download Done!')
pass
def download_old(url, filefolder):
print("Download started")
#myfile = requests.get(url, allow_redirects=True)
def bar_custom(current, total, width=80):
#self.flag_download_current = current
#self.flag_download_total = total
#self.flag_download_percent = current / total * 100
print("Downloading: %d%% [%d / %d] bytes" %
(current / total * 100, current, total))
#wget.download(url, bar=bar_custom)
wget.download(url, filefolder, bar=bar_custom)
#wget.download(url, filefolder)
#open(filefolder, 'wb').write(myfile.content)
print("Download finished")
pass
def do_some_work():
#time.sleep(0.3)
print()
url = "https://www.google.com/favicon.ico"
url = "http://212.183.159.230/5MB.zip"
url = "http://212.183.159.230/100MB.zip"
url = "http://212.183.159.230/512MB.zip"
url = "https://sisa.msal.gov.ar/datos/descargas/covid-19/files/Covid19Casos.csv"
filename = url.split('/')[-1].split('.')[0]
file_ext = '.'+url.split('.')[-1]
filenamevar = filename+" - "+getTime()+""+file_ext
download(url,filenamevar)
import cronus.beat as beat
#beat.set_rate(1/60) # 2 Hz
#beat.set_rate(1/(60*15)) # 2 Hz
beat.set_rate(1/(60*1)) # 1 minute
while beat.true():
# do some time consuming work here
do_some_work()
print("Now the system is up to date")
beat.sleep() # total loop duration would be 0.5 sec