Init
This commit is contained in:
		
						commit
						bf6c81e157
					
				
							
								
								
									
										20
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| # Use the official Python image from the Docker Hub | ||||
| FROM python:3.11-slim | ||||
| 
 | ||||
| # Set the working directory | ||||
| WORKDIR /app | ||||
| 
 | ||||
| # Copy the requirements file into the container | ||||
| COPY requirements.txt . | ||||
| 
 | ||||
| # Install the dependencies | ||||
| RUN pip install --no-cache-dir -r requirements.txt | ||||
| 
 | ||||
| # Copy the rest of the application code | ||||
| COPY . . | ||||
| 
 | ||||
| # Expose the port the app runs on | ||||
| EXPOSE 8000 | ||||
| 
 | ||||
| # Command to run the application | ||||
| CMD ["python", "main.py"] | ||||
							
								
								
									
										46
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,46 @@ | ||||
| # FastAPI DateTime Service | ||||
| 
 | ||||
| This is a simple FastAPI application that provides an OpenAPI-compatible `/datetime` endpoint returning the current date, time, weekday, and calendar week. | ||||
| 
 | ||||
| ## Requirements | ||||
| 
 | ||||
| - Python 3.7+ | ||||
| - FastAPI | ||||
| - Uvicorn | ||||
| 
 | ||||
| ```bash | ||||
| pip install -r requirements.txt | ||||
| ``` | ||||
| 
 | ||||
| ## Running the Application | ||||
| 
 | ||||
| To start the FastAPI server, run: | ||||
| 
 | ||||
| ```bash | ||||
| python main.py | ||||
| ``` | ||||
| 
 | ||||
| The server will be available at `http://localhost:8000`. | ||||
| 
 | ||||
| ## Endpoints | ||||
| 
 | ||||
| ### `GET /datetime` | ||||
| 
 | ||||
| Returns current date, time, weekday, and calendar week. | ||||
| 
 | ||||
| **Response Format:** | ||||
| 
 | ||||
| ```json | ||||
| { | ||||
|   "date": "2025-09-22", | ||||
|   "time": "14:30:45", | ||||
|   "weekday": "Monday", | ||||
|   "calendar_week": 38 | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| **Response Fields:** | ||||
| - `date` (string): Current date in YYYY-MM-DD format | ||||
| - `time` (string): Current time in HH:MM:SS format | ||||
| - `weekday` (string): Full weekday name (e.g., "Monday") | ||||
| - `calendar_week` (integer): ISO calendar week number | ||||
							
								
								
									
										43
									
								
								main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								main.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,43 @@ | ||||
| from fastapi import FastAPI | ||||
| from datetime import datetime | ||||
| import calendar | ||||
| from typing import Any | ||||
| 
 | ||||
| app = FastAPI() | ||||
| 
 | ||||
| @app.get( | ||||
|     "/datetime", | ||||
|     summary="Get Current Date and Time Information", | ||||
|     description="""Returns the current date, time, weekday, and calendar week. | ||||
| This endpoint provides time-related information in a structured JSON format | ||||
| that can be used for various applications including logging, timestamps, | ||||
| and scheduling. | ||||
| 
 | ||||
| **Response Fields:** | ||||
| - `date` (string): Current date in YYYY-MM-DD format | ||||
| - `time` (string): Current time in HH:MM:SS format | ||||
| - `weekday` (string): Full weekday name (e.g., "Monday") | ||||
| - `calendar_week` (integer): ISO calendar week number | ||||
| """, | ||||
|     tags=["datetime"], | ||||
|     response_model=dict, | ||||
|     response_description="Current date and time information" | ||||
| ) | ||||
| async def get_datetime() -> dict[str, Any]: | ||||
|     """ | ||||
|     Get current date and time information. | ||||
| 
 | ||||
|     Returns: | ||||
|         dict: A dictionary containing current date, time, weekday, and calendar week | ||||
|     """ | ||||
|     now = datetime.now() | ||||
|     return { | ||||
|         "date": now.strftime("%Y-%m-%d"), | ||||
|         "time": now.strftime("%H:%M:%S"), | ||||
|         "weekday": now.strftime("%A"), | ||||
|         "calendar_week": now.isocalendar().week | ||||
|     } | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     import uvicorn | ||||
|     uvicorn.run(app, host="0.0.0.0", port=8000) | ||||
							
								
								
									
										2
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| fastapi | ||||
| uvicorn | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user