Merge pull request #1 from aljazceru/claude/convert-currency-hkd-euro-011CUx3QzK9AAL7hCdWv8qfz

Claude/convert currency hkd euro 011 c ux3 qz k9 aal7h cd wv8qfz
This commit is contained in:
2025-11-09 11:28:03 +01:00
committed by GitHub
20 changed files with 364 additions and 87 deletions

View File

@@ -1,14 +1,14 @@
# This is a basic workflow to help you get started with Actions # This is a basic workflow to help you get started with Actions
# Daily job at 04:05 GMT # Daily job at 04:05 GMT
name: Simple update btc rates name: Update EUR BTC rates
on: on:
schedule: schedule:
- cron: '5 4 * * *' - cron: '5 4 * * *'
jobs: jobs:
run: run:
name: update hkdhistorical name: update eurhistorical
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: setup actions - name: setup actions
@@ -21,7 +21,7 @@ jobs:
- name: add and push - name: add and push
run: | run: |
npm install npm install
npm install axios@0.26.1 --save npm install axios@0.26.1 --save
node updaterate.js node updaterate.js
date > generated.txt date > generated.txt

View File

@@ -4,11 +4,11 @@ const moment = require('moment');
const path = require('path'); const path = require('path');
const dirPath = path.join(__dirname, "."); const dirPath = path.join(__dirname, ".");
const fileToWrite = dirPath + "/public/hkd_historical" const fileToWrite = dirPath + "/public/historical"
const fileToRead = dirPath + "/public/hkd_historical" const fileToRead = dirPath + "/public/historical"
// get btc/usd and btc/hkd daily rate // get btc/usd and btc/eur daily rate
async function BTCDaily() { async function BTCDaily() {
let url = "https://api.coingecko.com/api/v3/coins/bitcoin/history?localization=false&date=" let url = "https://api.coingecko.com/api/v3/coins/bitcoin/history?localization=false&date="
@@ -27,17 +27,17 @@ async function BTCDaily() {
// console.log("full url: ", full_url) // console.log("full url: ", full_url)
const data = await response.data; const data = await response.data;
const btcusd = data['market_data']['current_price']['usd'] const btcusd = data['market_data']['current_price']['usd']
const btchkd = data['market_data']['current_price']['hkd'] const btceur = data['market_data']['current_price']['eur']
const satsrate = 100000000 const satsrate = 100000000
const sathkd = parseInt(satsrate / btchkd) const sateur = parseInt(satsrate / btceur)
const usdsat = parseInt(satsrate / btcusd) const usdsat = parseInt(satsrate / btcusd)
row = { row = {
btcusd_rate: parseInt(btcusd), btcusd_rate: parseInt(btcusd),
date: dbdate, date: dbdate,
usdsat_rate: usdsat, usdsat_rate: usdsat,
sathkd_rate: sathkd, sateur_rate: sateur,
btchkd_rate: parseFloat(btchkd).toFixed(2), btceur_rate: parseFloat(btceur).toFixed(2),
} }
console.log("row data: ", row) console.log("row data: ", row)
}) })
@@ -63,10 +63,10 @@ async function updateFile() {
} }
module.exports = { module.exports = {
// start here // start here
main: async function () { main: async function () {
console.log("starting btcpoll script for satshkd....") console.log("starting btcpoll script for sateur....")
let result = updateFile(); let result = updateFile();
console.log(result) console.log(result)
return true return true

View File

@@ -3,7 +3,7 @@ const fs = require('fs');
module.exports = { module.exports = {
bfx: async function() { bfx: async function() {
const hkdrate = 0.1287 // approximate rate const eurrate = 0.92 // approximate EUR/USD rate
const btcDataURL = "https://api-pub.bitfinex.com/v2/ticker/tBTCUSD" const btcDataURL = "https://api-pub.bitfinex.com/v2/ticker/tBTCUSD"
const response = await axios.get(btcDataURL) const response = await axios.get(btcDataURL)
const data = response.data const data = response.data
@@ -13,16 +13,16 @@ module.exports = {
// see docs : https://docs.bitfinex.com/reference#rest-public-ticker // see docs : https://docs.bitfinex.com/reference#rest-public-ticker
btcLastPrice = data[6] btcLastPrice = data[6]
const sathkd = Math.round((1 / btcLastPrice) * satDenominator * hkdrate) const sateur = Math.round((1 / btcLastPrice) * satDenominator * eurrate)
//console.log("bitfinex last price: ", btcLastPrice, "current satHKD: ", sathkd) //console.log("bitfinex last price: ", btcLastPrice, "current satEUR: ", sateur)
return sathkd return sateur
}, },
get10yr: async function() { get10yr: async function() {
// console.log("get10yr") // console.log("get10yr")
try { try {
// const content = await fs.readFile('./public/hkd_historical') // const content = await fs.readFile('./public/historical')
const content = fs.readFileSync('./public/hkd_historical', { encoding: 'utf8' }) const content = fs.readFileSync('./public/historical', { encoding: 'utf8' })
const historical = JSON.parse(content) const historical = JSON.parse(content)
hist_entries = [] hist_entries = []
@@ -45,7 +45,7 @@ module.exports = {
for (var v = 0; v < hist_entries.length; v++) { for (var v = 0; v < hist_entries.length; v++) {
const date = new Date(hist_entries[v]['date']) const date = new Date(hist_entries[v]['date'])
year = date.getFullYear(); year = date.getFullYear();
rawsat = hist_entries[v]['sathkd_rate'] rawsat = hist_entries[v]['sateur_rate']
percentage = (-100 * ((rawsat - today_sats) / rawsat)).toFixed(3) percentage = (-100 * ((rawsat - today_sats) / rawsat)).toFixed(3)
final_list.push({ "year": date.toLocaleDateString(), "sats": rawsat.toLocaleString("en-US"), "percent": percentage }); final_list.push({ "year": date.toLocaleDateString(), "sats": rawsat.toLocaleString("en-US"), "percent": percentage });
} }
@@ -55,4 +55,4 @@ module.exports = {
} }
} }
} }

View File

@@ -11,9 +11,14 @@ const handlebars = require('express-handlebars');
const port = 3000; const port = 3000;
const calculate = require('./calculate') const calculate = require('./calculate')
const zhcnjson = require('./locales/zh-cn.json'); const enjson = require('./locales/en-eur.json');
const zhhkjson = require('./locales/zh-hk.json'); const dejson = require('./locales/de.json');
const enjson = require('./locales/en.json'); const frjson = require('./locales/fr.json');
const esjson = require('./locales/es.json');
const itjson = require('./locales/it.json');
const nljson = require('./locales/nl.json');
const ptjson = require('./locales/pt.json');
const pljson = require('./locales/pl.json');
app.set('view engine', 'hbs'); app.set('view engine', 'hbs');
app.set('views', __dirname + '/views') app.set('views', __dirname + '/views')
@@ -34,31 +39,71 @@ app.use(express.static(path.join(__dirname, 'public', 'css')));
app.get('/', function(req, res) { app.get('/', function(req, res) {
res.redirect('/en'); res.redirect('/en-eur');
}); });
app.get('/en', function(req, res) { // EUR routes
app.get('/en-eur', function(req, res) {
calculate.get10yr().then(pydata => { calculate.get10yr().then(pydata => {
// console.log("get10yr: ", pydata)
const yeardata = { 'yeardata': pydata } const yeardata = { 'yeardata': pydata }
let endata = Object.assign(enjson, yeardata) let endata = Object.assign(enjson, yeardata)
res.render('sats', endata) res.render('sats', endata)
}) })
}); });
app.get('/zh-cn', function(req, res) { app.get('/de', function(req, res) {
calculate.get10yr().then(pydata => { calculate.get10yr().then(pydata => {
const yeardata = { 'yeardata': pydata } const yeardata = { 'yeardata': pydata }
let zhcndata = Object.assign(zhcnjson, yeardata) let dedata = Object.assign(dejson, yeardata)
res.render('sats', zhcndata) res.render('sats', dedata)
}) })
}); });
app.get('/zh-hk', function(req, res) { app.get('/fr', function(req, res) {
calculate.get10yr().then(pydata => { calculate.get10yr().then(pydata => {
const yeardata = { 'yeardata': pydata } const yeardata = { 'yeardata': pydata }
let zhhkdata = Object.assign(zhhkjson, yeardata) let frdata = Object.assign(frjson, yeardata)
res.render('sats', zhhkdata) res.render('sats', frdata)
})
});
app.get('/es', function(req, res) {
calculate.get10yr().then(pydata => {
const yeardata = { 'yeardata': pydata }
let esdata = Object.assign(esjson, yeardata)
res.render('sats', esdata)
})
});
app.get('/it', function(req, res) {
calculate.get10yr().then(pydata => {
const yeardata = { 'yeardata': pydata }
let itdata = Object.assign(itjson, yeardata)
res.render('sats', itdata)
})
});
app.get('/nl', function(req, res) {
calculate.get10yr().then(pydata => {
const yeardata = { 'yeardata': pydata }
let nldata = Object.assign(nljson, yeardata)
res.render('sats', nldata)
})
});
app.get('/pt', function(req, res) {
calculate.get10yr().then(pydata => {
const yeardata = { 'yeardata': pydata }
let ptdata = Object.assign(ptjson, yeardata)
res.render('sats', ptdata)
})
});
app.get('/pl', function(req, res) {
calculate.get10yr().then(pydata => {
const yeardata = { 'yeardata': pydata }
let pldata = Object.assign(pljson, yeardata)
res.render('sats', pldata)
}) })
}); });

35
locales/de.json Normal file
View File

@@ -0,0 +1,35 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 Euro ist derzeit wert ",
"subtitle": "EURSAT Historische Performance",
"date": "Datum",
"price": "Preis",
"percentchange": "Prozentuale Änderung",
"footnote": "Datenquelle von usdsat.com, angepasst für EUR",
"data_file": "historical",
"rate_field": "sateur_rate",
"exchange_rate": "0.92",
"lang1_link": "/en-eur/",
"lang1": "English",
"lang2_link": "/fr/",
"lang2": "Français",
"lang3_link": "/es/",
"lang3": "Español",
"lang4_link": "/it/",
"lang4": "Italiano",
"lang5_link": "/nl/",
"lang5": "Nederlands",
"lang6_link": "/pt/",
"lang6": "Português",
"lang7_link": "/pl/",
"lang7": "Polski"
}

35
locales/en-eur.json Normal file
View File

@@ -0,0 +1,35 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 Euro is currently worth ",
"subtitle": "EURSAT Historical Performance",
"date": "Date",
"price": "Price",
"percentchange": "Percent Change",
"footnote": "data source from usdsat.com, adapted for EUR",
"data_file": "historical",
"rate_field": "sateur_rate",
"exchange_rate": "0.92",
"lang1_link": "/de/",
"lang1": "Deutsch",
"lang2_link": "/fr/",
"lang2": "Français",
"lang3_link": "/es/",
"lang3": "Español",
"lang4_link": "/it/",
"lang4": "Italiano",
"lang5_link": "/nl/",
"lang5": "Nederlands",
"lang6_link": "/pt/",
"lang6": "Português",
"lang7_link": "/pl/",
"lang7": "Polski"
}

View File

@@ -1,22 +0,0 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 HK dollar is currently worth ",
"subtitle": "HKDSAT Historical Performance",
"date": "Date",
"price": "Price",
"percentchange": "Percent Change",
"footnote": "data source from usdsat.com, adapted for HKD",
"lang1_link": "/zh-cn/",
"lang1": "中文(中国)",
"lang2_link": "/zh-hk/",
"lang2": "中文(香港)"
}

35
locales/es.json Normal file
View File

@@ -0,0 +1,35 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 Euro vale actualmente ",
"subtitle": "Rendimiento Histórico EURSAT",
"date": "Fecha",
"price": "Precio",
"percentchange": "Cambio Porcentual",
"footnote": "fuente de datos de usdsat.com, adaptado para EUR",
"data_file": "historical",
"rate_field": "sateur_rate",
"exchange_rate": "0.92",
"lang1_link": "/en-eur/",
"lang1": "English",
"lang2_link": "/de/",
"lang2": "Deutsch",
"lang3_link": "/fr/",
"lang3": "Français",
"lang4_link": "/it/",
"lang4": "Italiano",
"lang5_link": "/nl/",
"lang5": "Nederlands",
"lang6_link": "/pt/",
"lang6": "Português",
"lang7_link": "/pl/",
"lang7": "Polski"
}

35
locales/fr.json Normal file
View File

@@ -0,0 +1,35 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 Euro vaut actuellement ",
"subtitle": "Performance Historique EURSAT",
"date": "Date",
"price": "Prix",
"percentchange": "Variation en Pourcentage",
"footnote": "source de données de usdsat.com, adaptée pour EUR",
"data_file": "historical",
"rate_field": "sateur_rate",
"exchange_rate": "0.92",
"lang1_link": "/en-eur/",
"lang1": "English",
"lang2_link": "/de/",
"lang2": "Deutsch",
"lang3_link": "/es/",
"lang3": "Español",
"lang4_link": "/it/",
"lang4": "Italiano",
"lang5_link": "/nl/",
"lang5": "Nederlands",
"lang6_link": "/pt/",
"lang6": "Português",
"lang7_link": "/pl/",
"lang7": "Polski"
}

35
locales/it.json Normal file
View File

@@ -0,0 +1,35 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 Euro vale attualmente ",
"subtitle": "Performance Storica EURSAT",
"date": "Data",
"price": "Prezzo",
"percentchange": "Variazione Percentuale",
"footnote": "fonte dati da usdsat.com, adattato per EUR",
"data_file": "historical",
"rate_field": "sateur_rate",
"exchange_rate": "0.92",
"lang1_link": "/en-eur/",
"lang1": "English",
"lang2_link": "/de/",
"lang2": "Deutsch",
"lang3_link": "/fr/",
"lang3": "Français",
"lang4_link": "/es/",
"lang4": "Español",
"lang5_link": "/nl/",
"lang5": "Nederlands",
"lang6_link": "/pt/",
"lang6": "Português",
"lang7_link": "/pl/",
"lang7": "Polski"
}

35
locales/nl.json Normal file
View File

@@ -0,0 +1,35 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 Euro is momenteel waard ",
"subtitle": "EURSAT Historische Prestaties",
"date": "Datum",
"price": "Prijs",
"percentchange": "Procentuele Verandering",
"footnote": "gegevensbron van usdsat.com, aangepast voor EUR",
"data_file": "historical",
"rate_field": "sateur_rate",
"exchange_rate": "0.92",
"lang1_link": "/en-eur/",
"lang1": "English",
"lang2_link": "/de/",
"lang2": "Deutsch",
"lang3_link": "/fr/",
"lang3": "Français",
"lang4_link": "/es/",
"lang4": "Español",
"lang5_link": "/it/",
"lang5": "Italiano",
"lang6_link": "/pt/",
"lang6": "Português",
"lang7_link": "/pl/",
"lang7": "Polski"
}

