forked from React-Group/interstellar_ai
Weather API
This commit is contained in:
parent
3970c6a4f3
commit
6d4ac29d83
3 changed files with 56 additions and 4 deletions
18
py/api.py
18
py/api.py
|
@ -4,16 +4,18 @@ import secrets
|
|||
import threading
|
||||
from ai import AI
|
||||
from db import DB
|
||||
from weather import Weather
|
||||
from voice import VoiceRecognition
|
||||
|
||||
|
||||
class API:
|
||||
def __init__(self):
|
||||
self.crypt_size = 1
|
||||
self.crypt_size = 4096
|
||||
self.app = Flask(__name__)
|
||||
self.ai_response = {}
|
||||
self.ai = AI()
|
||||
self.db = DB()
|
||||
self.weather = Weather()
|
||||
self.voice = VoiceRecognition()
|
||||
self.db.load_database()
|
||||
self.ai_response_lock = threading.Lock()
|
||||
|
@ -23,8 +25,12 @@ class API:
|
|||
@self.app.route('/interstellar_ai/api/ai_create', methods=['GET'])
|
||||
def create_ai():
|
||||
access_token = secrets.token_urlsafe(self.crypt_size)
|
||||
self.ai_response[access_token] = ""
|
||||
return jsonify({'status': 200, 'access_token': access_token})
|
||||
|
||||
if access_token not in self.ai_response:
|
||||
self.ai_response[access_token] = ""
|
||||
return jsonify({'status': 200, 'access_token': access_token})
|
||||
|
||||
return jsonify({'status': 401, 'error': 'An error occurred, please try again.'})
|
||||
|
||||
@self.app.route('/interstellar_ai/api/ai_send', methods=['POST'])
|
||||
def send_ai():
|
||||
|
@ -99,6 +105,12 @@ class API:
|
|||
|
||||
return jsonify({'status': 401, 'response': "Invalid type"})
|
||||
|
||||
@self.app.route('/interstellar_ai/api/weather', methods=['POST'])
|
||||
def get_weather():
|
||||
unit_type = request.args.get('unit_type')
|
||||
city = request.args.get('city')
|
||||
return jsonify({'status': 200, 'response': self.weather.getweather(unit_type, city)})
|
||||
|
||||
self.app.run(debug=True, host='0.0.0.0', port=5000)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue