-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.py
41 lines (36 loc) · 1.14 KB
/
load.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
import unidata
import pathlib
import asyncio
import sys
import itertools
import aiohttp
from aiohttp import web
async def spin(msg):
write, flush = sys.stdout.write, sys.stdout.flush
dots = '⠉⠘⠰⢠⣀⡄⠆⠃' # Braille patterns
for char in itertools.cycle(dots):
status = msg + ' ' + char + ' '
write(status)
flush()
write('\x08' * len(status))
try:
await asyncio.sleep(.1)
except asyncio.CancelledError:
break
write(' ' * len(status) + '\x08' * len(status))
async def download():
filename = pathlib.Path(unidata.URL).name
spinner = asyncio.ensure_future(spin('downloading ' + filename))
async with aiohttp.request('GET', unidata.URL) as resp:
if resp.status != 200:
raise aiohttp.HttpProcessingError(
code=resp.status, message=resp.reason,
headers=resp.headers)
with open(filename, 'wb') as fd:
fd.write(await resp.read())
spinner.cancel()
def main():
loop = asyncio.get_event_loop()
text = loop.run_until_complete(download())
if __name__ == '__main__':
main()