1import { TwitterClient } from "./services/twitter.ts";
2import { initDatabase } from "./database/migrations.ts";
3import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
4import { TWEETS_TABLE } from "./database/migrations.ts";
5
6/**
11
12 try {
13 // Initialize database if needed
14 await initDatabase();
15
16 const twitterClient = new TwitterClient();
1import { Tweet, TwitterUser, upsertTweet, upsertUser, recordMetrics } from "../database/queries.ts";
2
3// Twitter API v2 endpoints
69 };
70
71 // Save user to database
72 await upsertUser(user);
73
97 };
98
99 // Save tweet to database
100 await upsertTweet(tweet);
101
168 };
169
170 // Save tweet to database
171 await upsertTweet(tweet);
172
7
8/**
9 * Initialize database tables
10 */
11export async function initDatabase() {
12 // Create users table
13 await sqlite.execute(`
54 `);
55
56 console.log("Database initialized successfully");
57}
1# Tweet Metrics Tracker
2
3This application scrapes tweets and other metrics from Twitter/X API, stores them in a SQLite database, and displays them in a web interface.
4
5## Features
6
7- Fetches tweets and metrics from Twitter/X API
8- Stores data in SQLite database
9- Periodically updates data using a cron job
10- Displays tweets and metrics in a web interface
15```
16โโโ backend/
17โ โโโ database/
18โ โ โโโ migrations.ts # Schema definitions
19โ โ โโโ queries.ts # DB query functions
14```
15โโโ backend/
16โ โโโ database/
17โ โ โโโ migrations.ts # Schema definitions
18โ โ โโโ queries.ts # DB query functions
29- Frontend: HTML, JavaScript, Tailwind CSS
30- Backend: Hono (API framework)
31- Database: SQLite
32- Real-time updates: Polling
33
6
7export async function runMigrations() {
8 console.log("Starting database migrations...");
9
10 try {
37 console.log(`Table ${CHAT_MESSAGES_TABLE} created successfully`);
38
39 console.log("Database migrations completed successfully");
40 } catch (error) {
41 console.error("Error during migrations:", error);
17```
18โโโ backend/
19โ โโโ database/
20โ โ โโโ migrations.ts # Schema definitions
21โ โ โโโ queries.ts # DB query functions
25 })),
26 system: `You are a helpful sqlite assistant that will tell me information about my
27 sqlite database tables and help me get insights and visualizations from my data.`,
28 tools: {
29 think: thinkTool,
9- [ ] make it one click to branch off like old jp townie demos
10- [ ] opentownie as a pr bot
11- [ ] give it the ability to see its own client-side and server-side logs by building a middleware that shoves them into a SQL light database date and then give it a tool to access them
12- [ ] do a browser use or screenshot thing to give it access to its own visual output
13- [ ] Have it default to creating a new branch off main
7export const thinkTool = tool({
8 description:
9 "Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.",
10 parameters: z.object({
11 thought: z.string().describe("A thought to think about."),