-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbite_317.py
More file actions
40 lines (32 loc) · 1.14 KB
/
bite_317.py
File metadata and controls
40 lines (32 loc) · 1.14 KB
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
from datetime import date
import os
from pathlib import Path
import pickle
from typing import Sequence, NamedTuple
from urllib.request import urlretrieve
url = "https://bites-data.s3.us-east-2.amazonaws.com"
PICKLE_INFILE = "https://bites-data.s3.us-east-2.amazonaws.com/input.pkl"
PICKLE_OUTFILE = "https://bites-data.s3.us-east-2.amazonaws.com/output.pkl"
class MovieRented(NamedTuple):
title: str
price: int
date: date
def download_pickle_file():
"""download a pickle file we created with a
list of namedtuples
"""
download = urlretrieve(url)
return download
def deserialize(pkl_file: Path = PICKLE_INFILE) -> Sequence[NamedTuple]:
"""Load the list of namedtuples from the pickle file passed in"""
f = urlretrieve(PICKLE_INFILE)
with pkl_file.open('rb') as f:
return pickle.load(f)
def serialize(pkl_file: Path = PICKLE_OUTFILE,
data: Sequence[NamedTuple] = None) -> None:
"""Save the data passed in to the pickle file passed in"""
f = urlretrieve(PICKLE_OUTFILE)
if data is None:
data = deserialize()
with pkl_file.open('wb') as f:
pickle.dump(data, f)