Skip to content

Commit

Permalink
ran prettier and working on feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Vidushi Sharma committed Nov 6, 2024
1 parent 5cd7aae commit a3cfc05
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions app/routes/docs.client.samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,26 @@ For new missions, GCN Notices are preferably distributed in JSON format. This gu
Read the JSON data from [sample.schema.json](https://gcn.nasa.gov/docs/notices/schema) and [sample.example.json](https://gcn.nasa.gov/docs/notices/schema), which parses it into Python dictionaries.

```python
from gcn_kafka import Consumer
import json

# Load and parse schema and example JSON files
with open('sample.schema.json', 'r') as schema_file:
schema = json.load(schema_file)
# Connect as a consumer
consumer = Consumer(client_id='fill me in',
client_secret='fill me in')

with open('sample.example.json', 'r') as example_file:
example = json.load(example_file)
# Subscribe to topics and receive alerts
consumer.subscribe(['gcn.classic.voevent.FERMI_GBM_SUBTHRESH'])

print('Schema:', schema)
print('Example:', example)
# Continuously consume and parse messages as JSON
for message in consumer.consume(timeout=1):
if not message.error():
json_data = json.loads(message.value().decode('utf-8'))
print("Received JSON Notice:", json_data)
```

## Encoding and Decoding of Embedded Data

The following code sample shows how to encode/decode a file in Python. The `base64` package includes the methods `b64decode` and `b64encode` to make this task simple.
The following code sample shows how to encode/decode a file in Python. The [`base64`](https://docs.python.org/3/library/base64.html#base64.b64encode) package includes the methods `b64decode` and `b64encode` to make this task simple.

```python
import base64
Expand Down Expand Up @@ -217,4 +221,4 @@ If you want to include a FITS file in a Notice, you add a property to your schem
}
```

In your data production pipeline, you can use the encoding steps to convert your file to a bytestring and set the value of the property to this bytestring. See [non-JSON data](https://json-schema.org/understanding-json-schema/reference/non_json_data.html) for more information.
In your data production pipeline, you can use the encoding steps to convert your file to a bytestring and set the value of the property to this bytestring. See [non-JSON data](https://json-schema.org/understanding-json-schema/reference/non_json_data.html) for more information.

0 comments on commit a3cfc05

Please sign in to comment.