cd c:\xampp\htdocs\xtractor
pip install -r requirements.txtpython test_setup.pyExpected output: Total: 5/5 tests passed
python app.pyYou should see:
* Running on http://127.0.0.1:5000
* Press CTRL+C to quit
Open your browser and navigate to:
http://localhost:5000
Invoke-WebRequest -Uri "http://localhost:5000/api/states" | ConvertFrom-Jsoncurl "http://localhost:5000/api/states"Expected response: [] (empty array, no data yet)
curl -X POST -F "file=@C:\path\to\your\pdf\file.pdf" http://localhost:5000/api/upload$file = "C:\path\to\your\pdf\file.pdf"
$uri = "http://localhost:5000/api/upload"
$form = @{
file = Get-Item -Path $file
}
Invoke-WebRequest -Uri $uri -Method Post -Form $formAfter uploading a PDF, test these endpoints:
curl "http://localhost:5000/api/states"curl "http://localhost:5000/api/states/1/lgas"curl "http://localhost:5000/api/lgas/1/wards"curl "http://localhost:5000/api/search?q=lagos&type=state"curl "http://localhost:5000/api/status"curl "http://localhost:5000/api/export" | Out-File -FilePath exported_data.json| Directory | Purpose |
|---|---|
uploads/ |
Uploaded PDF files |
extracted_data/ |
Exported JSON files |
data/ |
SQLite database |
app/ |
Application source code |
templates/ |
HTML templates |
static/ |
CSS and JavaScript files |
Edit .env:
PORT=8000 # instead of 5000Edit .env:
DATABASE_URL=sqlite:///./data/my_database.dbEdit .env:
FLASK_ENV=productionpip install pdfplumber==0.10.3# Change PORT in .env to 8000, 8080, or any available porticacls uploads /grant Everyone:F /T# Delete the database and restart
Remove-Item -Path data\xtractor.db
python app.py-
Start the server
python app.py
-
Upload a PDF file
curl -X POST -F "file=@electoral_data.pdf" http://localhost:5000/api/upload
-
Check extraction status
curl "http://localhost:5000/api/status" -
Search for specific data
curl "http://localhost:5000/api/search?q=ajeromi&type=lga" -
Export all extracted data
curl "http://localhost:5000/api/export" | Out-File export.json
- PDFExtractor - Reads PDF files and extracts text/tables
- DatabaseManager - Saves/retrieves data from SQLite
- ExtractionService - Orchestrates the extraction process
- Routes - Provides HTTP API endpoints
- Models - Defines database schema (State, LGA, Ward)
| File | Contains |
|---|---|
app/models.py |
Database models |
app/parser.py |
PDF extraction logic |
app/database.py |
Database operations |
app/extraction_service.py |
Service layer |
app/routes.py |
API endpoints |
app.py |
Server entry point |
.env |
Configuration |
requirements.txt |
Dependencies |
- Flask Documentation: https://flask.palletsprojects.com/
- SQLAlchemy ORM: https://docs.sqlalchemy.org/
- pdfplumber Documentation: https://github.com/jsvine/pdfplumber
Press CTRL+C in the terminal where the server is running.
- ✓ Server starts without errors
- ✓ Can access http://localhost:5000
- ✓ API endpoints return responses
- ✓ Can upload PDF files
- ✓ Database creates entries after upload
- ✓ Can query extracted data
Need Help? Check the comprehensive README.md for detailed API documentation.