diff --git a/.gitignore b/.gitignore
index b607ccb..fdf25da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
**/.vscode/
**/node_modules/
**/npm-debug.log*
+server/api/.env
diff --git a/client/index.html b/client/index.html
index 0c589ec..5b71336 100644
--- a/client/index.html
+++ b/client/index.html
@@ -4,7 +4,7 @@
-
Vite + React
+ Clinema
diff --git a/client/package-lock.json b/client/package-lock.json
index 9716f32..a7be9e5 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -18,6 +18,7 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
+ "axios": "^1.7.7",
"eslint": "^9.9.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
@@ -1517,6 +1518,13 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/asynckit": {
+ "version": "0.4.0",
+ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
+ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/available-typed-arrays": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz",
@@ -1532,6 +1540,18 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/axios": {
+ "version": "1.7.7",
+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz",
+ "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "follow-redirects": "^1.15.6",
+ "form-data": "^4.0.0",
+ "proxy-from-env": "^1.1.0"
+ }
+ },
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@@ -1731,6 +1751,19 @@
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
+ "node_modules/combined-stream": {
+ "version": "1.0.8",
+ "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
+ "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "delayed-stream": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/commander": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
@@ -1892,6 +1925,16 @@
"url": "https://github.com/sponsors/ljharb"
}
},
+ "node_modules/delayed-stream": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
+ "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.4.0"
+ }
+ },
"node_modules/didyoumean": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
@@ -2543,6 +2586,27 @@
"integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==",
"dev": true
},
+ "node_modules/follow-redirects": {
+ "version": "1.15.9",
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
+ "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://github.com/sponsors/RubenVerborgh"
+ }
+ ],
+ "license": "MIT",
+ "engines": {
+ "node": ">=4.0"
+ },
+ "peerDependenciesMeta": {
+ "debug": {
+ "optional": true
+ }
+ }
+ },
"node_modules/for-each": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
@@ -2568,6 +2632,21 @@
"url": "https://github.com/sponsors/isaacs"
}
},
+ "node_modules/form-data": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
+ "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "asynckit": "^0.4.0",
+ "combined-stream": "^1.0.8",
+ "mime-types": "^2.1.12"
+ },
+ "engines": {
+ "node": ">= 6"
+ }
+ },
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
@@ -3491,6 +3570,29 @@
"node": ">=8.6"
}
},
+ "node_modules/mime-db": {
+ "version": "1.52.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
+ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/mime-types": {
+ "version": "2.1.35",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
+ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "mime-db": "1.52.0"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@@ -4022,6 +4124,13 @@
"react-is": "^16.13.1"
}
},
+ "node_modules/proxy-from-env": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
+ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/punycode": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
diff --git a/client/package.json b/client/package.json
index e177852..92d2c36 100644
--- a/client/package.json
+++ b/client/package.json
@@ -26,6 +26,7 @@
"eslint-plugin-react-refresh": "^0.4.9",
"globals": "^15.9.0",
"tailwindcss": "^3.4.10",
+ "axios": "^1.7.7",
"vite": "^5.4.1"
}
}
diff --git a/client/src/App.jsx b/client/src/App.jsx
index b8b8473..076c3ae 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -1,35 +1,15 @@
-import { useState } from 'react'
-import reactLogo from './assets/react.svg'
-import viteLogo from '/vite.svg'
-import './App.css'
+// src/App.jsx
+// eslint-disable-next-line no-unused-vars
+import React from 'react';
+import LocationComponent from './LocationComponent'; // Import the LocationComponent
function App() {
- const [count, setCount] = useState(0)
-
- return (
- <>
-
- Vite + React
-
-
-
- Edit src/App.jsx
and save to test HMR
-
-
-
- Click on the Vite and React logos to learn more
-
- >
- )
+ return (
+
+
Welcome to CliNema
+ {/* Render the LocationComponent */}
+
+ );
}
-export default App
+export default App;
diff --git a/client/src/LocationComponent.jsx b/client/src/LocationComponent.jsx
new file mode 100644
index 0000000..e0883b0
--- /dev/null
+++ b/client/src/LocationComponent.jsx
@@ -0,0 +1,60 @@
+import { useEffect, useState } from 'react';
+import axios from 'axios';
+
+const LocationComponent = () => {
+ // eslint-disable-next-line no-unused-vars
+ const [latitude, setLatitude] = useState(null);
+ // eslint-disable-next-line no-unused-vars
+ const [longitude, setLongitude] = useState(null);
+ const [weatherData, setWeatherData] = useState(null);
+ const [error, setError] = useState(null);
+
+ useEffect(() => {
+ // Check if Geolocation API is available
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition(
+ (position) => {
+ const { latitude, longitude } = position.coords;
+ setLatitude(latitude);
+ setLongitude(longitude);
+ console.log(`Latitude: ${latitude}, Longitude: ${longitude}`);
+
+ // Send latitude and longitude to the Flask backend
+ axios.get(`http://localhost:5000/weather?lat=${latitude}&lon=${longitude}`)
+ .then(response => {
+ setWeatherData(response.data); // Set weather data in state
+ console.log("Weather data:", response.data); // Log the response data
+ })
+ .catch(err => {
+ console.error("Error fetching weather data:", err);
+ setError("Error fetching weather data");
+ });
+ },
+ (error) => {
+ console.error("Error getting location:", error);
+ setError("Error getting location");
+ }
+ );
+ } else {
+ console.log("Geolocation is not supported by this browser.");
+ setError("Geolocation is not supported by this browser.");
+ }
+ }, []); // The empty array ensures this runs once when the component mounts
+
+ return (
+
+
Your Location Weather
+ {weatherData ? (
+
+
Temperature: {weatherData.main.temp}°C
+
Weather: {weatherData.weather[0]?.description}
+
Location: {weatherData.name}
+
+ ) : (
+
{error ? error : "Fetching weather..."}
+ )}
+
+ );
+};
+
+export default LocationComponent;
diff --git a/client/vite.config.js b/client/vite.config.js
index 5a33944..ce1b2cf 100644
--- a/client/vite.config.js
+++ b/client/vite.config.js
@@ -1,7 +1,16 @@
-import { defineConfig } from 'vite'
-import react from '@vitejs/plugin-react'
+// vite.config.js
+import { defineConfig } from 'vite';
+import react from '@vitejs/plugin-react';
-// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
-})
+ server: {
+ proxy: {
+ '/weather': {
+ target: 'http://localhost:5000', // Your Flask server URL
+ changeOrigin: true,
+ rewrite: (path) => path.replace(/^\/weather/, '/weather'),
+ },
+ },
+ },
+});
diff --git a/server/api/.env b/server/api/.env
index e07104f..c246951 100644
--- a/server/api/.env
+++ b/server/api/.env
@@ -1,2 +1,4 @@
MOVIE_API_HOST=0.0.0.0
MOVIE_API_PORT=5000
+OPENWEATHER_API_KEY=9291dbdcabf7c26431129cb4438c30e1
+
diff --git a/server/api/app.py b/server/api/app.py
index 4b834d8..1412be4 100755
--- a/server/api/app.py
+++ b/server/api/app.py
@@ -1,14 +1,18 @@
#!/usr/bin/env python3
""" Starts the Flask web app """
import os
+
+import requests
from dotenv import load_dotenv
-from flask import Flask, jsonify
+from flask import Flask, jsonify, request
from models import storage
from api.views import app_views
+from flask_cors import CORS
load_dotenv()
app = Flask(__name__)
+CORS(app)
app.url_map.strict_slashes = False
app.register_blueprint(app_views)
HOST = "0.0.0.0"
@@ -16,10 +20,49 @@
SECRET_KEY = os.getenv('SECRET_KEY')
+OPENWEATHER_API_KEY = os.getenv('OPENWEATHER_API_KEY')
+
+
+def get_weather(lat, lon):
+ base_url = "https://api.openweathermap.org/data/2.5/weather"
+ params = {
+ 'lat': lat,
+ 'lon': lon,
+ 'appid': OPENWEATHER_API_KEY,
+ 'units': 'metric'
+ }
+
+ response = requests.get(base_url, params=params)
+
+ if response.status_code == 200:
+ print(response.json)
+ return response.json() # Return the weather data as JSON
+ else:
+ return None # Return None if the request failed
+
+
+@app.route('/weather', methods=['GET'])
+def weather():
+ lat = request.args.get('lat')
+ lon = request.args.get('lon')
+
+ print(f'Latitude: {lat}, Longitude: {lon}')
+
+ if not lat or not lon:
+ return jsonify({'error': 'Missing latitude or longitude'}), 400
+
+ weather_data = get_weather(lat, lon)
+
+ if weather_data:
+ return jsonify(weather_data)
+ else:
+ return jsonify({'error': 'Failed to fetch weather data'}), 500
+
+
@app.route('/volumes')
def volume():
""" A dummy route to test volumes of docker"""
- return "Testing volumes: -Zidane Square headed-"
+ return "Testing volumes: -Zidane -"
@app.teardown_appcontext
diff --git a/server/flask.dockerfile b/server/flask.dockerfile
index 824a45b..48ac92a 100644
--- a/server/flask.dockerfile
+++ b/server/flask.dockerfile
@@ -9,7 +9,7 @@ WORKDIR /movie_name
COPY . /movie_name
-RUN pip3 install flask==2.1.0 werkzeug==2.1.1 flask-cors==4.0.1 sqlalchemy==1.4.22 mysqlclient==2.2.4 python-dotenv
+RUN pip3 install flask==2.1.0 werkzeug==2.1.1 flask-cors==4.0.1 sqlalchemy==1.4.22 mysqlclient==2.2.4 python-dotenv requests
RUN apt-get clean && rm -rf /var/lib/apt/lists/*