|
|
3 days ago | |
|---|---|---|
| .vscode | 3 days ago | |
| src | 3 days ago | |
| .dev.vars.example | 3 days ago | |
| .editorconfig | 3 days ago | |
| .gitignore | 4 days ago | |
| .prettierrc | 3 days ago | |
| AGENTS.md | 4 days ago | |
| CLAUDE.md | 3 days ago | |
| README.md | 3 days ago | |
| package-lock.json | 4 days ago | |
| package.json | 3 days ago | |
| tsconfig.json | 3 days ago | |
| worker-configuration.d.ts | 4 days ago | |
| wrangler.jsonc | 3 days ago |
A Cloudflare Workers Scheduled Worker that automatically fetches exchange rates from Open Exchange Rates API and updates a Notion database.
Create a Notion database with the following properties:
| Property | Type |
|---|---|
| Code | Title |
| Rate | Number |
| Updated At | Date |
Then:
# Clone the repository
git clone git@ssh.git.ac:kotoyuuko/notion-exrate-worker.git
cd notion-exrate-worker
# Install dependencies
npm install
Copy the example environment file:
cp .dev.vars.example .dev.vars
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
# 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 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
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Info page |
/convert |
GET | Convert currency |
/sync |
GET | Sync rates to Notion |
GET /convert?from=USD&to=CNY&amount=100
Parameters:
from - Source currency code (e.g., USD, EUR, JPY)to - Target currency codeamount - Amount to convertResponse:
{
"success": true,
"from": "USD",
"to": "CNY",
"amount": 100,
"rate": 6.9002,
"result": 690.02,
"timestamp": 1773900000000
}
GET /sync
Response:
{
"success": true,
"currenciesFound": 173,
"ratesFetched": 172,
"succeeded": 172,
"failed": 0,
"errors": []
}
MIT