Skip to content

Commit

Permalink
Update "fetching_messages" example (#115)
Browse files Browse the repository at this point in the history
This updates the "fetching_messages" example to remove a deprecated
method call in favor of the streaming `iter_messages`. Instead of
printing the length, it prints the timestamp, channel, and topic of each
message; for example:

```txt
1616425609698483083 | /gps/navheading          | sensor_msgs/Imu
1616425609700292327 | /gps/fix_velocity        | geometry_msgs/TwistWithCovarianceStamped
```
  • Loading branch information
bryfox authored Dec 17, 2024
1 parent 6736620 commit 72fdbeb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
python:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
permissions:
id-token: write
steps:
Expand All @@ -23,6 +23,7 @@ jobs:
- run: pipenv run black --check --diff --color --exclude '.*_pb2.py' .
- run: pipenv run pyright foxglove
- run: pipenv run python -m flake8 foxglove
- run: pipenv run python -m flake8 examples
- run: pipenv run python -m pytest
- run: pipenv run python -m build

Expand Down
1 change: 0 additions & 1 deletion examples/downloading_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
from datetime import datetime, timedelta

from foxglove.client import Client
Expand Down
8 changes: 3 additions & 5 deletions examples/fetching_messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
from datetime import datetime, timedelta

from foxglove.client import Client
Expand All @@ -9,10 +8,9 @@

# Make sure you've imported either the mcap-ros1-support or mcap-protobuf-support
# libraries before making this call in order to get decoded messages.
messages = client.get_messages(
for schema, channel, message, decoded_message in client.iter_messages(
device_id=device_id,
start=datetime.now() - timedelta(hours=3),
end=datetime.now() - timedelta(hours=1),
)

print(f"downloaded {len(messages)} messages")
):
print(f"{message.log_time} | {channel.topic:<24} | {schema.name}")

0 comments on commit 72fdbeb

Please sign in to comment.