Skip to content

Instantly share code, notes, and snippets.

View harrietty's full-sized avatar

Harriet harrietty

View GitHub Profile
const CURR_DIR = process.cwd();
inquirer.prompt(QUESTIONS)
.then(answers => {
const projectChoice = answers['project-choice'];
const projectName = answers['project-name'];
const templatePath = `${__dirname}/templates/${projectChoice}`;
fs.mkdirSync(`${CURR_DIR}/${projectName}`);
function createDirectoryContents (templatePath, newProjectPath) {
const filesToCreate = fs.readdirSync(templatePath);
filesToCreate.forEach(file => {
const origFilePath = `${templatePath}/${file}`;
// get stats about the current file
const stats = fs.statSync(origFilePath);
if (stats.isFile()) {
if (stats.isFile()) {
const contents = fs.readFileSync(origFilePath, 'utf8');
// Rename
if (file === '.npmignore') file = '.gitignore';
const writePath = `${CURR_DIR}/${newProjectPath}/${file}`;
fs.writeFileSync(writePath, contents, 'utf8');
}
[
{job: 'Marketing Campaigns Officer', closing: 'Fri Jul 21 2017 00:00:00 GMT+0100', location: 'Leeds, UK'},
{job: 'Registered Veterinary Nurse', closing: 'Sat Jul 22 2017 00:00:00 GMT+0100', location: 'Manchester, UK'},
{job: 'Building Services Manager', closing: 'Fri Jul 21 2017 00:00:00 GMT+0100', location: 'London, UK'}
];
module.exports.getdonkeyjobs = (event, context, callback) => {
callback(null, 'Hello world');
};
service: donkeyjob
provider:
name: aws
runtime: nodejs6.10
functions:
getdonkeyjobs:
handler: handler.getdonkeyjobs
resources:
const request = require('axios');
const AWS = require('aws-sdk');
const dynamo = new AWS.DynamoDB.DocumentClient();
const { differenceWith, isEqual } = require('lodash');
const { extractListingsFromHTML } = require('./helpers');
module.exports.getdonkeyjobs = (event, context, callback) => {
let newJobs, allJobs;
request('https://www.thedonkeysanctuary.org.uk/vacancies')
const cheerio = require('cheerio');
const moment = require('moment');
function extractListingsFromHTML (html) {
const $ = cheerio.load(html);
const vacancyRows = $('.view-Vacancies tbody tr');
const vacancies = [];
vacancyRows.each((i, el) => {
function formatJobs (list) {
return list.reduce((acc, job) => {
return `${acc}${job.job} in ${job.location} closing on ${moment(job.closing).format('LL')}\n\n`;
}, 'We found:\n\n');
}
module.exports = {
extractListingsFromHTML,
formatJobs
};
.then(() => {
if (newJobs.length) {
var nexmo = new Nexmo({
apiKey: NEXMO_API_KEY,
apiSecret: NEXMO_API_SECRET
});
nexmo.message.sendSms('Donkey Jobs Finder', MY_PHONE_NUMBER, 'Hello, we found a new donkey job!');
}
callback(null, { jobs: newJobs });
})