Skip to content

Commit

Permalink
Merge pull request #2 from RajatSablok/main
Browse files Browse the repository at this point in the history
Added Node app to summarize TOS
  • Loading branch information
DiptoChakrabarty committed Oct 9, 2020
2 parents eff404c + e601ed0 commit 47509c6
Show file tree
Hide file tree
Showing 6 changed files with 1,933 additions and 9 deletions.
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Summarizer for Privacy Policies and Terms & Conditions.
<img src="https://embed-fastly.wistia.com/deliveries/49bd387c40e2c5aada92abdf973bc46d.webp?image_crop_resized=960x540">

---
[![DOCS](https://img.shields.io/badge/Documentation-see%20docs-green?style=flat-square&logo=appveyor)](INSERT_LINK_FOR_DOCS_HERE)
[![UI ](https://img.shields.io/badge/User%20Interface-Link%20to%20UI-orange?style=flat-square&logo=appveyor)](INSERT_UI_LINK_HERE)
[![DOCS](https://img.shields.io/badge/Documentation-see%20docs-green?style=flat-square&logo=appveyor)](https://documenter.getpostman.com/view/12931122/TVRkZ7WS)
<!-- [![UI ](https://img.shields.io/badge/User%20Interface-Link%20to%20UI-orange?style=flat-square&logo=appveyor)](INSERT_UI_LINK_HERE) -->

## About Summarizer
It is very tedious to read a long privacy policy or terms & conditions of a website or company. PP Summarizer helps the user choose the type of document or text and summarizes it within seconds.
Expand All @@ -21,16 +21,22 @@ It is very tedious to read a long privacy policy or terms & conditions of a webs

## Instructions to run
```
$ git clone https://github.com/CodeChefVIT/<Project>
$ cd <Project>
$ pip3 install -r requirements.txt
$ python3 manage.py runserver
$ git clone https://github.com/CodeChefVIT/Summerizer
$ cd Summerizer
$ npm install
```
These variables should reside as key value pairs in a file called `.env`.

## Contributors
- <a href="https://github.com/<Contributor>">Contributor Name</a>
- <a href="https://github.com/<Contributor>">Contributor Name</a>
| Variable Name | Description | Get it from |
| :-----------: | :-----------------------------: | :-------------------------------------------------: |
| APIKEY | MeaningCloud Summerizer API KEY | https://rapidapi.com/MeaningCloud/api/summarization |

```
$ npm start
```

## Contributors
- <a href="https://github.com/RajatSablok">Rajat Sablok</a>

<h2>
What is Hacktoberfest 2020? 😎
Expand Down
41 changes: 41 additions & 0 deletions api/routes/summarize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const express = require("express");
const request = require("request");

require("dotenv").config();

const router = express.Router();

//Get summary of terms of service or privacy policy from a URL
router.post("/", async (req, res) => {
const { url, sentences } = req.body;

const options = {
method: "GET",
url:
"https://meaningcloud-summarization-v1.p.rapidapi.com/summarization-1.0",
qs: {
url,
sentences,
},
headers: {
"x-rapidapi-host": "meaningcloud-summarization-v1.p.rapidapi.com",
"x-rapidapi-key": process.env.APIKEY,
accept: "application/json",
useQueryString: true,
},
};

request(options, function (error, response, body) {
if (error) {
return res.status(500).json({
message: "Something went wrong",
error: error.toString(),
});
}

let summary = JSON.parse(body);
res.status(200).json({ summary: summary.summary });
});
});

module.exports = router;
56 changes: 56 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const express = require("express");
const bodyParser = require("body-parser");
const helmet = require("helmet");
const cors = require("cors");

require("dotenv").config();

const app = express();

//Use helmet to prevent common security vulnerabilities
app.use(helmet());

//Use body-parser to parse json body
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// Allow CORS
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization, auth-token"
);
if (req.method === "OPTIONS") {
res.header("Access-Control-Allow-Methods", "PUT, POST, PATCH, DELETE, GET");
return res.status(200).json({});
}
next();
});

app.use(cors());

app.use("/api/v1/summarize", require("./api/routes/summarize"));

//This function will give a 404 response if an undefined API endpoint is fired
app.use((req, res, next) => {
const error = new Error("Route not found");
error.status = 404;
next(error);
});

app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: {
message: error.message,
},
});
});

const PORT = process.env.PORT || 3000;

//Start the server
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});
Loading

0 comments on commit 47509c6

Please sign in to comment.