From fd9658220390d63db69643fb56a71b4587df1c32 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sat, 28 Sep 2024 11:06:59 +0200 Subject: [PATCH] update cron jobs and delete endpoints --- app/cron_retail_volume.py | 8 ++--- app/cron_share_statistics.py | 2 -- app/main.py | 2 +- fastify/all-watchlists/server.js | 27 ----------------- fastify/app.js | 2 -- fastify/update-watchlist/server.js | 47 ------------------------------ 6 files changed, 5 insertions(+), 83 deletions(-) delete mode 100755 fastify/all-watchlists/server.js delete mode 100755 fastify/update-watchlist/server.js diff --git a/app/cron_retail_volume.py b/app/cron_retail_volume.py index a83b262..99b7298 100644 --- a/app/cron_retail_volume.py +++ b/app/cron_retail_volume.py @@ -131,10 +131,10 @@ async def run(): print(e) - most_retail_volume = [item for item in most_retail_volume if item['retailStrength'] <= 100] - most_retail_volume = sorted(most_retail_volume, key=lambda x: x['traded'], reverse=True)[:100] # top 100 retail volume stocks - with open(f"json/retail-volume/data.json", 'w') as file: - ujson.dump(most_retail_volume, file) + most_retail_volume = [item for item in most_retail_volume if item['retailStrength'] <= 100] + most_retail_volume = sorted(most_retail_volume, key=lambda x: x['traded'], reverse=True)[:100] # top 100 retail volume stocks + with open(f"json/retail-volume/data.json", 'w') as file: + ujson.dump(most_retail_volume, file) con.close() etf_con.close() diff --git a/app/cron_share_statistics.py b/app/cron_share_statistics.py index 9f7d43f..bba450a 100644 --- a/app/cron_share_statistics.py +++ b/app/cron_share_statistics.py @@ -82,8 +82,6 @@ async def get_data(ticker, con): async def run(): con = sqlite3.connect('stocks.db') - etf_con = sqlite3.connect('etf.db') - cursor = con.cursor() cursor.execute("PRAGMA journal_mode = wal") cursor.execute("SELECT DISTINCT symbol FROM stocks") diff --git a/app/main.py b/app/main.py index d9ea191..1f0e61e 100755 --- a/app/main.py +++ b/app/main.py @@ -3936,4 +3936,4 @@ async def get_newsletter(): res = orjson.loads(file.read()) except: res = [] - return res + return res \ No newline at end of file diff --git a/fastify/all-watchlists/server.js b/fastify/all-watchlists/server.js deleted file mode 100755 index c80f439..0000000 --- a/fastify/all-watchlists/server.js +++ /dev/null @@ -1,27 +0,0 @@ -// Declare a route -module.exports = function (fastify, opts, done) { - - const pb = opts.pb; - - fastify.post('/all-watchlists', async (request, reply) => { - const data = request.body; - const userId = data?.userId; - - let output; - - try { - output = await pb.collection("watchlist").getFullList({ - filter: `user="${userId}"` - }) - } - catch(e) { - //console.log(e) - output = {}; - } - - reply.send({ items: output }) - - }); - - done(); -}; \ No newline at end of file diff --git a/fastify/app.js b/fastify/app.js index bd83c8f..515b842 100755 --- a/fastify/app.js +++ b/fastify/app.js @@ -68,7 +68,6 @@ fastify.register(require("./get-user-data/server"), { pb }); fastify.register(require("./get-all-comments/server"), { pb }); fastify.register(require("./get-post/server"), { pb }); fastify.register(require("./get-one-post/server"), { pb }); -fastify.register(require("./update-watchlist/server"), { pb, serialize }); fastify.register(require("./get-portfolio-data/server"), { pb }); fastify.register(require("./create-portfolio/server"), { pb, serialize }); fastify.register(require("./buy-stock/server"), { pb }); @@ -82,7 +81,6 @@ fastify.register(require("./feedback/server"), { pb }); fastify.register(require("./create-watchlist/server"), { pb }); fastify.register(require("./delete-watchlist/server"), { pb }); fastify.register(require("./edit-name-watchlist/server"), { pb }); -fastify.register(require("./all-watchlists/server"), { pb }); fastify.register(require("./get-notifications/server"), { pb }); fastify.register(require("./update-notifications/server"), { pb }); fastify.register(require("./create-strategy/server"), { pb }); diff --git a/fastify/update-watchlist/server.js b/fastify/update-watchlist/server.js deleted file mode 100755 index 18e1335..0000000 --- a/fastify/update-watchlist/server.js +++ /dev/null @@ -1,47 +0,0 @@ -// Declare a route -module.exports = function (fastify, opts, done) { - const pb = opts.pb; - const serialize = opts.serialize; - - fastify.post("/update-watchlist", async (request, reply) => { - const data = request.body; - - const userId = data?.userId; - const ticker = data?.ticker; - const watchListId = data?.watchListId; - let output; - - try { - const watchList = await pb.collection("watchlist").getOne(watchListId); - - if (watchList?.ticker?.includes(ticker)) { - // Remove ticker from the watchlist. - const newTickerList = watchList?.ticker.filter( - (item) => item !== ticker - ); - output = await pb - .collection("watchlist") - .update(watchListId, { ticker: newTickerList }); - } else { - // Add ticker to the watchlist. - const newTickerList = [...watchList?.ticker, ticker]; - output = await pb - .collection("watchlist") - .update(watchListId, { ticker: newTickerList }); - } - } catch (e) { - //console.log(e) - output = await pb.collection("watchlist").create( - serialize({ - user: userId, - ticker: JSON.stringify([ticker]), - title: "Favorites", - }) - ); - } - - reply.send({ items: output }); - }); - - done(); -};