Skip to content

Commit

Permalink
Create data_acquisition.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Oct 29, 2024
1 parent a0af8a0 commit 75e1e8e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/iot/data_acquisition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# src/iot/data_acquisition.py

import requests
import json
from datetime import datetime

class DataAcquisition:
"""Class to acquire data from external sources."""

def __init__(self, api_url):
self.api_url = api_url

def fetch_external_data(self):
"""Fetch data from an external API."""
try:
response = requests.get(self.api_url)
response.raise_for_status() # Raise an error for bad responses
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error fetching external data: {e}")
return None

def combine_data(self, sensor_data, external_data):
"""Combine sensor data with external data."""
combined_data = {
'timestamp': datetime.utcnow().isoformat(),
'sensor_data': sensor_data,
'external_data': external_data
}
return combined_data

if __name__ == "__main__":
# Example usage
api_url = "https://api.example.com/climate-data"
data_acquisition = DataAcquisition(api_url)
external_data = data_acquisition.fetch_external_data()
print(external_data)

0 comments on commit 75e1e8e

Please sign in to comment.