Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed May 10, 2017
1 parent 72784fd commit 96e7d9d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/
dist/
dist/
*.zip
.DS_Store
1 change: 1 addition & 0 deletions aws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.pull = require('./dist/src/pull').handler;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "djei",
"version": "1.0.0",
"description": "",
"main": "dist/src/pull.js",
"scripts": {
"test": "tsc && mocha dist/test",
"lint": "tslint src/** test/**"
Expand Down
56 changes: 13 additions & 43 deletions src/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,38 @@ interface PullResult {
processes: Processes;
}

export const pull = async (errorHandler: ErrorHandler): Promise<PullResult> => {
export const pull = async (): Promise<PullResult> => {
const url = 'https://www.djei.ie/en/What-We-Do/Jobs-Workplace-and-Skills/Employment-Permits/Current-Application-Processing-Dates/';
const client = new AWS.DynamoDB.DocumentClient();
const today = getToday();
const response = await axios.get(url);
const body = $.load(response.data);
const rows = body('article table tbody tr').toArray();
const updated = extractWhenUpdated(body('article p').text());
const processes: Processes = { };

const rows = body('article table tbody tr').toArray();
for (const row of rows) {
const name = formatPermit($('td:nth-child(1)', row).text());
const date = $('td:nth-child(2)', row).text();
processes[name] = parseDate(date, today).getTime();
}

const updated = extractWhenUpdated(body('article p').text());
return {
ticks: today.getTime(),
updated: parseDate(updated, today).getTime(),
processes
};
};

/*
const pull = async (url: string, tableName: string, errorHandler: ErrorHandler): Promise<PullResult> => {
try {
const client = new AWS.DynamoDB.DocumentClient();
const today = getToday();
const response = await axios.get(url);
const body = $.load(response.data);
const rows = body('article table tbody tr').toArray();
const updated = extractWhenUpdated(body('article p').text());
const processes = [];
for (const row of rows) {
const name = $('td:nth-child(1)', row).text();
const date = $('td:nth-child(2)', row).text();
processes.push({
name,
date: parseDate(date, today)
});
}
client.put({
TableName: tableName,
Item: {
ticks: today.getTime(),
updated: parseDate(updated, today).getTime(),
processes
}
}, (err: Error) => {
if (err) {
errorHandler(err);
}
});
} catch (err) {
errorHandler(err);
}
};
*/

export const handler = async (event: any, context: any, callback: any) => {
const tableName = 'mydjei_raw';
pull(callback);
const result = await pull();
const client = new AWS.DynamoDB.DocumentClient();
client.put({
TableName: 'djei_raw',
Item: result
}, (err: Error, output: AWS.DynamoDB.DocumentClient.PutItemOutput) => {
if (err) {
callback(err);
}
});
};
2 changes: 1 addition & 1 deletion test/pull.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Pull', () => {

it(`should pull data from live page`, async function() {
this.timeout(30000);
const result = await pull(fail);
const result = await pull();
expect(result.ticks).to.be.greaterThan(0);
expect(result.updated).to.be.greaterThan(0);
expect(result.processes.reviews).to.be.greaterThan(0);
Expand Down

0 comments on commit 96e7d9d

Please sign in to comment.