amzn-top-100-trckrscheduler.ts5 matches
1// Daily cron job to scrape Amazon bestsellers
2import { initializeDatabase } from "./backend/database/migrations.ts";
3import { saveBooks } from "./backend/database/queries.ts";
4import { scrapeBooks } from "./backend/scraper.ts";
58
9try {
10// Ensure database is initialized
11await initializeDatabase();
12
13// Add a small delay to avoid immediate rate limiting
18
19if (result.success && result.books && result.books.length > 0) {
20// Save the books to the database
21await saveBooks(result.books);
22console.log(`โ Scraping completed successfully: ${result.booksFound} books found and saved`);
amzn-top-100-trckrmigrations.ts2 matches
3const TABLE_NAME = 'amazon_books_v1';
45export async function initializeDatabase() {
6// Create the main books table
7await sqlite.execute(`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
23await sqlite.execute(`CREATE INDEX IF NOT EXISTS idx_rank ON ${TABLE_NAME} (rank, scraped_at)`);
24
25console.log("Database initialized successfully");
26}
27
reactHonoStarterREADME.md1 match
9- The **client-side entrypoint** is `/frontend/index.html`, which in turn imports `/frontend/index.tsx`, which in turn imports the React app from `/frontend/components/App.tsx`.
1011[React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a fuller featured example project, with a SQLite database table, queries, client-side CSS and a favicon, and some shared code that runs on both client and server.
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { initializeDatabase } from "./database/migrations.ts";
4import { getAllTodos } from "./database/queries.ts";
5import todosRouter from "./routes/todos.ts";
612});
1314// Initialize database on startup
15await initializeDatabase();
1617// API routes
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { getAllTodos, createTodo, updateTodo, deleteTodo } from "../database/queries.ts";
3import type { CreateTodoRequest, UpdateTodoRequest } from "../../shared/types.ts";
4
CoolTownmigrations.ts1 match
3export const TABLE_NAME = 'todos_v1';
45export async function initializeDatabase() {
6await sqlite.execute(`
7CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
15```
16โโโ backend/
17โ โโโ database/
18โ โ โโโ migrations.ts # Database schema
19โ โ โโโ queries.ts # Database operations
20โ โโโ routes/
21โ โ โโโ todos.ts # Todo API routes
40## Development
4142The app runs on Val Town with automatic deployment. The database is automatically initialized on first run.
book-lookup-notionnotion.ts10 matches
1/**
2* Notion API integration for book database
3*/
42829export interface BookMetadata {
30// Core fields (mapped to Notion database)
31title?: string;
32author?: string;
5960/**
61* Get records from Notion database that need metadata enrichment
62* This includes:
63* 1. Records with Title + Author but missing other metadata
66export async function getIncompleteRecords(): Promise<NotionBookRecord[]> {
67const token = Deno.env.get('NOTION_API_TOKEN');
68const databaseId = Deno.env.get('NOTION_DATABASE_ID');
69
70if (!token || !databaseId) {
71throw new Error('Missing NOTION_API_TOKEN or NOTION_DATABASE_ID environment variables');
72}
7374console.log('Debug info:', {
75tokenPrefix: token.substring(0, 10) + '...',
76databaseIdLength: databaseId.length,
77databaseIdPrefix: databaseId.substring(0, 8) + '...'
78});
7980const response = await fetch(`${NOTION_API_BASE}/databases/${databaseId}/query`, {
81method: 'POST',
82headers: {
464
465if (!additionalResponse.ok) {
466console.log(`Property "${propName}" doesn't exist in database, skipping...`);
467}
468} catch (error) {
book-lookup-notionindex.ts16 matches
1/**
2* Notion Book Database Auto-Populator
3* Main HTTP handler and API endpoints
4*/
44app.get('/status', async (c) => {
45const hasNotionToken = !!Deno.env.get('NOTION_API_TOKEN');
46const hasNotionDatabase = !!Deno.env.get('NOTION_DATABASE_ID');
47
48const status = {
49configured: hasNotionToken && hasNotionDatabase,
50notion_token: hasNotionToken ? 'Set' : 'Missing',
51notion_database: hasNotionDatabase ? 'Set' : 'Missing',
52timestamp: new Date().toISOString()
53};
60setup_instructions: {
61notion_token: 'Set NOTION_API_TOKEN environment variable with your Notion integration token',
62notion_database: 'Set NOTION_DATABASE_ID environment variable with your book database ID'
63}
64}, 400);
110app.get('/debug', (c) => {
111const token = Deno.env.get('NOTION_API_TOKEN');
112const databaseId = Deno.env.get('NOTION_DATABASE_ID');
113
114return c.json({
118prefix: token?.substring(0, 10) + '...' || 'N/A'
119},
120database_info: {
121exists: !!databaseId,
122length: databaseId?.length || 0,
123prefix: databaseId?.substring(0, 8) + '...' || 'N/A'
124}
125});
171app.get('/help', (c) => {
172return c.json({
173title: 'Notion Book Database Auto-Populator',
174description: 'Automatically enriches your Notion book database with metadata from Google Books API',
175endpoints: {
176'GET /': 'Process all incomplete records',
183step1: 'Create a Notion integration at https://www.notion.so/my-integrations',
184step2: 'Copy the integration token and set it as NOTION_API_TOKEN environment variable',
185step3: 'Share your book database with the integration',
186step4: 'Copy the database ID from the URL and set it as NOTION_DATABASE_ID environment variable',
187step5: 'Ensure your database has these properties: Title (title), Author (rich text), ISBN (rich text), Year Published (number), Page Count (number), Publisher (rich text)'
188},
189database_properties: {
190required: ['Title (title)', 'Author (rich text)'],
191populated: ['ISBN (rich text)', 'Year Published (number)', 'Page Count (number)', 'Publisher (rich text)'],
book-lookup-notioncron-processor.ts4 matches
15if (result.totalProcessed > 0) {
16const summary = `
17๐ Book Database Update Complete
1819๐ Summary:
3940await email({
41subject: `๐ Book Database Updated - ${result.successful} books enriched`,
42text: summary
43});
52// Send error notification
53await email({
54subject: 'โ Book Database Update Failed',
55text: `
56The scheduled book database update failed with the following error:
5758${error instanceof Error ? error.message : 'Unknown error'}