Browse Source

docs: add README.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kotoyuuko 4 days ago
parent
commit
4199d95a6e
1 changed files with 126 additions and 0 deletions
  1. 126 0
      README.md

+ 126 - 0
README.md

@@ -0,0 +1,126 @@
+# Notion Exchange Rate Worker
+
+A Cloudflare Workers Scheduled Worker that automatically fetches exchange rates from Open Exchange Rates API and updates a Notion database.
+
+## Features
+
+- 🔄 Hourly automatic sync via Cron trigger
+- 🔌 Manual sync via HTTP endpoint
+- 💱 Supports 170+ currencies
+- ⚡ Fast and serverless
+
+## Setup
+
+### Prerequisites
+
+- Node.js 18+
+- Cloudflare account
+- [Open Exchange Rates API](https://openexchangerates.org/) App ID
+- Notion Integration Token
+
+### Notion Setup
+
+1. Create a Notion database with the following properties:
+
+   | Property | Type |
+   |----------|------|
+   | Code | Title |
+   | Rate | Number |
+   | Updated At | Date |
+
+2. Create a Notion Integration at https://www.notion.so/my-integrations
+3. Share your database with the integration
+
+### Installation
+
+```bash
+# Clone the repository
+git clone git@ssh.git.ac:kotoyuuko/notion-exrate-worker.git
+cd notion-exrate-worker
+
+# Install dependencies
+npm install
+```
+
+### Configuration
+
+1. Copy the example environment file:
+   ```bash
+   cp .dev.vars.example .dev.vars
+   ```
+
+2. Fill in your credentials in `.dev.vars`:
+   ```
+   OXR_APP_ID=your_open_exchange_rates_app_id
+   NOTION_TOKEN=your_notion_integration_token
+   NOTION_DATABASE_ID=your_notion_database_id
+   ```
+
+### Local Development
+
+```bash
+# Start development server
+npm run dev
+
+# Test scheduled handler
+curl "http://localhost:8787/__scheduled?cron=0+*+*+*+*"
+
+# Or use manual sync endpoint
+curl "http://localhost:8787/sync"
+```
+
+### Deploy
+
+```bash
+# Deploy to Cloudflare Workers
+npm run deploy
+
+# Set production secrets
+wrangler secret put OXR_APP_ID
+wrangler secret put NOTION_TOKEN
+wrangler secret put NOTION_DATABASE_ID
+```
+
+## Usage
+
+### Automatic Sync
+
+The worker runs automatically every hour via Cron trigger.
+
+### Manual Sync
+
+Send a GET request to the `/sync` endpoint:
+
+```bash
+curl https://your-worker.workers.dev/sync
+```
+
+Response:
+```json
+{
+  "success": true,
+  "currenciesFound": 173,
+  "ratesFetched": 172,
+  "succeeded": 172,
+  "failed": 0,
+  "errors": []
+}
+```
+
+## API Reference
+
+| Endpoint | Method | Description |
+|----------|--------|-------------|
+| `/` | GET | Info page |
+| `/sync` | GET | Manually trigger exchange rate sync |
+
+## Tech Stack
+
+- [Cloudflare Workers](https://workers.cloudflare.com/)
+- [Open Exchange Rates API](https://openexchangerates.org/)
+- [Notion API](https://developers.notion.com/)
+- TypeScript
+
+## License
+
+MIT