Add in download option

pull/4/head
Michaela 2021-04-07 18:34:52 +10:00
rodzic a56e1f5e89
commit 2ca9e23404
4 zmienionych plików z 33 dodań i 8 usunięć

Wyświetl plik

@ -35,7 +35,8 @@ while 1:
```
CLI Usage
### CLI Usage
#### Live streaming data
```sh
# all radiosondes
sondehub
@ -68,6 +69,11 @@ sondehub | jq .
```
#### Downloading data
```
sondehub --download S2810113 # Note this may take a long time to finish!
```
Open Data Access
==

Wyświetl plik

@ -1,6 +1,6 @@
[tool.poetry]
name = "sondehub"
version = "0.1.8"
version = "0.1.9"
description = "SDK to access SondeHub open data"
authors = ["Michaela <git@michaela.lgbt>"]
readme = "README.md"

Wyświetl plik

@ -126,6 +126,8 @@ class Downloader(threading.Thread):
task = self.tasks_to_accomplish.get_nowait()
except queue.Empty:
return
if self.debug:
print(task[1])
data = s3.get_object(Bucket=task[0], Key=task[1])
response = json.loads(data["Body"].read())
if self.debug:
@ -134,11 +136,11 @@ class Downloader(threading.Thread):
self.tasks_to_accomplish.task_done()
def download(serial=None, datetime_prefix=None, debug=False):
def download(serial=None, datetime_prefix=None, hashed=True, debug=False):
if serial:
prefix_filter = f"serial/{serial}/"
prefix_filter = f"serial{'-hashed' if hashed else ''}/{serial}/"
elif serial and datetime_prefix:
prefix_filter = f"serial/{serial}/{datetime_prefix}"
prefix_filter = f"serial{'-hashed' if hashed else ''}/{serial}/{datetime_prefix}"
elif datetime_prefix:
prefix_filter = f"date/{datetime_prefix}"
else:

Wyświetl plik

@ -3,6 +3,7 @@ import sondehub
import argparse
import os
import sys
import time
unbuffered = os.fdopen(sys.stdout.fileno(), "wb", 0)
@ -15,7 +16,8 @@ def on_message(message):
def main():
parser = argparse.ArgumentParser(description="Sondehub CLI")
parser.add_argument(
group = parser.add_mutually_exclusive_group()
group.add_argument(
"--serial",
dest="sondes",
default=["#"],
@ -24,15 +26,30 @@ def main():
type=str,
action="append",
)
group.add_argument(
"--download",
dest="download",
default=[],
nargs="*",
help="Sondes to download from open data",
type=str,
action="append",
)
args = parser.parse_args()
if (args.download):
serials = [item for sublist in args.download for item in sublist]
for serial in serials:
for frame in sondehub.download(serial=serial):
on_message(frame)
return
if (
len(args.sondes) > 1
): # we need to drop the default value if the user specifies sepcific sondes
): # we need to drop the default value if the user specifies specific sondes
args.sondes = args.sondes[1:]
sondes = [item for sublist in args.sondes for item in sublist]
test = sondehub.Stream(on_message=on_message, sondes=sondes)
while 1:
pass
time.sleep(0.01) # don't overwork the CPU waiting for events
if __name__ == "__main__":