aboutsummaryrefslogtreecommitdiff
path: root/src/server/index.ts
diff options
context:
space:
mode:
authorkimdahey <claire_kim1@brown.edu>2019-08-09 11:05:42 -0400
committerkimdahey <claire_kim1@brown.edu>2019-08-09 11:05:42 -0400
commitc407983788a09a5f93921439390834a4811b8842 (patch)
treeb757999bda24e13269608a6c63f116e55a702ba7 /src/server/index.ts
parent46637dc8f902077d613b737f576b755545a92c17 (diff)
parent68f613b5e762649b743059e494e9307eb103ff0d (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into tree_claire
Diffstat (limited to 'src/server/index.ts')
-rw-r--r--src/server/index.ts29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/server/index.ts b/src/server/index.ts
index 10a84c823..29b44713c 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -1,6 +1,6 @@
require('dotenv').config();
import * as bodyParser from 'body-parser';
-import { exec } from 'child_process';
+import { exec, ExecOptions } from 'child_process';
import * as cookieParser from 'cookie-parser';
import * as express from 'express';
import * as session from 'express-session';
@@ -148,6 +148,33 @@ app.get("/pull", (req, res) =>
res.redirect("/");
}));
+app.get("/buxton", (req, res) => {
+ let cwd = '../scraping/buxton';
+
+ let onResolved = (stdout: string) => { console.log(stdout); res.redirect("/"); };
+ let onRejected = (err: any) => { console.error(err.message); res.send(err); };
+ let tryPython3 = () => command_line('python3 scraper.py', cwd).then(onResolved, onRejected);
+
+ command_line('python scraper.py', cwd).then(onResolved, tryPython3);
+});
+
+const command_line = (command: string, fromDirectory?: string) => {
+ return new Promise<string>((resolve, reject) => {
+ let options: ExecOptions = {};
+ if (fromDirectory) {
+ options.cwd = path.join(__dirname, fromDirectory);
+ }
+ exec(command, options, (err, stdout) => err ? reject(err) : resolve(stdout));
+ });
+};
+
+const read_text_file = (relativePath: string) => {
+ let target = path.join(__dirname, relativePath);
+ return new Promise<string>((resolve, reject) => {
+ fs.readFile(target, (err, data) => err ? reject(err) : resolve(data.toString()));
+ });
+};
+
app.get("/version", (req, res) => {
exec('"C:\\Program Files\\Git\\bin\\git.exe" rev-parse HEAD', (err, stdout, stderr) => {
if (err) {