This repository has been archived by the owner on Nov 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_yadisk.py
55 lines (41 loc) · 1.56 KB
/
read_yadisk.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
import datetime
import logging
import sys
from argparse import ArgumentParser, ArgumentTypeError
from m4m_sync.encrypt import AesStreamWrapper
from m4m_sync.stores import YaDiskStore, Sensor, Controller
from m4m_sync.utils import DateTimeRange
logging.basicConfig(
stream=sys.stdout,
level=logging.INFO,
format="%(asctime)s [%(levelname)s] [%(name)s] %(message)s",
)
logger = logging.getLogger(__name__)
def valid_date(s):
try:
return datetime.datetime.strptime(s, "%d-%m-%Y")
except ValueError:
msg = "Not a valid date: '{0}'.".format(s)
raise ArgumentTypeError(msg)
def main():
parser = ArgumentParser()
parser.add_argument("--serializer", default="CsvRawSerializer")
parser.add_argument("--key", required=False, type=str)
parser.add_argument("--sensor", type=str, required=True)
parser.add_argument("--controller", type=str, required=True)
parser.add_argument("--date", type=valid_date, required=True)
parser.add_argument("--token", required=True)
parser.add_argument("--output", "-o", default="out.tsv")
args = parser.parse_args()
logger.info("init")
store = YaDiskStore(token=args.token)
for data in store.get(
sensor=Sensor(id=args.sensor, controller=Controller(mac=args.controller)),
range=DateTimeRange.day(args.date),
stream_wrapper=AesStreamWrapper(key=args.key.encode("utf-8")) if args.key else None,
):
with open(args.output, "wb") as file:
file.write(data)
logger.info("done")
if __name__ == "__main__":
main()