示例#1
0
def get_result(m, extension, inp):
    fname = TEST_FNAME + "." + extension
    try:
        m.write(inp, fname)
        read_result = m.read(fname)
    finally:
        just.remove(fname)
    return read_result
示例#2
0
def load_from_download(ingest_glob, vendor, recent_only=True, delete_existing=True):
    ingest_files = just.glob(ingest_glob)
    if not ingest_files:
        raise ValueError(f"Nothing to extract using {ingest_glob} - Aborting")
    nostalgia_input = "~/nostalgia_data/input/{}".format(vendor)
    if delete_existing:
        just.remove(nostalgia_input, allow_recursive=True)
    elif just.exists(nostalgia_input):
        raise ValueError(f"Cannot overwrite path {nostalgia_input}, pass delete_existing=True")
    fnames = sorted(ingest_files, key=os.path.getctime)
    if recent_only:
        fnames = fnames[-1:]
    for fname in fnames:
        with zipfile.ZipFile(fname, 'r') as zip_ref:
            out = os.path.expanduser(nostalgia_input)
            print("unpacking from", fname, "to", out)
            zip_ref.extractall(out)
示例#3
0
 def heartrate_intraday_filenames(self):
     start = self.member_since
     days = 0
     partials = self.filename("heartrate_intraday", "*/*.partial*.json")
     print("partials", partials)
     print("h", just.remove(partials, allow_recursive=True))
     while 1:
         d = start + timedelta(days=days)
         days += 1
         if d > date.today():
             return
         partial = ".partial_{}".format(time.time()) if d == date.today() else ""
         filename = self.filename(
             'heartrate_intraday',
             '{:04d}'.format(d.year),
             'heartrate_intraday.{:04d}.{:02d}.{:02d}{}.json'.format(
                 d.year, d.month, d.day, partial
             ),
         )
         yield d, filename
示例#4
0
def test_unsuccesful_remove():
    assert just.remove("A" * 100, 42) == 42
示例#5
0
 elif x.endswith(".csv"):
     shrynk = pdc
     tp = "CSV"
 old_size = os.path.getsize(x)
 old_total += old_size
 data = shrynk.load(x)
 new_file = shrynk.save(
     data,
     x.replace("csv_", "").replace(".csv", "").replace(".json", ""))
 comp = new_file.split(".")[-1]
 if comp == "None":
     new_size = old_size
 else:
     new_size = os.path.getsize(new_file)
 new_total += new_size
 just.remove(new_file)
 improvement = 100 - int(new_size / old_size * 100)
 if improvement > 50:
     improvement = Fore.GREEN + "{}%".format(improvement) + Fore.RESET
 elif improvement > 20:
     improvement = Fore.YELLOW + "{}%".format(improvement) + Fore.RESET
 else:
     improvement = Fore.RED + "{}%".format(improvement) + Fore.RESET
 improvement = improvement.rjust(13)
 print(
     "•",
     tp.rjust(4),
     "->",
     comp.rjust(5),
     "{} (deflated {})".format(human_readable_size(new_size, 0),
                               improvement).rjust(34),
示例#6
0
import tqdm
import sys
import just
import zipfile

if __name__ == "__main__":
    for x in tqdm.tqdm(sys.argv[1:]):
        with zipfile.ZipFile(x, "r") as zip_ref:
            zip_ref.extractall()
        just.remove(x)