Skip to content

Commit

Permalink
docs: Update documentation for ContinuousAugmentedDiff class
Browse files Browse the repository at this point in the history
  • Loading branch information
mvexel committed Jan 28, 2025
1 parent c4329ad commit b7c2e31
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
36 changes: 33 additions & 3 deletions docs/api/augmenteddiff.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# AugmentedDiff
# Augmented Diffs

This class is used to represent an OSM Augmented Diff. For more information about OSM Augmented Diffs, see the [Augmented Diff](https://wiki.openstreetmap.org/wiki/Overpass_API/Augmented_Diffs) page on the OpenStreetMap Wiki.
This module provides classes for working with OSM Augmented Diffs. For more information about OSM Augmented Diffs, see the [Augmented Diff](https://wiki.openstreetmap.org/wiki/Overpass_API/Augmented_Diffs) page on the OpenStreetMap Wiki.

Basic usage:
## AugmentedDiff

Basic usage of the AugmentedDiff class:

```python
>>> from osmdiff import AugmentedDiff
Expand All @@ -29,3 +31,31 @@ AugmentedDiff (3191 created, 1724 modified, 7077 deleted) # the results of the
options:
show_root_heading: true
show_source: false

## ContinuousAugmentedDiff

The ContinuousAugmentedDiff class provides an iterator interface for continuously fetching augmented diffs as they become available. It handles timing, backoff, and error recovery automatically.

Basic usage:

```python
>>> from osmdiff import ContinuousAugmentedDiff
>>> # Create fetcher for London area
>>> fetcher = ContinuousAugmentedDiff(
... minlon=-0.489,
... minlat=51.28,
... maxlon=0.236,
... maxlat=51.686
... )
>>> # Iterate over diffs as they become available
>>> for diff in fetcher:
... print(f"Got diff {diff.sequence_number} with {len(diff.create)} creates")
Got diff 6509701 with 2776 creates
Got diff 6509702 with 3191 creates
# ... continues until interrupted
```

::: osmdiff.augmenteddiff.ContinuousAugmentedDiff
options:
show_root_heading: true
show_source: false
56 changes: 55 additions & 1 deletion docs/examples/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,58 @@
# Examples

This page will contain examples of how to use the OSMDiff library.
Here are some examples of how to use the OSMDiff library.

## Basic Augmented Diff Usage

```python
from osmdiff import AugmentedDiff

# Create an AugmentedDiff instance for a specific area
ad = AugmentedDiff(
minlon=-0.489, # London bounding box
minlat=51.28,
maxlon=0.236,
maxlat=51.686
)

# Get current state and retrieve changes
ad.get_state()
status = ad.retrieve()

if status == 200:
print(f"Changes retrieved:")
print(f" Created: {len(ad.create)}")
print(f" Modified: {len(ad.modify)}")
print(f" Deleted: {len(ad.delete)}")
```

## Continuous Monitoring

For continuous monitoring of changes, use the ContinuousAugmentedDiff class:

```python
from osmdiff import ContinuousAugmentedDiff

# Create continuous fetcher for London area
fetcher = ContinuousAugmentedDiff(
minlon=-0.489,
minlat=51.28,
maxlon=0.236,
maxlat=51.686,
min_interval=30, # Check at least every 30 seconds
max_interval=120 # Back off up to 120 seconds if no changes
)

# Process changes as they come in
for diff in fetcher:
print(f"\nNew changes in diff {diff.sequence_number}:")
print(f" Created: {len(diff.create)} objects")
print(f" Modified: {len(diff.modify)} objects")
print(f" Deleted: {len(diff.delete)} objects")

# Process specific changes
for obj in diff.create:
if "amenity" in obj.tags:
print(f"New amenity: {obj.tags['amenity']}")
```

0 comments on commit b7c2e31

Please sign in to comment.