Workflow Automation March 2025 23 views

Almavivabot

A Python-based Bot Backend for Visa Application User Management

Almavivabot

almavivaBot

A Python-based Bot Backend for Visa Application User Management

almavivaBot is a core backend system, primarily focusing on managing user accounts and their associated visa application preferences. Built with Python and SQLite, this system provides a robust and straightforward way to store and retrieve essential user data, including login credentials and specific visa requirements, which can then be utilized by a larger bot application for automation or information processing.

Features

Based on the provided database.py file, the core features include:

  • User Management: Securely add and manage user accounts, each with a unique username and password.
  • Visa Preference Storage: Store detailed visa-related preferences for each user, such as:
    • Application Center: e.g., 'Cairo' (default)
    • Service Level: e.g., 'Standard' (default)
    • Visa Type: Specific type of visa required.
    • Trip Date: Planned travel date.
    • Destination: Country or region of destination.
  • SQLite Database: Persistent and reliable data storage using a local SQLite database file (visa_users.db).
  • Automatic Database Initialization: The database schema (the users table) is automatically created upon first instantiation if it doesn't exist.
  • User Status Management: Includes an active flag for potential user account activation/deactivation.

Technologies Used

  • Python: The primary programming language.
  • SQLite3: A C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. Used for data persistence.

Installation

To get almavivaBot running locally, follow these steps:

  1. Clone the repository:

    git clone https://github.com/your-username/almavivaBot.git
    cd almavivaBot
    
  2. Python Environment: Ensure you have Python 3.x installed. No special pip packages are required for the database.py component as sqlite3 is part of Python's standard library.

    (Optional, but recommended for larger projects): Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    

Database Structure

The VisaDatabase class manages a single table named users with the following schema:

| Column Name | Type | Constraints | Description | | :------------ | :---------- | :------------------------------- | :-------------------------------------------- | | id | INTEGER | PRIMARY KEY AUTOINCREMENT | Unique identifier for each user. | | username | TEXT | UNIQUE NOT NULL | User's unique username for login. | | password | TEXT | NOT NULL | User's password (should be hashed in production). | | center | TEXT | DEFAULT 'Cairo' | Preferred visa application center. | | service_level | TEXT | DEFAULT 'Standard' | Desired service level (e.g., 'Standard', 'Premium'). | | visa_type | TEXT | NULL | Specific type of visa (e.g., 'Tourist', 'Business'). | | trip_date | TEXT | NULL | Planned date of travel. | | destination | TEXT | NULL | Country or region of destination. | | active | INTEGER | DEFAULT 1 | Flag indicating if the user account is active (1 for active, 0 for inactive). | | created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Timestamp when the user account was created. |

Usage

Here's how you can use the VisaDatabase class to manage user data:

from database import VisaDatabase
<h1 id="section-bd9c46e02a7afd97cd8a21dffabc3619">Initialize the database. It will create &#039;visa_users.db&#039; if it doesn&#039;t exist.</h1>
db = VisaDatabase()
<h1 id="section-895f816bbe20d07fe151a8cb2b1e8cdb">--- Adding Users ---</h1>
<h1 id="section-7c6135e58d5da178b0393acd7534d9e9">Add a new user with default visa preferences</h1>
if db.add_user("john_doe", "password123"):
    print("User 'john_doe' added successfully.")
else:
    print("Failed to add user 'john_doe' (username might already exist).")
<h1 id="section-ffe7fd9961908e04fe4d70492adb6630">Add another user with specific visa preferences</h1>
if db.add_user(
    "jane_smith",
    "securepass",
    center="Alexandria",
    service_level="Premium",
    visa_type="Business",
    trip_date="2024-12-01",
    destination="Germany"
):
    print("User 'jane_smith' added successfully with custom preferences.")
else:
    print("Failed to add user 'jane_smith'.")
<h1 id="section-d284b9793364efef8e829f14eea0f607">Attempt to add a duplicate user (will fail)</h1>
if not db.add_user("john_doe", "anotherpass"):
    print("Attempted to add 'john_doe' again, correctly prevented due to unique username constraint.")
<h1 id="section-0313fe2fa629e6268db527b25235e96d">--- (Inferred) Retrieving and Updating User Data ---</h1>
<h1 id="section-a1d1b8b946bba4d26f7e6f8a70ab3cd9">Note: The database.py snippet provided only shows &#039;add_user&#039; and &#039;update_user&#039; (truncated).</h1>
<h1 id="section-e80d787c4ae87d1d8e594c7f626f8036">You would typically add methods to:</h1>
<h1 id="section-2ad0c9644a32cacdb3234e141afa6a9d">- get_user_by_username(username)</h1>
<h1 id="section-33a8f2e5a9936d24550dd92796b03c3f">- get_user_by_id(user_id)</h1>
<h1 id="section-02ce1451fb0193f8a9d44be44e3bdaeb">- update_user(user_id, new_center=None, new_visa_type=None, ...)</h1>
<h1 id="section-899b15ef692d9ab302ac693b3a0b9bbd">- delete_user(user_id)</h1>
<h1 id="section-2c3e90107178033bf3dc5bc85de368e6">Example of how you might update a user (assuming an &#039;update_user&#039; method exists and is complete):</h1>
<h1 id="section-1b21fbbef78ad1dd7f365da70f198fdf">user_id_to_update = 1 # Assuming John Doe is user_id 1</h1>
<h1 id="section-a9273a084aae22e67196fd05872b29ac">if db.update_user(user_id_to_update, center=&#039;Giza&#039;, service_level=&#039;Express&#039;):</h1>
<h1 id="section-68cc540c90375308142012d207a910b4">print(f&quot;User with ID {user_id_to_update} updated successfully.&quot;)</h1>
<h1 id="section-f680da5198ab96a274e835cc5f7ec6aa">else:</h1>
<h1 id="section-672fba41fe4d4fd6e0eeb617d6b9b66e">print(f&quot;Failed to update user with ID {user_id_to_update}.&quot;)</h1>
<h1 id="section-d753f6343edbcede0a73c932b5000622">After operations, the database connection is automatically managed by each method.</h1>
<h1 id="section-1b2861c8b85b7c462e586a96d7177738">If you need a persistent connection for multiple queries, you might manage it explicitly.</h1>

Contributing

Contributions are welcome! If you have suggestions for improvements, new features, or bug fixes, please feel free to:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature-name).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add new feature').
  5. Push to the branch (git push origin feature/your-feature-name).
  6. Open a Pull Request.

License

(This section is a placeholder. Choose a license that fits your project, e.g., MIT, Apache 2.0, GPL.)

This project is licensed under the MIT License.


Client
Mansour
Technologies
Express Python SQLite python

Project Gallery