Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
squidgetx committed Dec 18, 2022
1 parent b9f8be8 commit 584119c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
18 changes: 16 additions & 2 deletions server/db/db.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
const pgPromise = require("pg-promise");
const config = require("../lib/config");
const { ConnectionString } = require('connection-string');

const pgp = pgPromise({});
const DB = pgp(config.dbConnectionString);
const cnObj = new ConnectionString(config.dbConnectionString)
const cn = {
host: cnObj.hostname,
port: cnObj.port,
database: cnObj.path?.[0],
user: cnObj.user,
password: cnObj.password,
ssl: {
rejectUnauthorized: false,
},
};

const pgp = pgPromise();
const DB = pgp(cn);

module.exports = DB;

8 changes: 3 additions & 5 deletions server/db/init
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ drop table tweets;
drop table authors;
drop table media;
drop table links;
drop table elites;

create table elites (
id bigint unique,
Expand Down Expand Up @@ -69,7 +70,7 @@ CREATE INDEX ideo_index
ON elites (ideo);

CREATE INDEX tweets_link_index
ON tweets (link);
ON tweets (link_preview_url);

CREATE INDEX tweets_media_index_1
ON tweets (media_id_1);
Expand All @@ -83,15 +84,12 @@ ON tweets (ds);
CREATE INDEX usernames
ON users (username);

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO testuser;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO twee_user;

-- initial data for elites table
COPY elites(id, username, ideo)
FROM './elites.csv'
DELIMITER ','
CSV HEADER;

-- some test data
insert into authors values (16129920, 'Rachel Maddow MSNBC', 'maddow', TRUE, 'https://pbs.twimg.com/profile_images/59437078/icon-200x200_normal.jpg', TRUE, -1);
insert into users values ('test', 'test-install-code', 2, 1);

7 changes: 3 additions & 4 deletions server/db/scraper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import pgPromise from "pg-promise";
const pgp = pgPromise({});

import { default as DB } from "./db.js";
import { default as config } from "../lib/config.js"

const BEARER_TOKEN = process.env.BEARER_TOKEN;
const BEARER_TOKEN = config.twitterBearerToken;

const WRITE_DB = true;

Expand Down Expand Up @@ -338,12 +339,10 @@ const unwrapped_link = await getLinkPreview(test_link, {
followRedirects: `follow`,
});

/*
Maddow
// Maddow
test_fetch("16129920").then((result) => {
console.log("fetched")
});
*/

// Fox news
test_fetch("1367531").then((result) => {
Expand Down
6 changes: 5 additions & 1 deletion server/makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
start:
npm start
npx pm2 start bin/www

list:
npx pm2 list


setup_node: install_nvm
npm install
Expand Down
15 changes: 15 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"dependencies": {
"aws-sdk": "^2.1275.0",
"connection-string": "^4.3.6",
"cookie-parser": "~1.4.4",
"cors": "^2.8.5",
"debug": "~2.6.9",
Expand Down

0 comments on commit 584119c

Please sign in to comment.