35
locales/pl.json Normal file
View File

@@ -0,0 +1,35 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 Euro jest obecnie warte ",
"subtitle": "Historyczna Wydajność EURSAT",
"date": "Data",
"price": "Cena",
"percentchange": "Zmiana Procentowa",
"footnote": "źródło danych z usdsat.com, dostosowane dla EUR",
"data_file": "historical",
"rate_field": "sateur_rate",
"exchange_rate": "0.92",
"lang1_link": "/en-eur/",
"lang1": "English",
"lang2_link": "/de/",
"lang2": "Deutsch",
"lang3_link": "/fr/",
"lang3": "Français",
"lang4_link": "/es/",
"lang4": "Español",
"lang5_link": "/it/",
"lang5": "Italiano",
"lang6_link": "/nl/",
"lang6": "Nederlands",
"lang7_link": "/pt/",
"lang7": "Português"
}

35
locales/pt.json Normal file
View File

@@ -0,0 +1,35 @@
{
"post": {
"author": "Janith Kasun",
"image": "https://picsum.photos/500/500",
"comments": [
"This is the first comment",
"This is the second comment",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec fermentum ligula. Sed vitae erat lectus."
]
},
"layout": "main",
"Title": "1 Euro vale atualmente ",
"subtitle": "Desempenho Histórico EURSAT",
"date": "Data",
"price": "Preço",
"percentchange": "Variação Percentual",
"footnote": "fonte de dados de usdsat.com, adaptado para EUR",
"data_file": "historical",
"rate_field": "sateur_rate",
"exchange_rate": "0.92",
"lang1_link": "/en-eur/",
"lang1": "English",
"lang2_link": "/de/",
"lang2": "Deutsch",
"lang3_link": "/fr/",
"lang3": "Français",
"lang4_link": "/es/",
"lang4": "Español",
"lang5_link": "/it/",
"lang5": "Italiano",
"lang6_link": "/nl/",
"lang6": "Nederlands",
"lang7_link": "/pl/",
"lang7": "Polski"
}

