atmosx-nwws-parser 1.0.18 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,89 +1,208 @@
1
- # AtmosphericX - NOAA Weather Wire Service Parser
2
-
3
-
4
- This repository contains the primary parser for AtmosphericX's NOAA Weather Wire Service parser. It is designed to handle real time weather alerts and messages from the National Weather Service using XMPP. If you do not know basic programming, this parser is not for you. It is intended for developers who want to integrate alerts from NOAA Weather Wire easily into their applications or services without hassle. If you wish to use NWWS without programming, feel free to use our project where most of this code was used - [AtmosphericX](https://github.com/k3yomi/AtmosphericX).
5
-
6
- ## Installation Guide
7
- To install this package, you can use **NPM** (Node Package Manager). Open your terminal and run the following command:
8
-
1
+ <h1 style='font-size: 65px'; align="center">🌪️ AtmosphericX - NOAA Wire + API Parser ⚠️</h1>
2
+ <div align="center">
3
+ <p align = "center">This repository contains the primary parser for AtmosphericX's NOAA Weather Wire Service (NWWS) and National Weather Service (NWS) API. It is designed to handle real-time weather alerts and messages from the National Weather Service, using both XMPP (NWWS) and direct API access (Slower). This parser is intended for developers who want to integrate real-time weather alerts, watches, warnings, and forecast data from the NWS seamlessly into their applications or services. It is not recommended for users without basic programming knowledge. If you wish to access NOAA weather data without programming, consider using our end-user project, which leverages this parser and provides an easy-to-use interface for tracking weather alerts.</small></p>
4
+ <p align = "center">Documentation written by @k3yomi</p>
5
+ <div align="center" style="border: none;">
6
+ <img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/k3yomi/atmosx-nwws-parser">
7
+ <img alt="GitHub forks" src="https://img.shields.io/github/forks/k3yomi/atmosx-nwws-parser">
8
+ <img alt="GitHub issues" src="https://img.shields.io/github/issues/k3yomi/atmosx-nwws-parser">
9
+ <img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/k3yomi/atmosx-nwws-parser">
10
+ </div>
11
+ </div>
12
+
13
+ ## Installation (NPM)
9
14
  ```bash
10
15
  npm install atmosx-nwws-parser
11
16
  ```
12
17
 
