A TypeScript application that automatically imports and manages trading card data from beckett.com. The application scrapes trading card checklists from URLs, downloads Excel files, and stores the card information in a SQLite database.
- 🃏 Automated Card Import: Import trading card data directly from URLs
- 📊 Excel Processing: Parse and process Excel checklist files
- 🗄️ Database Storage: Store card data in SQLite with Drizzle ORM
- 🏀 Multi-Sport Support: Support for Basketball and Football cards
- 🧪 Comprehensive Testing: Full test suite with Jest
- 📝 Type Safety: Written in TypeScript for better code reliability
trading-cards/
├── src/
│ ├── db/ # Database configuration and services
│ │ ├── index.ts # Database connection
│ │ ├── schema.ts # Database schema definitions
│ │ └── service.ts # Database operations
│ ├── download-file.ts # File download utilities
│ ├── get-set-name.ts # Extract set names from URLs
│ ├── get-xlsx-link.ts # Extract Excel file links
│ ├── import-cards-from-url.ts # Main import functionality
│ ├── index.ts # Application entry point
│ ├── logger.ts # Logging configuration
│ ├── process-cards.ts # Excel file processing
│ └── types.ts # Type definitions
├── tests/ # Test files
├── drizzle/ # Database migrations
├── spreadsheet-downloads/ # Downloaded Excel files
└── database.db # SQLite database file
The application uses a relational database with two main tables:
id: Primary keyname: Set name (e.g., "2024 Panini Prizm Football")year: Release yearsource_file: Original Excel file pathsport: Sport type (Basketball/Football)
id: Primary keycard_number: Card number within the setplayer_name: Player name on the cardcard_type: Type of card (Base, Rookie, etc.)set_id: Foreign key to sets table
- Clone the repository:
git clone <repository-url>
cd trading-cards- Install dependencies:
npm install- Set up the database:
npm run db:generate
npm run db:migrateRun the application to import cards from a URL:
npm startThe default configuration imports from a Panini Prizm Football URL. You can modify the URL in src/index.ts.
Run in development mode with hot reloading:
npm run devimport { importCardsFromUrl } from "./src/import-cards-from-url";
import { Sport } from "./src/types";
// Import football cards
const footballCards = await importCardsFromUrl(
"https://www.beckett.com/news/2024-panini-prizm-football-cards/",
Sport.Football
);
// Import basketball cards
const basketballCards = await importCardsFromUrl(
"https://www.beckett.com/news/2024-25-panini-nba-hoops-basketball-cards/",
Sport.Basketball
);import { dbService } from "./src/db/service";
// Get all sets
const sets = await dbService.getAllSets();
// Get cards by set
const cards = await dbService.getCardsBySetId(1);
// Create a new set
const newSet = await dbService.createSet({
name: "2024 Topps Baseball",
year: "2024",
sourceFile: "topps-2024.xlsx",
sport: "Baseball",
});npm start- Run the applicationnpm run dev- Run in development modenpm run build- Build TypeScript to JavaScriptnpm test- Run the test suitenpm run db:generate- Generate database migrationsnpm run db:migrate- Apply database migrations
The project includes comprehensive tests for all major components:
# Run all tests
npm test
# Run specific test file
npm test -- get-set-name.test.ts
# Run tests in watch mode
npm test -- --watch- TypeScript: Type-safe JavaScript
- Drizzle ORM: Type-safe database operations
- ExcelJS: Excel file processing
- Axios: HTTP client for downloads
- Playwright: Web scraping capabilities
- Pino: High-performance logging
- Zod: Runtime type validation
- Jest: Testing framework
- Drizzle Kit: Database migration tools
Create a .env file in the root directory:
# Database configuration
DATABASE_URL=./database.db
# Logging level
LOG_LEVEL=infoThe project uses modern TypeScript with ES modules. See tsconfig.json for full configuration.
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and add tests
- Run the test suite:
npm test - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License.
Database connection errors:
- Ensure the database file exists:
ls database.db - Run migrations:
npm run db:migrate
Excel parsing errors:
- Check that the downloaded Excel file is valid
- Verify the file structure matches expected format
Network errors:
- Check internet connection
- Verify the source URL is accessible
- Some sites may require user agent headers
For more help, please open an issue on GitHub.