test_ken_dev

Untitled

Jan 24th, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | Software | 0 0
  1. # Synergy Daily Basket
  2.  
  3. ## Overview
  4.  
  5. This Flask application is designed to fetch daily sales data from the Foodbasket API, generate Excel reports, and send email notifications to designated recipients. The app handles large datasets efficiently by batching API requests and sending vouchers and BIS reports.
  6.  
  7. ## Features
  8.  
  9. - Fetch sales data in batches from the Foodbasket API for both orders and invoices.
  10. - Filter data by date and payment method.
  11. - Generate Excel reports with detailed sales information.
  12. - Manage email recipients for notifications.
  13. - Designed with error handling for API requests and data processing.
  14.  
  15. ## Technologies Used
  16.  
  17. - **Flask**: Web framework for Python.
  18. - **OpenPyXL**: Library for working with Excel files.
  19. - **Resend**: API for sending emails.
  20. - **SQLAlchemy**: ORM for database operations.
  21. - **Requests**: HTTP library for making API calls.
  22. - **Docker**: For containerizing the application.
  23.  
  24. ## Project Structure
  25.  
  26. ```
  27. ├── app
  28. | ├── models.py
  29. | ├── routes.py
  30. | ├── tasks.py
  31. | ├── __init__.py
  32. | └── __pycache__
  33. ├── cert.pem
  34. ├── config.py
  35. ├── docker-compose.yml
  36. ├── Dockerfile
  37. ├── instance
  38. | └── db.sqlite3
  39. ├── key.pem
  40. ├── migrations
  41. | ├── alembic.ini
  42. | ├── env.py
  43. | ├── README
  44. | ├── script.py.mako
  45. | ├── versions
  46. | └── __pycache__
  47. ├── README.md
  48. ├── requirements.txt
  49. ├── run.py
  50. ├── synergy-daily-basket.tar
  51. └── __pycache__
  52. └── config.cpython-311.pyc
  53. ```
  54.  
  55. ### Key Files
  56.  
  57. - `app/routes.py`: Contains all the application routes for fetching data, generating Excel reports, and managing email recipients.
  58. - `app/models.py`: Defines the database schema for managing email recipients.
  59. - `config/config.py`: Stores configuration variables such as API keys and database URLs.
  60.  
  61. ## Installation
  62.  
  63. 1. Clone the repository:
  64.  
  65. ```bash
  66. git clone <repository-url>
  67. cd <repository-folder>
  68. ```
  69.  
  70. 2. Create and activate a virtual environment:
  71.  
  72. ```bash
  73. python -m venv .venv
  74. source .venv/bin/activate
  75. # On Windows: .venv\Scripts\activate
  76. ```
  77.  
  78. 3. Install dependencies:
  79.  
  80. ```bash
  81. pip install -r requirements.txt
  82. ```
  83.  
  84. 4. Set up environment variables: Create a `.env` file in the root directory and add the variables specified in _.env.example_
  85.  
  86. 5. Initialize the database:
  87.  
  88. ```bash
  89. flask db upgrade
  90. ```
  91.  
  92. 6. Run the application:
  93.  
  94. ```bash
  95. flask run
  96. ```
  97.  
  98. ## API Endpoints
  99.  
  100. ### Data Retrieval
  101.  
  102. #### Fetch Orders - Voucher Sales
  103.  
  104. - **URL**: `/orders-daily-voucher-sales`
  105. - **Method**: `GET`
  106. - **Description**: Fetch daily orders paid with vouchers.
  107.  
  108. #### Fetch Invoices - Voucher Sales
  109.  
  110. - **URL**: `/invoices-daily-voucher-sales`
  111. - **Method**: `GET`
  112. - **Description**: Fetch daily invoices paid with vouchers.
  113.  
  114. #### Fetch Orders - BIS Sales
  115.  
  116. - **URL**: `/orders-daily-bis-sales`
  117. - **Method**: `GET`
  118. - **Description**: Fetch daily orders paid with BIS.
  119.  
  120. #### Fetch Invoices - BIS Sales
  121.  
  122. - **URL**: `/invoices-daily-bis-sales`
  123. - **Method**: `GET`
  124. - **Description**: Fetch daily invoices paid with BIS.
  125.  
  126. ### Email Management
  127.  
  128. #### Get All Email Recipients
  129.  
  130. - **URL**: `/email-recipients`
  131. - **Method**: `GET`
  132. - **Description**: Retrieve all registered email recipients.
  133.  
  134. #### Add a New Email Recipient
  135.  
  136. - **URL**: `/email-recipients`
  137. - **Method**: `POST`
  138. - **Description**: Add a new recipient to the email list.
  139. - **Payload**:
  140. ```json
  141. {
  142. "email": "[email protected]",
  143. "name": "John Doe",
  144. "active": true
  145. }
  146. ```
  147.  
  148. ## Error Handling
  149.  
  150. - Handles connection errors, timeouts, and unexpected server errors when fetching data from the Foodbasket API.
  151. - Validates the presence of expected fields in API responses.
  152. - Ensures no duplicate email entries when adding recipients.
  153.  
  154. ## Planned Enhancements
  155.  
  156. 1. **Implement Celery**:
  157.  
  158. - Implement celery with redis as broker into this project. The tasks.py file is already included. That's where the tasks will be defined. There is already a docker compose yml file to run the flask app along with the redis broker and celery worker. There is also going to be task defined inside of tasks.py that will run every day at 1AM.
  159.  
  160. ## Contribution Guidelines
  161.  
  162. 1. Fork the repository and clone it locally.
  163. 2. Create a new feature branch:
  164. ```bash
  165. git checkout -b feature-name
  166. ```
  167. 3. Commit your changes:
  168. ```bash
  169. git commit -m "your descriptive commit message"
  170. ```
  171. 4. Push the branch and create a pull request.
  172.  
Advertisement
Add Comment
Please, Sign In to add comment