Skip to content

Commit

Permalink
add docstrings, and improve header
Browse files Browse the repository at this point in the history
  • Loading branch information
jero98772 committed Sep 13, 2024
1 parent bddae7d commit 5aad55f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
6 changes: 2 additions & 4 deletions airedellin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-"
"""
airedellin - 2024 - by MLEAFIT
"""
#airellin - by MLeafit

from core.main import *
from core.main import app
Expand Down
40 changes: 38 additions & 2 deletions core/tools/dummy_donations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,50 @@
import json
import os
def load_data(data_file):
"""Load data from the file."""
"""
Load data from a JSON file if it exists.
Args:
data_file (str): The path to the JSON file that contains data.
Returns:
dict: A dictionary containing keys 'images', 'accounts', 'entities', and 'sensors'.
If the file does not exist, it returns an empty structure with those keys and empty lists.
"""
if os.path.exists(data_file):
with open(data_file, 'r') as file:
return json.load(file)
return {"images": [], "accounts": [], "entities": [], "sensors": []}

def retrieve_data_for_sensor(sensor_name,data):
"""Retrieve associated data based on the sensor name."""
"""
Retrieve data associated with a sensor by its name.
Args:
sensor_name (str): The name of the sensor to look up in the data.
data (dict): A dictionary containing 'sensors', 'entities', 'accounts', and 'images' lists.
Returns:
dict: A dictionary containing the sensor name, its associated entity, account, and image.
If the sensor is not found, returns a placeholder dictionary with a message for donation.
Example:
If the sensor exists:
{
"sensor": "sensor_name",
"entity": "corresponding_entity",
"account": "corresponding_account",
"image": "corresponding_image_url"
}
If the sensor does not exist:
{
"sensor": "not found",
"entity": "you can add your sensor for donations",
"account": "go to <a href='/add_donation'>add donation</a>",
"image": "https://via.placeholder.com/150"
}
"""
if sensor_name not in data['sensors']:
print(f"Sensor {sensor_name} not found.")
associated_data = {
Expand Down

0 comments on commit 5aad55f

Please sign in to comment.