View File

@@ -1,12 +0,0 @@
{
"Title": "1 港币现值 ",
"subtitle": "HKDSAT 过往表现",
"date": "日期",
"price": "价格",
"percentchange": "百分比变化",
"footnote": "来自usdsat.com的数据源",
"lang1_link": "/",
"lang1": "EN",
"lang2_link": "/zh-hk/",
"lang2": "中文(香港)"
}

View File

@@ -1,12 +0,0 @@
{
"Title": "1 港幣現值 ",
"subtitle" : "HKDSAT 過往表現",
"date" : "日期",
"price" : "價格",
"percentchange" : "百分比變化",
"footnote" : "來自usdsat.com的數據源",
"lang1_link": "/zh-cn/",
"lang1": "中文(中国)",
"lang2_link": "/",
"lang2": "EN"
}

1
public/historical Normal file
View File

@@ -0,0 +1 @@
[]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -8,6 +8,6 @@ try {
core.setOutput('✅ Success'); core.setOutput('✅ Success');
} catch (error) { } catch (error) {
core.setFailed(`🛑 ${error.message}`); core.setFailed(`🛑 ${error.message}`);
} }

View File

@@ -58,8 +58,7 @@
</li> </li>
</ul> </ul>
<span class="navbar-item" style="color: #fff"> <span class="navbar-item" style="color: #fff">
<a class="px-2" href="{{ lang1_link }}" style="color: rgb(6, 168, 231)"> {{ lang1 }} </a> | <a class="px-2" href="{{ lang1_link }}" style="color: rgb(6, 168, 231)"> {{ lang1 }} </a>{{#if lang2}} | <a class="px-2" href="{{ lang2_link }}" style="color: rgb(6, 168, 231)"> {{ lang2 }}</a>{{/if}}{{#if lang3}} | <a class="px-2" href="{{ lang3_link }}" style="color: rgb(6, 168, 231)"> {{ lang3 }}</a>{{/if}}{{#if lang4}} | <a class="px-2" href="{{ lang4_link }}" style="color: rgb(6, 168, 231)"> {{ lang4 }}</a>{{/if}}{{#if lang5}} | <a class="px-2" href="{{ lang5_link }}" style="color: rgb(6, 168, 231)"> {{ lang5 }}</a>{{/if}}{{#if lang6}} | <a class="px-2" href="{{ lang6_link }}" style="color: rgb(6, 168, 231)"> {{ lang6 }}</a>{{/if}}{{#if lang7}} | <a class="px-2" href="{{ lang7_link }}" style="color: rgb(6, 168, 231)"> {{ lang7 }}</a>{{/if}}
<a class="px-2" href="{{ lang2_link }}" style="color: rgb(6, 168, 231)"> {{ lang2 }}</a>
</span> </span>
</div> </div>
</div> </div>
@@ -125,7 +124,7 @@
i.forEach(function(item) { i.forEach(function(item) {
if (Array.isArray(item)) { if (Array.isArray(item)) {
var btc_price = item[0]; var btc_price = item[0];
currentPrice = Math.round((1 / btc_price) * 100000000 / 7.75); // satoshis per HKD dollar currentPrice = Math.round((1 / btc_price) * 100000000 / {{ exchange_rate }}); // satoshis per currency unit
document.title = currentPrice.toLocaleString() + " sats"; document.title = currentPrice.toLocaleString() + " sats";
document.querySelector('#current').textContent = currentPrice.toLocaleString(); document.querySelector('#current').textContent = currentPrice.toLocaleString();
@@ -165,7 +164,7 @@
</p> </p>
</div> </div>
<script> <script>
d3.json('/hkd_historical', function(data) { d3.json('/{{ data_file }}', function(data) {
data = MG.convert.date(data, 'date'); data = MG.convert.date(data, 'date');
var windowWidth = $(window).width(); var windowWidth = $(window).width();
@@ -230,7 +229,7 @@
xax_count: 16, xax_count: 16,
yax_count: 12, yax_count: 12,
x_accessor: 'date', x_accessor: 'date',
y_accessor: 'sathkd_rate', y_accessor: '{{ rate_field }}',
y_scale_type: 'log', y_scale_type: 'log',
y_extended_ticks: true, y_extended_ticks: true,
yax_units: ' sats', yax_units: ' sats',