Skip to content

Commit

Permalink
Merge pull request #42 from MrClemRkz/master
Browse files Browse the repository at this point in the history
clem update
  • Loading branch information
MrClemRkz authored Jul 31, 2020
2 parents be41f89 + 09a6be3 commit 7fd9f83
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 116 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ config.json
.DS_Store
package-lock.json
static/exports
.env
.env
report.*
24 changes: 22 additions & 2 deletions handlers/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ module.exports = async function(req, res) {
}

if (!global.browser) {
const browser = await puppeteer.launch({ args: ['--no-sandbox'] })
await reGenerateBrowser();
}
const page = await global.browser.newPage();
const page = await getNewPageFromBrowser();
page.setDefaultNavigationTimeout(0);
if (req.body.url) {
await page.goto(req.body.url);
Expand All @@ -72,6 +72,26 @@ module.exports = async function(req, res) {
});
}

async function getNewPageFromBrowser() {
const newPage = await global.browser.newPage().catch( (e) => {
console.log("Browser instance seems to be dead.")
})

if (newPage) {
return newPage;
} else {
await reGenerateBrowser();
console.log("Created a new page instance.");
return await global.browser.newPage()
}

}

async function reGenerateBrowser() {
global.browser = await puppeteer.launch({ args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'] });
console.log('Browser instance regenerated.')
}

function revisedRandId() {
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10);
}
2 changes: 1 addition & 1 deletion puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer');
const config = require('./config');
const headlessState = true;

puppeteer.launch({ headless: headlessState, args: ['--no-sandbox', '--disable-dev-shm-usage'] }).then(function(browser) {
puppeteer.launch({ headless: headlessState, args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'] }).then(function(browser) {
global.browser = browser;
console.log('browser ready');
});
2 changes: 1 addition & 1 deletion purge_expired.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ function purgeExpired() {
}
}
});
}
}
216 changes: 105 additions & 111 deletions templates/incidents/complaints/full_summary_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,138 +4,132 @@ Use the following JSON as request body to populate report.

