A Flask-based REST API that provides a session handling and checkins for the CheckOut AutoCheckin system.
- Features
- AutoCheckin Process
- Setup
- Static Files
- Development Server
- Production Deployment
- API Endpoints
- Contributing
- Error Handling
- Acknowledgments
- RESTful API design
- API Key authentication testing
- Standardized JSON responses
- Proper error handling
- Environment configuration
- Production-ready with Gunicorn support
- Public static file serving
The AutoCheckin system operates in two modes:
The system runs an intelligent background scheduler that:
- Runs automatically at random intervals (between 1-5 hours) to avoid detection
- Processes users in random order with random delays between each user (0-10 minutes)
- For each user:
- Refreshes their session token to maintain authentication
- Updates their status in the system
- Logs any issues or successes
The system also provides immediate code submission through the /api/v1/try-codes
endpoint:
- Fetches and sorts available codes from CheckOut by reputation score
- For each registered user:
- Refreshes their session token and obtains CSRF token
- Gets their current event schedule
- For each event not marked as "Present":
- Tries available codes until one works
- Logs successful checkins back to CheckOut
- Moves to next event on success
- Returns detailed statistics about the process:
- Total number of users processed
- Number of successful submissions
- Timestamp of the operation
This dual-mode operation ensures both automated background processing and the ability to manually trigger checkins when needed.
- Clone the repository:
git clone https://github.com/jameshaworthcs/AutoCheckin.git
cd AutoCheckin
- Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
cp .env.example .env
Edit .env
file with your specific configuration. Make sure to set the CHECKOUT_API_KEY
for authentication testing.
The /public
directory is used to serve static files without authentication. This is useful for:
- Favicons (
favicon.ico
,favicon.svg
) - Images
- Other public assets
To serve a static file, simply place it in the public
directory and access it at the root URL.
Ensure the CHECKOUT_API_URL
is set in .env and you have 'autosysop' permissions with the CHECKOUT_API_KEY
you're using.
Tip: When running AutoCheckin in WSL and CheckOut within Windows, run this command within wsl to find the IP address for your windows 'localhost':
ip route show | grep -i default | awk '{ print $3}'
This can often change on reboot, so will need to be updated if this is how you're developing.
To run the development server:
python main.py
The server will start on http://localhost:5000 (or the PORT specified in your .env file)
For production deployment, this project includes a Procfile for platforms like Railway. The Procfile uses Gunicorn as the WSGI server:
web: gunicorn main:app
- GET
/
- Returns API information and available endpoints
- GET/POST
/api/v1/auth/test
- Tests if the provided API key matches the configured key
- Required Headers:
x-checkout-key: your-api-key-here
- Response Format:
{ "success": true, "message": "Authentication Test Result", "data": { "authenticated": true|false } }
-
GET
/api/v1/status
- Returns the current API connection status
- Response Format:
{ "success": true, "message": "API Status", "data": { "connected": true|false } }
-
GET
/api/v1/state
- Returns the global state including connection status and stored data
- Response Format:
{ "success": true, "message": "Global State", "data": { "connected": true|false, "stored_data": { "last_users_fetch": "2024-03-21T10:30:00Z", "last_all_session_refresh": "2024-03-21T10:35:00Z", "last_individual_session_refresh": "2024-03-21T10:40:00Z", "autoCheckinUsers": [...] } } }
-
GET
/api/v1/refresh
- Refreshes and returns all user checkin sessions
- Response Format:
{ "success": true, "message": "Checkin sessions refreshed successfully", "data": { "sessions": [...] } }
-
GET
/api/v1/refresh-session/<email>
- Refreshes and returns a specific user's checkin session
- Parameters:
email
: Email address of the user
- Response Format:
{ "success": true, "message": "Checkin session refreshed successfully", "data": { "session": {...} } }
-
GET
/api/v1/fetch-attendance
- Triggers an attendance fetch for all users
- Forces an immediate run of the attendance checker
- Optional Query Parameters:
year
: Specific academic year to fetch attendance for (e.g., 2023)week
: Specific week number to fetch attendance for (e.g., 42)
- Response Format:
{ "success": true, "message": "Attendance fetch completed successfully", "data": { "success": true, "year": 2023, "week": 42 } }
- Error Response Format:
{ "success": false, "message": "Attendance fetch failed", "error": "Error description" }
-
GET
/api/v1/fetch-attendance-by-user
- Triggers an attendance fetch for a specific user by email
- Required Query Parameters:
email
: Email address of the user to fetch attendance for
- Optional Query Parameters:
year
: Specific academic year to fetch attendance for (e.g., 2023)week
: Specific week number to fetch attendance for (e.g., 42)
- Response Format:
{ "success": true, "message": "Attendance fetch for user@example.com completed successfully", "data": { "success": true, "email": "user@example.com", "year": 2023, "week": 42 } }
- Error Response Format:
{ "success": false, "message": "Attendance fetch for user@example.com failed", "error": "User not found or fetch failed", "status_code": 404 }
-
GET
/api/v1/fetch-prior-attendance
- Fetches attendance data for all weeks defined in the academic calendar
- Uses the weekCommencing dates to calculate ISO week numbers
- Required Query Parameters (one of the following):
email
: Email address of the user to fetch attendance forfetchall
: Set to "true" to fetch for all users instead of a specific email
- Response Format:
{ "success": true, "message": "Prior attendance fetch for user@example.com completed", "data": { "results": [ { "weekCommencing": "2024-09-16", "weekNumber": "F", "isoYear": 2024, "isoWeek": 38, "status": "success" }, { "weekCommencing": "2024-09-23", "weekNumber": "1", "isoYear": 2024, "isoWeek": 39, "status": "success" } ], "errors": [], "totalWeeks": 38, "successfulFetches": 38, "failedFetches": 0 } }
- Error Response Format:
{ "success": false, "message": "Prior attendance fetch failed", "error": "Error description", "status_code": 500 }
- Partial Success Response (HTTP 207):
{ "success": false, "message": "Prior attendance fetch for user@example.com completed", "data": { "results": [...], "errors": [ { "weekCommencing": "2024-10-07", "weekNumber": "3", "isoYear": 2024, "isoWeek": 41, "error": "Error description" } ], "totalWeeks": 38, "successfulFetches": 37, "failedFetches": 1 }, "status_code": 207 }
- GET
/api/v1/fetch-users
- Triggers a new fetch of users from the CheckOut API
- Response Format:
{ "success": true, "message": "User fetch completed", "data": { "success": true } }
-
GET
/api/v1/codes
- Returns a sorted list of available codes from the CheckOut API
- Response Format:
{ "success": true, "message": "Available codes retrieved successfully", "data": { "codes": [123456, 123457, ...] } }
-
GET
/api/v1/try-codes
- Attempts to use available codes for all users' events
- For each user:
- Refreshes their session token
- Gets their current events
- Tries available codes for each event not marked as present
- Logs successful checkins to CheckOut API
- Response Format:
{ "success": true, "message": "Code submission completed", "data": { "total_users": 10, "processed_users": 8, "timestamp": "2024-03-21T10:45:00Z" } }
This project uses Black for code formatting. Black is an uncompromising Python code formatter that ensures consistent style across the project.
To format your code:
- Install Black (it's included in requirements.txt):
pip install black
- Format your code before committing:
black .
- To check if your code is properly formatted without making changes:
black --check .
Note: The project includes a GitHub Actions workflow that automatically checks if all Python files conform to Black's formatting standards. Pull requests will fail if the code is not properly formatted.
To ensure your contributions are accepted:
- Run
black .
locally before committing - Verify all files pass the check with
black --check .
- Fix any formatting issues before pushing your changes
All errors return a standardized JSON response:
{
"success": false,
"message": "API Error",
"error": "Error description"
}
Common HTTP status codes:
- 200: Successful operation
- 400: Bad request (missing or invalid API key)
- 404: Endpoint not found
- 405: Method not allowed
- 500: Internal server error
Special thanks to actorpus for the initial revision of checkin code that this project ultimately stemmed from.