mirror of
https://github.com/aljazceru/satshkd-vercel.git
synced 2025-12-18 13:44:22 +01:00
clean up
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* GET product list.
|
||||
*
|
||||
* @return product list | empty.
|
||||
*/
|
||||
router.get("/", async (req, res) => {
|
||||
try {
|
||||
res.json({
|
||||
status: 200,
|
||||
message: "Get data has successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).send("Server error");
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -1,120 +0,0 @@
|
||||
from datetime import date
|
||||
import json
|
||||
import yaml
|
||||
import logging
|
||||
import requests
|
||||
#import os
|
||||
|
||||
logging.basicConfig(filename='satshkd.log', level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
logging.getLogger('satslogger').setLevel(level=logging.WARNING)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def del_years(d, years):
|
||||
"""
|
||||
Return a date that's `years` years after the date (or datetime)
|
||||
object `d`. Return the same calendar date (month and day) in the
|
||||
destination year, if it exists, otherwise use the following day
|
||||
(thus changing February 29 to March 1).
|
||||
|
||||
"""
|
||||
try:
|
||||
return d.replace(year = d.year - years)
|
||||
except ValueError:
|
||||
return d + (date(d.year + years, 1, 1) - date(d.year, 1, 1))
|
||||
|
||||
|
||||
# generate 10 year historical prices based on today's date
|
||||
def get_10year(lang):
|
||||
# path = '/home/bitkarrot/satshkd/static/hkd_historical'
|
||||
path = './public/static/hkd_historical'
|
||||
filep = open(path)
|
||||
historical = json.load(filep)
|
||||
hist_entries = []
|
||||
|
||||
datelist = []
|
||||
years = list(range(1,11))
|
||||
for i in years:
|
||||
adate = str(del_years(date.today(), i))
|
||||
datelist.append(adate)
|
||||
|
||||
for entry in historical:
|
||||
if entry['date'] in datelist:
|
||||
hist_entries.append(entry)
|
||||
hist_entries.reverse()
|
||||
|
||||
final_list = []
|
||||
today_sats = get_bitfinex_rate()
|
||||
|
||||
i = 1
|
||||
text_array = []
|
||||
if lang == 'zh-cn' or lang == 'zh-hk':
|
||||
text_array.append('年前')
|
||||
text_array.append('年前')
|
||||
elif lang =='en':
|
||||
text_array.append("year ago")
|
||||
text_array.append("years ago")
|
||||
|
||||
|
||||
for entry in hist_entries:
|
||||
year = entry['date']
|
||||
rawsat = entry['sathkd_rate']
|
||||
sats = "{:,}".format(rawsat)
|
||||
percentage = -100 * (rawsat - today_sats)/rawsat
|
||||
strp = "{:.3f}".format(percentage) + "%"
|
||||
# print(f'year: {year} sats: {sats} percent: {strp}')
|
||||
if i == 1:
|
||||
aset = {'year' : f"{i} {text_array[0]}", 'sats': sats + " sats", 'percent': strp}
|
||||
else:
|
||||
aset = {'year' : f"{i} {text_array[1]}", 'sats': sats + " sats", 'percent': strp}
|
||||
final_list.append(aset)
|
||||
i = i + 1
|
||||
return final_list
|
||||
|
||||
|
||||
def get_bitfinex_rate():
|
||||
try:
|
||||
path = "./"
|
||||
rates_file = path + 'rates.yml'
|
||||
|
||||
with open(rates_file, 'rb') as f:
|
||||
doc = yaml.load(f, Loader=yaml.FullLoader)
|
||||
sort_file = yaml.dump(doc, sort_keys=True)
|
||||
f.close()
|
||||
|
||||
hkdrate = doc['hkdrate']
|
||||
|
||||
satDenominator = 100000000
|
||||
btcDataURL = "https://api-pub.bitfinex.com/v2/ticker/tBTCUSD"
|
||||
|
||||
'''
|
||||
cmd = "wget " + btcDataURL
|
||||
print("command: " + cmd)
|
||||
ret = os.system(cmd)
|
||||
print('returned value: ', ret)
|
||||
'''
|
||||
|
||||
btcRates = requests.get(btcDataURL).json()
|
||||
btcLastPrice = btcRates[6]
|
||||
|
||||
sathkd = round((1/btcLastPrice)*satDenominator*hkdrate)
|
||||
# print(f'bitfinex last price: {btcLastPrice}, current sat rate: {sathkd}')
|
||||
return sathkd
|
||||
|
||||
except Exception as e:
|
||||
print("Exception" + e )
|
||||
logger.info(e)
|
||||
|
||||
|
||||
|
||||
# initial test
|
||||
# rate = get_bitfinex_rate()
|
||||
# print(f'getting bitfinex rate - initial test: {rate}')
|
||||
|
||||
|
||||
lang = 'zh-cn'
|
||||
lang = 'zh-hk'
|
||||
lang = 'en'
|
||||
final = get_10year(lang)
|
||||
print(final)
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import json
|
||||
import requests
|
||||
import logging
|
||||
|
||||
logging.basicConfig(filename='rates.log', level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
logging.getLogger('rateslogger').setLevel(level=logging.WARNING)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
path = "./"
|
||||
|
||||
def convert():
|
||||
try:
|
||||
# grab file from original site
|
||||
r = requests.get("http://usdsat.com/historical")
|
||||
with open(path + "static/historical", "wb") as f:
|
||||
f.write(r.content)
|
||||
f.close()
|
||||
|
||||
# convert to hkd
|
||||
my_file = open(path + 'static/historical', 'rt')
|
||||
lines = my_file.read()
|
||||
my_file.close()
|
||||
jlist = json.loads(lines)
|
||||
|
||||
print(len(jlist))
|
||||
|
||||
|
||||
# we don't need exact rate for historical
|
||||
# just a ball park rate is sufficient for the amts
|
||||
for i in jlist:
|
||||
print(i)
|
||||
price = i['usdsat_rate']
|
||||
i['sathkd_rate'] = int(price/7.75)
|
||||
whole_price = i['btcusd_rate']
|
||||
i['btchkd_rate'] = whole_price*7.75
|
||||
|
||||
|
||||
|
||||
print(jlist[len(jlist)-1])
|
||||
logger.info(jlist[len(jlist)-1])
|
||||
|
||||
with open(path + 'static/hkd_historical', 'w') as output:
|
||||
output.write(json.dumps(jlist))
|
||||
output.close()
|
||||
|
||||
except Exception as e:
|
||||
print("Exception" + e)
|
||||
logger.info(e)
|
||||
logger.info("Something unexpected occurred!")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
convert()
|
||||
@@ -1 +0,0 @@
|
||||
hkdrate: 0.1287
|
||||
@@ -1,2 +0,0 @@
|
||||
PyYAML==5.4
|
||||
requests==2.25.1
|
||||
@@ -1,7 +1,6 @@
|
||||
const axios = require('axios')
|
||||
const fs = require('fs');
|
||||
|
||||
|
||||
module.exports = {
|
||||
bfx: async function() {
|
||||
const btcDataURL = "https://api-pub.bitfinex.com/v2/ticker/tBTCUSD"
|
||||
@@ -10,7 +9,7 @@ module.exports = {
|
||||
//console.log(data[6])
|
||||
|
||||
const satDenominator = 100000000
|
||||
const hkdrate = 0.1287
|
||||
const hkdrate = 0.1287 // approximate rate
|
||||
btcLastPrice = data[6]
|
||||
const sathkd = Math.round((1 / btcLastPrice) * satDenominator * hkdrate)
|
||||
//console.log("bitfinex last price: ", btcLastPrice, "current satHKD: ", sathkd)
|
||||
|
||||
40
index.js
40
index.js
@@ -1,6 +1,5 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
* source origin: https://github.com/expressjs/express/tree/master/examples/static-files
|
||||
*/
|
||||
|
||||
const express = require("express");
|
||||
@@ -16,22 +15,6 @@ const zhcnjson = require('./locales/zh-cn.json');
|
||||
const zhhkjson = require('./locales/zh-hk.json');
|
||||
const enjson = require('./locales/en.json');
|
||||
|
||||
|
||||
// old default for testing
|
||||
let pydataold = {
|
||||
'yeardata': [{ 'year': '1 year ago', 'sats': '1,199 ', 'percent': '-79.149' },
|
||||
{ 'year': '2 years ago', 'sats': '1,582 ', 'percent': '-84.197' },
|
||||
{ 'year': '3 years ago', 'sats': '1,958 ', 'percent': '-87.232' },
|
||||
{ 'year': '4 years ago', 'sats': '2,984 ', 'percent': '-91.622' },
|
||||
{ 'year': '5 years ago', 'sats': '21,122 ', 'percent': '-98.816' },
|
||||
{ 'year': '6 years ago', 'sats': '53,632 ', 'percent': '-99.534' },
|
||||
{ 'year': '7 years ago', 'sats': '40,367 ', 'percent': '-99.381' },
|
||||
{ 'year': '8 years ago', 'sats': '106,515 ', 'percent': '-99.765' },
|
||||
{ 'year': '9 years ago', 'sats': '1,016,962 ', 'percent': '-99.975' },
|
||||
{ 'year': '10 years ago', 'sats': '2,649,533 ', 'percent': '-99.991' }
|
||||
]
|
||||
}
|
||||
|
||||
app.set('view engine', 'hbs');
|
||||
app.set('views', __dirname + '/views')
|
||||
|
||||
@@ -41,36 +24,13 @@ app.engine('hbs', handlebars({
|
||||
extname: 'hbs',
|
||||
}));
|
||||
|
||||
//Serves static files (we need it to import a css file)
|
||||
app.use(express.static('public'))
|
||||
|
||||
// log requests
|
||||
app.use(logger('dev'));
|
||||
|
||||
// express on its own has no notion
|
||||
// of a "file". The express.static()
|
||||
// middleware checks for a file matching
|
||||
// the `req.path` within the directory
|
||||
// that you pass it. In this case "GET /js/app.js"
|
||||
// will look for "./public/js/app.js".
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
|
||||
// if you wanted to "prefix" you may use
|
||||
// the mounting feature of Connect, for example
|
||||
// "GET /static/js/app.js" instead of "GET /js/app.js".
|
||||
// The mount-path "/static" is simply removed before
|
||||
// passing control to the express.static() middleware,
|
||||
// thus it serves the file correctly by ignoring "/static"
|
||||
app.use('/static', express.static(path.join(__dirname, 'public')));
|
||||
|
||||
// if for some reason you want to serve files from
|
||||
// several directories, you can use express.static()
|
||||
// multiple times! Here we're passing "./public/css",
|
||||
// this will allow "GET /style.css" instead of "GET /css/style.css":
|
||||
app.use(express.static(path.join(__dirname, 'public', 'css')));
|
||||
//app.use(express.json({ extended: false }));
|
||||
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
</li>
|
||||
<!--
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-2 text-white" href="#">DCA or Lightning Laisee</a>
|
||||
<a class="nav-link px-2 text-white" href="#">Lightning Laisee</a>
|
||||
</li>
|
||||
-->
|
||||
<li class="nav-item">
|
||||
|
||||
Reference in New Issue
Block a user