```JSON
{
"file": {
"template": "incidents/complaints/daily_summary_report.js",
"incidents": [
{
"refId": "EC/EDR/PE20/JAF/0002",
"channel": "Letter",
"created_date": "2020/06/15",
"reporter": "adasdasdad",
"location": "fsdfdfdsf - Jaffna",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/JAF/0003",
"channel": "Email",
"created_date": "2020/06/15",
"reporter": "sdfasdfd",
"location": "Jaffna",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/JAF/0003",
"channel": "Letter",
"created_date": "2020/06/15",
"reporter": "asdfsdf",
"location": "Jaffna",
"summery" : "shkdfksjdhf kjshdfk"
"margin.top": "15",
"margin.right": "1",
"margin.bottom": "0.5",
"margin.left": "1.5",
"format": "A3",
"landscape": true,
"file": {
"template": "incidents/complaints/full_summary_report.js",
"date": "2020/07/10",
"dateInfo": "2020/07/09 4:00pm - 2020/07/10 4:00pm",
"complaints": [
{
"complaintNo": "EC/EDR/PE20/KAN/0009",
"channelLtr": "x",
"channelTel": "",
"channelFax": "",
"channelMail": "",
"complaintDate": "2020/06/09",
"reporter": "",
"location": "Kandy",
"complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla.",
"violentAction": "A-4",
"violationOfElectionLaw": "",
"other": "",
"law": "",
"medium": "x",
"critical": "",
"reportedParty": "-",
"progress": "-"
},
{
"refId": "EC/EDR/PE20/HAM/0004",
"channel": "Letter",
"created_date": "2020/06/21",
"complaintNo": "EC/EDR/PE20/HAM/0004",
"channelLtr": "x",
"channelTel": "",
"channelFax": "",
"channelMail": "",
"complaintDate": "2020/06/21",
"reporter": "Cleement",
"location": "Hambantota",
"summery" : "shkdfksjdhf kjshdfk"
"complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla viverra, nibh quis ultrices malesuada, ligula ipsum vulputate diam, aliquam egestas.",
"violentAction": "",
"violationOfElectionLaw": "B-13",
"other": "",
"law": "",
"medium": "",
"critical": "x",
"reportedParty": "-",
"progress": "-"
},
{
"refId": "EC/EDR/PE20/GAM/0005",
"channel": "Email",
"created_date": "2020/06/22",
"complaintNo": "EC/EDR/PE20/GAM/0005",
"channelLtr": "",
"channelTel": "",
"channelFax": "",
"channelMail": "x",
"complaintDate": "2020/06/22",
"reporter": "adadadadadass",
"location": "Gampaha",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/KAN/0006",
"channel": "Email",
"created_date": "2020/06/25",
"reporter": "",
"location": "Kandy",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/GAM/0007",
"channel": "Letter",
"created_date": "2020/06/25",
"reporter": "",
"location": "Gampaha",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/GAM/0008",
"channel": "Fax",
"created_date": "2020/06/25",
"reporter": "",
"location": "Gampaha",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/KAN/0009",
"channel": "Letter",
"created_date": "2020/06/25",
"reporter": "",
"location": "Kandy",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/GAM/0010",
"channel": "Letter",
"created_date": "2020/06/26",
"reporter": "",
"location": "Gampaha",
"summery" : "shkdfksjdhf kjshdfk"
"complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla.",
"violentAction": "",
"violationOfElectionLaw": "B-13",
"other": "",
"law": "",
"medium": "x",
"critical": "",
"reportedParty": "-",
"progress": "-"
},
{
"refId": "EC/EDR/PE20/JAF/0011",
"channel": "Letter",
"created_date": "2020/06/26",
"complaintNo": "EC/EDR/PE20/JAF/0011",
"channelLtr": "x",
"channelTel": "",
"channelFax": "",
"channelMail": "",
"complaintDate": "2020/06/26",
"reporter": "",
"location": "Jaffna",
"summery" : "shkdfksjdhf kjshdfk"
"complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla viverra, nibh quis ultrices malesuada, ligula ipsum vulputate diam, aliquam egestas.",
"violentAction": "",
"violationOfElectionLaw": "",
"other": "Other",
"law": "",
"medium": "",
"critical": "x",
"reportedParty": "Education Department ",
"progress": " situation is handled."
},
{
"refId": "EC/EDR/PE20/HAM/0014",
"channel": "Letter",
"created_date": "2020/07/01",
"reporter": "sfsdfdfdf",
"location": "Hambantota",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/KEG/0012",
"channel": "Letter",
"created_date": "2020/07/01",
"reporter": "sdfafasdf",
"location": "Kegalle",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/JAF/0013",
"channel": "Letter",
"created_date": "2020/07/01",
"complaintNo": "EC/EDR/PE20/JAF/0013",
"channelLtr": "x",
"channelTel": "",
"channelFax": "",
"channelMail": "",
"complaintDate": "2020/07/01",
"reporter": "",
"location": "Jaffna",
"summery" : "shkdfksjdhf kjshdfk"
"complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla.",
"violentAction": "A-8",
"violationOfElectionLaw": "",
"other": "",
"law": "x",
"medium": "",
"critical": "",
"reportedParty": "-",
"progress": "-"
},
{
"refId": "EC/EDR/PE20/KIL/0015",
"channel": "Letter",
"created_date": "2020/07/01",
"complaintNo": "EC/EDR/PE20/KIL/0015",
"channelLtr": "x",
"channelTel": "",
"channelFax": "",
"channelMail": "",
"complaintDate": "2020/07/01",
"reporter": "asdfasdf",
"location": "Kilinochchi",
"summery" : "shkdfksjdhf kjshdfk"
},
{
"refId": "EC/EDR/PE20/GAM/0016",
"channel": "Letter",
"created_date": "2020/07/01",
"reporter": "",
"location": "Gampaha",
"summery" : "shkdfksjdhf kjshdfk"
"complainSummery": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam et fermentum dui. Ut orci quam, ornare sed lorem sed, hendrerit auctor dolor. Nulla viverra, nibh quis ultrices malesuada, ligula ipsum vulputate diam, aliquam egestas.",
"violentAction": "",
"violationOfElectionLaw": "B-23",
"other": "",
"law": "",
"medium": "x",
"critical": "",
"reportedParty": "Legal Department ",
"progress": " Proper way is to manage outcome."
}
]
}
}
}
```

0 comments on commit 7fd9f83

Please sign in to comment.