try again

This commit is contained in:
2025-12-08 22:49:18 +00:00
parent 3399dda125
commit a7b6c529a9
2 changed files with 0 additions and 2167 deletions

View File

@@ -1,596 +0,0 @@
# NWS API Documentation - Integrated Main Endpoint
This document describes all available endpoints in the integrated `main.php` file, which consolidates functionality from multiple separate PHP scripts.
## Base URL
```
/main.php
```
## General Information
- **Content-Type**: `application/json` (unless otherwise specified)
- **CORS**: Enabled with `Access-Control-Allow-Origin: *`
- **Methods**: GET, POST, OPTIONS
- **Database**: PostgreSQL (connection: `host=localhost dbname=nws user=nws password=nws`)
## Utility Functions (No Direct Access)
The following utility functions are included at the top of the file for compatibility:
- `connect_db()` - Database connection
- `send_error($code, $message)` - JSON error response
- `send_json($data)` - JSON success response
- `send_geojson($features)` - GeoJSON response
## GET Endpoints
### 1. Single Camera Information
**Endpoint**: `?camid={id}`
**Description**: Get detailed information for a single camera.
**Parameters**:
- `camid` (string, required): Camera ID
**Response**: Camera object with hydro/airport boolean fields
**Example**: `/main.php?camid=123`
---
### 2. Active Cameras
**Endpoint**: `?cams` or no parameters
**Description**: Get all active cameras with recent successful connections.
**Response**: Array of camera objects
**Example**: `/main.php?cams`
---
### 3. Camera List
**Endpoint**: `?camlist`
**Description**: Get comprehensive list of all active cameras.
**Response**:
```json
{
"status": "success",
"data": [...],
"count": 150
}
```
**Example**: `/main.php?camlist`
---
### 4. Camera API with Filters
**Endpoint**: `?cams` with bounding box parameters
**Parameters**:
- `lat1`, `lon1`, `lat2`, `lon2` (float, required): Bounding box coordinates
- `elevbottom`, `elevtop` (float, required): Elevation range
**Response**: Filtered camera array
**Example**: `/main.php?cams&lat1=38.0&lon1=-82.0&lat2=39.0&lon2=-81.0&elevbottom=100&elevtop=1000`
---
### 5. Camera Static Search
**Endpoint**: `?camstatic`
**Parameters**:
- `lat1`, `lon1`, `radius` (float, required): Center point and radius for radius search
- `camstatic=bbox` with `lat1`, `lon1`, `lat2`, `lon2`, `elevbottom`, `elevtop`: Bounding box search
**Response**: Cameras within specified area
**Example**: `/main.php?camstatic=radius&lat1=38.5&lon1=-81.5&radius=50`
---
### 6. Camera Database Count
**Endpoint**: `?camdb`
**Response**: Total count of camera records
**Example**: `/main.php?camdb`
---
### 7. Camera Circles
**Endpoint**: `?camcircle`
**Description**: Get camera locations as buffer circles (8000m radius).
**Response**: GeoJSON FeatureCollection with circular buffers
**Example**: `/main.php?camcircle`
---
### 8. Weather Station Data
**Endpoint**: `?outside` or `?outsideold`
**Description**: Get current weather station observations.
**Response**: Array of weather station data
**Example**: `/main.php?outside`
---
### 9. Fire Data
**Endpoint**: `?fire`
**Description**: Get active wildfire information.
**Response**: GeoJSON FeatureCollection of fire data
**Example**: `/main.php?fire`
---
### 10. Individual Camera Images
**Endpoint**: `?camid={id}&dtg={datetime}&camimages={count}`
**Parameters**:
- `camid` (string, required): Camera ID
- `dtg` (string, optional): End time for historical images (YYYY-MM-DD HH:MM UTC)
- `camimages` (int, optional): Number of images (default: 20)
**Response**: Array of camera image records
**Example**: `/main.php?camid=123&camimages=10`
---
### 11. OHGO Data
**Endpoint**: `?ohgo`
**Description**: Get Ohio Department of Transportation road information.
**Response**: Array of OHGO road status data
**Example**: `/main.php?ohgo`
---
### 12. Power Outage Data
**Endpoint**: `?power`
**Description**: Get current power outage information for RLX CWA.
**Response**: Array of power outage points
**Example**: `/main.php?power`
---
### 13. Power API (Advanced)
**Endpoint**: Various parameters for power data
**Parameters**:
- `states`: Get state boundaries GeoJSON
- `county`: Get county outage summary
- `max` with `start`, `end`: Get maximum outage by county for date range
- `countyarchive` with `start`, `end`: County archive data
- `archivepoint` with `start`, `end`: Point outage archive
- `svr=current`: Current severe weather warnings
- `svrpolys`: Warning polygon metadata
- `powerids={ids}`: Specific outage details
- `poweridsgeojson={ids}`: Specific outage GeoJSON
- `polygongeojson={geojson}`: Outages within polygon
**Response**: Varies by endpoint (JSON or GeoJSON)
**Example**: `/main.php?states`
---
### 14. Local Storm Reports (LSR)
**Endpoint**: Various LSR-related parameters
**Parameters**:
- `ohgo`: OHGO data as GeoJSON
- `ohgotable`: OHGO tabular data
- `vtec={code}`: Warning polygon by VTEC code
- `reports={code}`: Reports within warning polygon
- `outages={code}`: Power outages within warning polygon
- `verify`: Verification table data
- `stats`: Report statistics by county
- `metars` with `start`, `end`: METAR data
- `news`, `news2`, `news3`: News data with various filtering
- `newsarchive` with search parameters: Archived news
- `wv511`: West Virginia 511 data
- `ky511`: Kentucky 511 data
- `getCombinedTable`: Combined road incident table
- `updater` with `table`, `id`, `lsr`/`hide`: Update incident flags
**Response**: Varies by endpoint
**Example**: `/main.php?ohgo`
---
### 15. NWS Staff Data
**Endpoint**: `?officestats`, `?regionstats`, `?drilldown`
**Parameters**:
- `datetime`: Date for statistics (m-d-Y format)
**Response**: NWS office staffing statistics
**Example**: `/main.php?officestats`
---
### 16. Verification Data
**Endpoint**: Various verification parameters
**Parameters**:
- `lsrslist`: Simple verification list
- `reset`: Clear verification table
- `lsrs` with `zone`, `lsr`, `dir`: Update verification counts
- `inc`/`hide` with `id`, `true`/`false`: Update report visibility
**Response**: Verification operation results
**Example**: `/main.php?lsrslist`
---
### 17. Warning Tracking
**Endpoint**: `?warntrack`
**Description**: Get active warning tracking information for KRLX.
**Response**: GeoJSON FeatureCollection of warning tracks
**Example**: `/main.php?warntrack`
---
## POST Endpoints
### 1. MP4/GIF Creation
**Endpoint**: POST with form data
**Parameters**:
- `data` (array, required): Array of image file paths
- `images` (int, required): Number of images
- `delay` (int, required): Frame delay in milliseconds
- `lastdelay` (int, required): Last frame delay
- `maxh`, `maxv` (int, optional): Maximum dimensions
**Response**: Base64-encoded GIF data
**Content-Type**: Not JSON (binary/gif)
---
### 2. Update Camera Field
**Endpoint**: POST with form data
**Parameters**:
- `camid` (string, required): Camera ID
- `field` (string, required): Field name ('hydro' or 'airport')
- `value` (string, required): New value ('true' or 'false')
**Response**:
```json
{
"success": true
}
```
---
### 3. Admin Functions
**Endpoint**: POST with form data
**Parameters**:
- `action` (string, required): Action type
- `checkurl`: Check if URL exists
- `newcam`: Add new camera
**For `checkurl`**:
- `url` (string, required): URL to check
**For `newcam`**:
- `url`, `lat`, `lon`, `description`, `method`, `permission`, `owner`, `email` (all required)
**Response**: Operation result
---
### 4. Storm Data API
**Endpoint**: POST with JSON data
**Content-Type**: `application/json`
**Request Body**:
```json
{
"request_type": "ohgo|ohgonopoly|power|powernopoly|wupoly|campoly",
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-01-02 00:00:00",
"area_geojson": {...},
"buffer": 2,
"outage_threshold": 10,
"polygons": ["POLYGON(...)"],
"camimages": 20
}
```
**Request Types**:
- `ohgo`: OHGO data within GeoJSON polygon
- `ohgonopoly`: OHGO data without polygon filter
- `power`: Power outages within GeoJSON polygon
- `powernopoly`: Power outages without polygon filter
- `wupoly`: Weather Underground data within polygons
- `campoly`: Camera images within GeoJSON polygon
**Response**: GeoJSON FeatureCollection
---
## Error Handling
All endpoints return consistent error responses:
```json
{
"error": "Error message"
}
```
Common HTTP status codes:
- `200`: Success
- `400`: Bad Request (missing/invalid parameters)
- `404`: Not Found
- `500`: Internal Server Error (database/query issues)
## Migration Guide for Existing Callers
### Simple URL Changes
Most existing callers only need to update the filename in their requests:
**Before:**
```
https://your-server/single.php?camid=123
```
**After:**
```
https://your-server/main.php?camid=123
```
### Specific Migration Instructions
#### 1. single.php → main.php
**No parameter changes needed**
- Existing calls: `single.php?camid={id}`
- New calls: `main.php?camid={id}`
#### 2. cam.php → main.php
**No parameter changes needed**
- Existing calls: `cam.php` or `cam.php?cams`
- New calls: `main.php` or `main.php?cams`
#### 3. camlist.php → main.php
**Parameter change required**
- Existing calls: `camlist.php`
- New calls: `main.php?camlist`
#### 4. camapi.php → main.php
**No parameter changes needed**
- Existing calls: `camapi.php?cams=1&lat1=...`
- New calls: `main.php?cams=1&lat1=...`
#### 5. camcircle.php → main.php
**Parameter change required**
- Existing calls: `camcircle.php`
- New calls: `main.php?camcircle`
#### 6. camobs.php → main.php
**No parameter changes needed**
- Existing calls: `camobs.php?camstatic=radius&lat1=...`
- New calls: `main.php?camstatic=radius&lat1=...`
#### 7. db.php → main.php
**No parameter changes needed**
- Existing calls: `db.php?outside`
- New calls: `main.php?outside`
- Existing calls: `db.php?outsideold`
- New calls: `main.php?outsideold`
#### 8. fire.php → main.php
**Parameter change required**
- Existing calls: `fire.php`
- New calls: `main.php?fire`
#### 9. individualcam.php → main.php
**No parameter changes needed**
- Existing calls: `individualcam.php?camid=123&dtg=...`
- New calls: `main.php?camid=123&dtg=...`
#### 10. lsr.php → main.php
**No parameter changes needed**
- Existing calls: `lsr.php?ohgo`
- New calls: `main.php?ohgo`
- Existing calls: `lsr.php?vtec=...`
- New calls: `main.php?vtec=...`
#### 11. mp4.php → main.php
**No parameter changes needed (POST data remains the same)**
- Existing calls: POST to `mp4.php`
- New calls: POST to `main.php`
#### 12. nws.php → main.php
**No parameter changes needed**
- Existing calls: `nws.php?officestats`
- New calls: `main.php?officestats`
#### 13. ohgo.php → main.php
**Parameter change required**
- Existing calls: `ohgo.php`
- New calls: `main.php?ohgo`
#### 14. power.php → main.php
**Parameter change required**
- Existing calls: `power.php`
- New calls: `main.php?power`
#### 15. powerapi.php → main.php
**No parameter changes needed**
- Existing calls: `powerapi.php?states`
- New calls: `main.php?states`
- Existing calls: `powerapi.php?county`
- New calls: `main.php?county`
#### 16. searchapi.php → main.php
**No parameter changes needed**
- Existing calls: `searchapi.php?county`
- New calls: `main.php?county`
#### 17. stormdata.php → main.php
**No parameter changes needed (POST JSON remains the same)**
- Existing calls: POST to `stormdata.php`
- New calls: POST to `main.php`
#### 18. update_field.php → main.php
**No parameter changes needed (POST data remains the same)**
- Existing calls: POST to `update_field.php`
- New calls: POST to `main.php`
#### 19. ver.php → main.php
**No parameter changes needed**
- Existing calls: `ver.php?lsrslist`
- New calls: `main.php?lsrslist`
#### 20. warntrack.php → main.php
**Parameter change required**
- Existing calls: `warntrack.php`
- New calls: `main.php?warntrack`
### Files NOT Requiring Changes
#### one.php
This file contains HTML/JavaScript interface and should remain as-is. It makes calls to other endpoints that have been integrated.
### Bulk Update Script
For systems with many hardcoded references, use this sed command pattern:
```bash
# Update all .php files to use main.php
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/single\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/cam\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/camapi\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/camlist\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/camobs\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/db\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/fire\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/individualcam\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/lsr\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/mp4\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/nws\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/ohgo\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/power\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/powerapi\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/searchapi\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/stormdata\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/update_field\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/ver\.php/main.php/g' {} \;
find /path/to/your/code -name "*.php" -type f -exec sed -i 's/warntrack\.php/main.php/g' {} \;
```
### Testing Migration
After updating references, test key endpoints:
```bash
# Test basic camera functionality
curl "http://your-server/main.php?camid=123"
# Test admin functions
curl -X POST "http://your-server/main.php" -d "action=checkurl&url=http://example.com"
# Test storm data API
curl -X POST "http://your-server/main.php" \
-H "Content-Type: application/json" \
-d '{"request_type":"power","start_time":"2025-01-01","area_geojson":"{\"type\":\"Polygon\",\"coordinates\":[[[-82,38],[-81,38],[-81,39],[-82,39],[-82,38]]}"}'
```
## Original Files Consolidated
This integrated file consolidates the following original scripts:
- `admin.php` - Admin functions
- `cam.php` - Active cameras
- `camapi.php` - Camera API with filters
- `camcircle.php` - Camera buffer circles
- `camlist.php` - Camera list
- `camobs.php` - Camera observations
- `db.php` - Weather station data
- `fire.php` - Fire data
- `individualcam.php` - Individual camera images
- `lsr.php` - Local storm reports
- `mp4.php` - GIF creation
- `nws.php` - NWS staff data
- `ohgo.php` - OHGO road data
- `one.php` - HTML interface (not integrated)
- `power.php` - Power outages
- `powerapi.php` - Advanced power API
- `powerapitest.php` - Power API test
- `searchapi.php` - Search API
- `single.php` - Single camera info
- `stormdata.php` - Storm data API
- `update_field.php` - Camera field updates
- `ver.php` - Verification data
- `warntrack.php` - Warning tracking
## Usage Examples
### Get all active cameras:
```bash
curl "http://your-server/main.php?cams"
```
### Get camera within bounding box:
```bash
curl "http://your-server/main.php?cams&lat1=38.0&lon1=-82.0&lat2=39.0&lon2=-81.0&elevbottom=100&elevtop=1000"
```
### Update camera hydro status:
```bash
curl -X POST "http://your-server/main.php" \
-d "camid=123&field=hydro&value=true"
```
### Query storm data with polygon:
```bash
curl -X POST "http://your-server/main.php" \
-H "Content-Type: application/json" \
-d '{
"request_type": "power",
"start_time": "2025-01-01 00:00:00",
"end_time": "2025-01-02 00:00:00",
"area_geojson": {
"type": "Polygon",
"coordinates": [[[-82, 38], [-81, 38], [-81, 39], [-82, 39], [-82, 38]]]
},
"buffer": 2
}'
```
## Notes
1. The `one.php` file contains HTML/JavaScript interface and is not integrated into this API endpoint.
2. All database connections use the same credentials and should be pooled in production.
3. Geographic data uses SRID 4326 (WGS84) unless otherwise specified.
4. Time-based queries typically use UTC unless converted to local time zones.
5. The integrated file maintains backward compatibility with existing callers by preserving all original functionality.

1571
main.php

File diff suppressed because it is too large Load Diff