13
- ## Usage
14
- ```js
15
- const AtmosXWireParser = require(`atmosx-nwws-parser`); // or require(`@k3y0mi/nwws-parser`);
16
- ```
17
-
18
- ## Configuration and Initialization
19
-
20
- There are several settings you can configure when intializing the parser. Below is the test.js example that shows some of the settings you can use:
21
-
22
- ```js
23
- let Client = new AtmosXWireParser({
24
- alertSettings: {
25
- onlyCap: false, // Set to true to only receive CAP messages only
26
- betterEvents: true, // Set to true to receive better event handling
27
- ugcPolygons: false, // Set to true to receive UGC Polygons instead of reading from raw products.
28
- expiryCheck: true, // Set to true to check for expired alerts and remove them from the list
29
- filteredAlerts: [] // Alerts you want to only log, leave empty to receive all alerts (Ex. ["Tornado Warning", "Radar Indicated Tornado Warning"])
18
+ ## Example Usage
19
+ ```javascript
20
+ const { AlertManager } = require('atmosx-nwws-parser'); // CJS
21
+ import { AlertManager } from 'atmosx-nwws-parser'; // ESM
22
+
23
+ const parser = new AlertManager({
24
+ database: `shapefiles.db`,
25
+ is_wire: true,
26
+ journal: true,
27
+ noaa_weather_wire_service_settings: {
28
+ reconnection_settings: {
29
+ enabled: true,
30
+ interval: 60,
31
+ },
32
+ credentials: {
33
+ username: `username_here`,
34
+ password: `password_here`,
35
+ nickname: "AtmosphericX Parser",
36
+ },
37
+ cache: {
38
+ enabled: true,
39
+ max_file_size: 5,
40
+ max_db_history: 5000,
41
+ directory: `meow`,
42
+ },
43
+ preferences: {
44
+ disable_ugc: false,
45
+ disable_vtec: false,
46
+ disable_text: false,
47
+ cap_only: false,
48
+ }
30
49
  },
31
- xmpp: {
32
- reconnect: true, // Set to true to enable automatic reconnection if you lose connection
33
- reconnectInterval: 60, // Interval in seconds to attempt reconnection
50
+ national_weather_service_settings: {
51
+ interval: 15,
52
+ endpoint: `https://api.weather.gov/alerts/active`,
34
53
  },
35
- cacheSettings: {
36
- maxMegabytes: 2, // Maximum cache size in megabytes
37
- readCache: false, // Set to true if you wish to reupload the cache from earlier (Now supports reading from CAP, SPS, and Alerts)
38
- cacheDir: `./cache`, // Directory for cache files
54
+ global_settings: {
55
+ parent_events_only: true,
56
+ better_event_parsing: true,
57
+ shapefile_coordinates: false,
58
+ shapefile_skip: 10,
59
+ filtering: {
60
+ events: [`Severe Thunderstorm Warning`],
61
+ filtered_icao: [],
62
+ ignored_icao: [`KWNS`],
63
+ ignored_events: [`Xx`, `Test Message`],
64
+ ugc_filter: [],
65
+ state_filter: [],
66
+ check_expired: true,
67
+ ignore_text_products: true,
68
+ location: {
69
+ unit: `miles`
70
+ },
71
+ },
72
+ eas_settings: {
73
+ directory: null,
74
+ intro_wav: null,
75
+ }
39
76
  },
40
- authentication: {
41
- username: `USERNAME_HERE`, // Your XMPP username
42
- password: `PASSWORD_HERE`, // Your XMPP password
43
- display: `DISPLAY_NAME` // Display name for your XMPP client
44
- },
45
- database: `./database.db`, // Path to the SQLite database file (It will be created if it doesn't exist and will be used to store UGC counties and zones.)
77
+ })
78
+ ```
79
+
80
+ ## NOAA Weather Wire Service (Getting Started)
81
+ To use the NOAA Weather Wire Service (NWWS). You would need to obtain credentials from the National Weather Service. Follow these steps:
82
+ 1. Visit the [NOAA NWWS Registration Page](https://www.weather.gov/nwws/nwws_oi_request).
83
+ 2. Fill out the registration form with the required information.
84
+ 3. Submit the form and wait for approval. You will receive your NWWS credentials via email.
85
+
86
+ ## Events and Listeners
87
+ > All events are in GeoJSON.
88
+
89
+ ### Event `onEvents`
90
+ Triggered when a batch of new alerts are received and processed.
91
+ ```javascript
92
+ parser.on(`onEvents`, (alerts) => {
93
+ console.log(`Received ${alerts.length} new alerts.`);
94
+ alerts.forEach(alert => {
95
+ console.log(`${alert.properties.event} for ${alert.properties.locations}`);
96
+ });
97
+ });
98
+ ```
99
+ Alternatively, you can listen for single alert events using `onSevereThunderstormWarning` or `onTornadoWarning`, etc.
100
+ ```javascript
101
+ parser.on(`onTornadoWarning`, (alert) => {
102
+ console.log(`Tornado Warning issued for ${alert.properties.locations}`);
46
103
  });
47
104
  ```
48
105
 
106
+ ### Event `onReconnection`
107
+ Triggered when the parser attempts to reconnect to the NWWS service.
108
+ ```javascript
109
+ parser.on(`onReconnection`, (data) => {
110
+ console.log(`Reconnection attempt #${data.reconnects}`);
111
+ });
112
+ ```
49
113
 
50
- ## Event Handling
114
+ ### Event `onConnection`
115
+ Triggered when the parser successfully connects to the NWWS service.
116
+ ```javascript
117
+ parser.on(`onConnection`, (nickname) => {
118
+ console.log(`Connected to NWWS service as ${nickname}`);
119
+ });
120
+ ```
51
121
 
52
- You can handle various events emitted by the parser. Here are some examples:
122
+ ### Event `onOccupant`
123
+ Triggered when a new occupant is detected on the NWWS XMPP service.
124
+ ```javascript
125
+ parser.on(`onOccupant`, (data) => {
126
+ console.log(`New occupant detected: ${data.occupant}`);
127
+ });
128
+ ```
53
129
 
54
- ```js
55
- Client.onEvent(`onAlert`, (alerts: Array) => {});
56
- Client.onEvent(`onStormReport`, (report: Object) => {});
57
- Client.onEvent(`onMesoscaleDiscussion`, (discussion: Object) => {});
58
- Client.onEvent(`onMessage`, (stanza: Object) => {});
59
- Client.onEvent(`onOccupant`, (occupant: Object) => {});
60
- Client.onEvent(`onError`, (error: Object) => {});
61
- Client.onEvent(`onReconnect`, (service: Object) => {});
130
+ ### Event `onMessage`
131
+ Triggered when a stanza message is validated and received from the XMPP client.
132
+ ```javascript
133
+ parser.on(`onMessage`, (data) => {
134
+ console.log(`Message received from ${data.from}: ${data.message}`);
135
+ });
136
+ ```
62
137
 
138
+ ### Event `log`
139
+ Triggered for logging purposes, providing log level and message.
140
+ ```javascript
141
+ parser.on(`log`, (message) => {
142
+ console.log(data.message);
143
+ });
63
144
  ```
64
145
 
65
- ## Functions and Methods
66
- You can also use various functions provided by the parser. Here are some examples:
67
- ```js
68
- // Debugging function to create your own alert manually
69
- Client.forwardCustomStanza(stanza: String, attributes: Object);
146
+ ## Callbacks and Functions
147
+
148
+ ### Function `setDisplayName(name)`
149
+ Sets the display name for the XMPP client. This requires reconnection to take effect.
150
+ ```javascript
151
+ parser.setDisplayName(`My Weather Parser`);
70
152
  ```
71
153
 
72
- ```js
73
- // Function to set the display name of the XMPP client (Will only set upon reconnect)
74
- Client.setDisplayName(displayName: String);
154
+ ### Function `setCurrentLocation(name, {latitude, longitude})`
155
+ Sets the current location for the parser, which can be used for location-based filtering.
156
+ ```javascript
157
+ parser.setCurrentLocation(`My Location`, {34.05, -118.25 });
75
158
  ```
76
159
 
77
- ## Error Handling
78
- The parser can emit various errors. Here are some common errors you might encounter:
160
+ ### Function `createEasAudio(description, header)`
161
+ Generates an EAS audio file based on the provided description and header. Audio file will be located based on settings provided in the global_settings.eas_settings object.
162
+ ```javascript
163
+ parser.createEasAudio(`This is a test alert`, `EAS Header Info`);
164
+ ```
79
165
 
80
- **not-authorized**: This error occurs when the parser is not authorized to connect to the XMPP server. Ensure that your username and password are correct.
166
+ ### Function `getAllAlertTypes()`
167
+ Returns an array of all supported alert types by the parser.
168
+ ```javascript
169
+ const alertTypes = parser.getAllAlertTypes();
170
+ console.log(alertTypes);
171
+ ```
81
172
 
82
- **unreachable-host**: This error indicates that the parser cannot reach the XMPP server. Check your internet connection and ensure that the server address is correct.
173
+ ### Function `searchStanzaDatabase(query)`
174
+ Searches the internal stanza database for messages matching the provided query.
175
+ ```javascript
176
+ const results = parser.searchStanzaDatabase(`Tornado Warning`);
177
+ console.log(results);
178
+ ```
83
179
 
84
- **service-error**: This error occurs when there is an issue with the XMPP service. It could be due to server maintenance or other issues. You can try reconnecting after some time.
180
+ ### Function `setSettings({})`
181
+ Dynamically updates the parser settings. Accepts the same configuration object as the constructor.
182
+ ```javascript
183
+ parser.setSettings({
184
+ global_settings: {
185
+ filtering: {
186
+ ignored_icao: [`KXYZ`],
187
+ }
188
+ }
189
+ });
190
+ ```
85
191
 
86
- **no-database-dir**: This error occurs when the database directory does not exist. Ensure that the directory specified in the `database` setting exists or create it before running the parser.
192
+ ### Function `stop()`
193
+ Stops the parser and disconnects from the NWWS service.
194
+ ```javascript
195
+ parser.stop();
196
+ ```
87
197
 
88
- ## Credits
89
- This parser is developed and maintained by [K3YOMI](https://github.com/K3YOMI) and the AtmosphericX Team. It is open-source and available for contributions and improvements. If you find any issues or have suggestions, feel free to open an issue or submit a pull request in the repository.
198
+ ## References
199
+ - [NOAA NWWS Information](https://www.weather.gov/nwws/)
200
+ - [NWS API Documentation](https://www.weather.gov/documentation/services-web-api)
201
+ - [XMPP Protocol](https://xmpp.org/about/technology-overview/)
202
+ - [AtmosphericX](https://github.com/k3yomi/AtmosphericX)
203
+
204
+ ## Acknowledgements
205
+ - [k3yomi](https://github.com/k3yomi)
206
+ - Lead developer @ AtmosphericX and maintainer of this module.
207
+ - [StarflightWx](https://x.com/starflightVR)
208
+ - For testing and providing feedback (Co-Developer and Spotter @ AtmosphericX)