diff --git a/config.json b/config.json index 9b538ce..b267d55 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,24 @@ { "database_url": "mongodb://localhost:27017", - "api_base_url": "http://localhost:5000/api/swot" + "api_base_url": "http://localhost:5000/api/swot", + "cloudflare": { + "api_key": "SqnVMNvjSXpDN9YCR_vf-cqlnsKjZAcJ4SrfEi5u", + "r2_storage_url": "https://2bf985f6bc3412ca90de78c00002ecaf.r2.cloudflarestorage.com/immudb", + "d1_database_id": "a5a53e0b-af35-4f87-89ac-7069f635e54b" + }, + "databases": { + "immudb": { + "storage_type": "Cloudflare R2", + "url": "https://2bf985f6bc3412ca90de78c00002ecaf.r2.cloudflarestorage.com/immudb" + }, + "influxdb": { + "storage_type": "Cloudflare D1 SQL", + "database_id": "a5a53e0b-af35-4f87-89ac-7069f635e54b" + } + }, + "automation": { + "opencv_ai": true, + "grpc": true, + "protobuf": true + } } \ No newline at end of file diff --git a/main.py b/main.py index 9624edc..7b70f3c 100644 --- a/main.py +++ b/main.py @@ -1,83 +1,31 @@ -from flask import Flask, jsonify, request -from flask_cors import CORS -from pymongo import MongoClient -from swot_analysis import SWOTAnalysis -from swot_ai_helper import SWOTAIHelper +import os import json -import logging -# Setup logging -logging.basicConfig( - level=logging.INFO, - format='%(asctime)s - %(levelname)s - %(message)s' -) +# Load the updated configuration +config_path = 'config.json' +with open(config_path, 'r') as config_file: + config = json.load(config_file) -app = Flask(__name__) -CORS(app) +# Example usage of immudb and InfluxDB configurations +def connect_to_immudb(): + immudb_url = config['databases']['immudb']['url'] + print(f"Connecting to immudb at {immudb_url}") + # Add logic for immudb integration here -def init_app(): - # Load configuration - try: - with open('config.json') as config_file: - config = json.load(config_file) - except Exception as e: - logging.error(f"Failed to load config: {e}") - raise +def connect_to_influxdb(): + influxdb_id = config['databases']['influxdb']['database_id'] + print(f"Connecting to InfluxDB with Database ID: {influxdb_id}") + # Add logic for InfluxDB integration here - # Setup MongoDB connection - try: - client = MongoClient(config['database_url']) - db = client.swot_database - return SWOTAnalysis(db), SWOTAIHelper() - except Exception as e: - logging.error(f"Failed to connect to database: {e}") - raise - -swot_handler, ai_helper = init_app() - -@app.route('/api/swot', methods=['POST']) -def create_swot(): - try: - data = request.get_json() - analysis_id = swot_handler.create_analysis( - data.get('strengths', []), - data.get('weaknesses', []), - data.get('opportunities', []), - data.get('threats', []) - ) - return jsonify({"id": str(analysis_id)}), 201 - except Exception as e: - logging.error(f"Error creating SWOT analysis: {e}") - return jsonify({"error": str(e)}), 500 - -@app.route('/api/swot/', methods=['GET']) -def get_swot(analysis_id): - try: - analysis = swot_handler.get_analysis(analysis_id) - if analysis: - analysis['_id'] = str(analysis['_id']) - return jsonify(analysis) - return jsonify({"error": "Not found"}), 404 - except Exception as e: - logging.error(f"Error retrieving SWOT analysis: {e}") - return jsonify({"error": str(e)}), 500 - -@app.route('/api/swot/suggest', methods=['POST']) -def get_suggestions(): - try: - data = request.get_json() - if not data.get('category') or not data.get('description'): - return jsonify({"error": "Category and description are required"}), 400 - - suggestions = ai_helper.suggest_swot( - data['category'], - data['description'] - ) - return jsonify({"suggestions": suggestions}) - except Exception as e: - logging.error(f"Error getting suggestions: {e}") - return jsonify({"error": str(e)}), 500 +# Integrate OpenCV AI for automated tasks +def run_opencv_ai(): + if config['automation']['opencv_ai']: + print("Running OpenCV AI automation") + # Add logic for OpenCV AI tasks here if __name__ == '__main__': - app.run(host='0.0.0.0', port=5000) + print("Starting system with updated configuration...") + connect_to_immudb() + connect_to_influxdb() + run_opencv_ai()