from datetime import timedelta

from core import fetch_day, decompress, dump


SATURDAY = 5


def dates(start, end):
    if start > end:
        return
    end = end + timedelta(days=1)
    while start != end:
        if start.weekday() is not SATURDAY:
            yield start
        start = start + timedelta(days=1)


def fetch_ticks(symbols, start, end):
    for symbol in symbols:
        for date in dates(start, end):
            dump(symbol, decompress(date, fetch_day(symbol, date)))


@@ -1,12 +1,24 @@
+import time%0A
 from datetim
@@ -35,16 +35,46 @@
 imedelta
+%0Afrom collections import deque
 %0A%0Afrom c
@@ -366,40 +366,901 @@
 ef f
-etch_ticks(symbols, start, end):
+ormat_seconds(seconds):%0A    if seconds %3C 0:%0A        return %22--:--:--%22%0A    m, s = divmod(seconds, 60)%0A    h, m = divmod(m, 60)%0A    return %22%25d:%2502d:%2502d%22 %25 (h, m, s)%0A%0A%0Adef update_progress(done, total, avg_time_per_job):%0A    progress = done / total%0A    progress = int((1.0 if progress %3E 1.0 else progress) * 100)%0A    remainder = 100 - progress%0A    estimation = avg_time_per_job * (total - done)%0A    print('%5Cr%5B%7B0%7D%5D %7B1%7D%25  Left : %7B2%7D  '.format('#' * progress + '-' * remainder, progress, format_seconds(estimation)),%0A          end='')%0A%0A%0Adef how_many_days(start, end):%0A    delta_days = (end - start).days%0A    saturday_counter = delta_days / 7%0A    return delta_days - saturday_counter%0A%0A%0Adef fetch_ticks(symbols, start, end):%0A    if start %3E end:%0A        return%0A%0A    fetched_days = 0%0A    days = how_many_days(start, end)%0A%0A    last_fetch = deque(%5B%5D, maxlen=3)%0A    update_progress(fetched_days, days, -1)%0A
 %0A   
@@ -1318,24 +1318,60 @@
 tart, end):%0A
+            star_time = time.time()%0A
             
@@ -1425,10 +1425,178 @@
  date)))
+%0A            last_fetch.append(time.time() - star_time)%0A            fetched_days += 1%0A            update_progress(fetched_days, days, sum(last_fetch) / len(last_fetch))
 %0A%0A

Add stats