-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduolingo-daily.py
More file actions
38 lines (31 loc) · 1.12 KB
/
duolingo-daily.py
File metadata and controls
38 lines (31 loc) · 1.12 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
#!/usr/bin/python3
import argparse
import datetime
import gzip
import json
import os
from duolingo_client import Duo
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Daily Daily Data.')
parser.add_argument('user', help='Duolingo user name')
parser.add_argument('--out', help='Output dir', default=None)
parser.add_argument('--zip', dest='zip', help='Zip data', action='store_true')
parser.add_argument('--no-zip', dest='zip', help="Don't zip data", action='store_false')
parser.set_defaults(zip=False)
args = parser.parse_args()
duo = Duo(args.user)
dataJson = json.dumps(duo.get_data(), indent=2)
if args.out is None:
print(dataJson)
else:
os.makedirs(args.out, exist_ok=True)
ext = 'gz' if args.zip else 'json'
filename = datetime.datetime.now().strftime('%Y-%m-%d-duolingo-data.') + ext
if args.zip:
writer = gzip.open
data = dataJson.encode()
else:
writer = open
data = dataJson
with writer(os.path.join(args.out, filename), 'w') as f:
f.write(data)