forked from davidfekke/wallstreetbets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
importstocks.js
67 lines (53 loc) · 1.77 KB
/
importstocks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import path from 'path';
import { promises as fsPromises } from 'fs';
const __dirname = path.dirname(import.meta.url);
const nysecsv = path.join(__dirname, 'NYSE_screener.csv');
const nasdaqcsv = 'NASDAQ_screener.csv';
const amexcsv = 'AMEX_screener.csv';
const insert_query = 'INSERT INTO stock (symbol, name, exchange, is_etf) VALUES ($1, $2, $3, $4)';
import PG from 'pg';
const Pool = PG.Pool;
const pool = new Pool({
user: 'postgres',
host: 'localhost',
database: 'etfdb',
password: 'password',
port: 5432
});
try {
const nysedata = await fsPromises.readFile('NYSE_screener.csv', 'UTF-8');
const nyseArray = nysedata.split('\r\n');
nyseArray.shift();
for (let item of nyseArray) {
const row = item.split(',');
console.log(`NASDAQ Symbol: ${row[0]}, name: ${row[1]}`);
await pool.query(insert_query,[row[0], row[1],'NYSE', 'false']);
}
} catch (err) {
console.error(err);
}
try {
const nasdaqdata = await fsPromises.readFile('nasdaq_screener.csv', 'UTF-8');
const nasdaqArray = nasdaqdata.split('\r\n');
nasdaqArray.shift();
for (let item of nasdaqArray) {
const row = item.split(',');
console.log(`NASDAQ Symbol: ${row[0]}, name: ${row[1]}`);
await pool.query(insert_query,[row[0], row[1],'NASDAQ', 'false']);
}
} catch (err) {
console.error(err);
}
try {
const amexdata = await fsPromises.readFile('AMEX_screener.csv', 'UTF-8');
const amexArray = amexdata.split('\r\n');
amexArray.shift();
for (let item of amexArray) {
const row = item.split(',');
console.log(`AMEX Symbol: ${row[0]}, name: ${row[1]}`);
await pool.query(insert_query,[row[0], row[1],'AMEX', 'false']);
}
} catch (err) {
console.error(err);
}
await pool.end();