Commit 12f017d0 authored by shreyansh's avatar shreyansh

removing old code

parent ecd52a90
var {google} = require("googleapis");
var serviceAccount = require('./serviceKey.json');
var scopes = [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/firebase.database"
];
var jwtClient = new google.auth.JWT(
serviceAccount.client_email,
null,
serviceAccount.private_key,
scopes
);
module.exports = function (callback) {
jwtClient.authorize(function(error, tokens) {
callback(error, tokens);
})
};
\ No newline at end of file
'use strict';
const request = require('request');
const express = require('express');
let accessToken;
require('./gAuth.js')(function (error,tokens){
if (error)
console.log("Error making request to generate access token:", error);
else if (tokens.access_token === null)
console.log("Provided service account does not have permission to generate access tokens");
else
accessToken = tokens.access_token;
}.bind(this));
const PORT = 8080;
const HOST = 'localhost';
const app = express();
app.use(express.json());
app.get('/', (req, res) => {
res.send('Hello world\n');
});
app.post('/evaluate', (req, res) => {
var essay = req.body.essay;
new Promise(function(resolve, reject) {
const { spawn } = require('child_process');
const predict = spawn('python3',['prediction.py',essay]);
predict.stdout.on('data', function(data) {
data = new Buffer.from(data, 'base64').toString("ascii")
resolve(data);
});
predict.stderr.on('data', (data) => {
data = new Buffer.from(data, 'base64').toString("ascii")
reject(data);
});
})
.then((marks)=>{
res.send(marks)
})
.catch((err)=>{
console.log(err)
})
});
app.post('/contribute', (req, res) => {
var body = req.body;
var score = body.score;
var essay = body.essay;
var prompt = body.prompt;
var options = {
uri: `https://softlab-ba722.firebaseio.com/${prompt}/.json`,
method: 'POST',
body: {
"essay": essay,
"score": score
},
headers: {
"Content-Type":"application/json",
"Authorization":`Bearer ${accessToken}`
},
json: true
};
request(options, function(err,response,body){
res.send("Success");
})
});
app.get('/:id', (req, res) => {
var prompt = req.params.id;
var options = {
uri: `https://softlab-ba722.firebaseio.com/${prompt}.json`,
method: 'GET',
headers: {
"Content-Type":"application/json",
"Authorization":`Bearer ${accessToken}`
},
json: true
};
request(options, function(err,response,body){
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(body, null, 3));
})
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`)
\ No newline at end of file
{
"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "First Last <first.last@example.com>",
"main": "server.js",
"scripts": {
"start": "node main.js"
},
"dependencies": {
"express": "^4.16.1",
"googleapis": "^44.0.0",
"plagiarism-checker": "^1.2.1",
"request": "^2.88.0"
}
}
var request = require('request');
var CopyleaksCloud = require('plagiarism-checker');
var _ = require('lodash');
var clCloud = new CopyleaksCloud();
var config = clCloud.getConfig();
var credentials = {
"Email": "sjain0615@gmail.com",
"ApiKey": "89893811-8da7-432b-8f40-7d4eb6456693"
}
let access_token;
var essay = 'yes i am on moonlight. yes i am on moonlight yes .i am on moonlight yes i am on moonlightyes i am on moonlight. yes i am on moonlight. yes i am on moonlight';
clCloud.login(credentials.Email,credentials.ApiKey,'education',function(resp,err){
if(!err){
access_token = _.get(resp,'access_token','');
console.log(resp);
var _customHeaders = {};
_customHeaders[config.SANDBOX_MODE_HEADER] = true; // Sandbox mode - Scan without consuming any credits and get back dummy results
_customHeaders[config.HTTP_CALLBACK] = 'http://requestb.in/callbacks/' // Callback url - For a fast testing of callbacks option we recommend to use http://requestb.in
clCloud.createByText(essay,_customHeaders,function(resp,err){
console.log(resp)
if(resp && resp.ProcessId){
let PID = resp.ProcessId
let Status = 'Processing'
clCloud.getProcessStatus(PID,function(resp,err){
console.log(resp.Status,resp)
if(resp.Status==='Finished'){
clCloud.getProcessResults(PID,function(resp,err){
console.log(resp);
setTimeout(function(){
})
},15);
}
else{
clCloud.getProcessResults(PID,function(resp,err){
console.log(resp.results);
setTimeout(function(){
},15);
})
}
})
}
});
}
})
// var pid = '4decf855-60d6-4b9e-985b-4bfcfdb6bd63'
// function setToken(){
// var headers = {
// "Content-type": "application/json"
// };
// var options = {
// url: "https://id.copyleaks.com/v1/account/login-api",
// method: "POST",
// headers: headers,
// body: dataString,
// json: true
// };
// return new Promise(function(resolve,reject){
// clCloud.login(options, function(error, response, body) {
// if (!error && response.statusCode == 200)
// resolve(body.access_token)
// else
// reject(error)
// })
// })
// }
// function scanFile(token, essay){
// var headers = {
// 'Authorization': `Bearer ${token}`,
// 'Content-type': "application/json"
// };
// var options = {
// url: "https://id.copyleaks.com/v2/education/4d7728fb-ed3e-4c77-8a2c-07783cfad046/result",
// method: "GET",
// headers: headers,
// body: essay
// };
// request(options,function(error, response, body) {
// if (!error && response.statusCode == 200) {
// console.log(body);
// }
// });
// }
// setToken()
// .then((token)=>{
// scanFile(token,essay)
// })
// .catch((err)=>console.log('err '+err))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment