diff --git a/README.md b/README.md index 4913ea5..f6bc306 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Montana Code School: Pet Project +# This is an important page for your demo day! Add your contributor names and +# a little about the project technologies being used - Harold + ## Run ~~~ $ npm install diff --git a/helpers/scrape.js b/helpers/scrape.js index 427913e..acf2ef4 100644 --- a/helpers/scrape.js +++ b/helpers/scrape.js @@ -1,10 +1,11 @@ +// seems to work using import. good to resolve any remaining issues. +// Please only include the needed helper code now - not sure what is still being used +// -Harold -let request = require('request'); -// import request from 'request'; -let cheerio = require('cheerio'); -// import cheerio from 'cheerio'; -let scraper = {}; +import request from 'request'; +import cheerio from 'cheerio'; +let scraper = {}; scraper.scrapePetango = function(url, callback) { //Make a GET request @@ -71,10 +72,4 @@ scraper.parseIndividualAnimalResponse = function(html) { return petObject; }; - - - - - - -module.exports = scraper; +export default scraper; diff --git a/helpers/scrape.test.js b/helpers/scrape.test.js index f9c01df..d9db65b 100644 --- a/helpers/scrape.test.js +++ b/helpers/scrape.test.js @@ -1,7 +1,10 @@ import {expect} from 'chai'; -let scrape = require('./scrape'); +import scrape from './scrape'; describe('Scrape', () => { + // Still not reading from a file. + // You can do some expects around the number of animals in the data etc, + // No need to do a full .to.eql comparison. - Harold //We need to figure out how to run callbacks and mock the data so that we can //run this test. xdescribe('scrapePetango', () => { @@ -9,6 +12,8 @@ describe('Scrape', () => { expect(scrape.scrapePetango("http://ws.petango.com/Webservices/adoptablesearch/wsAdoptableAnimals.aspx?species=Dog&sex=All&agegroup=All&colnum=1&authkey=1t4v495156y98t2wd78317102f933h83or1340ptjm31spd04d")).to.eql([]); }); }); + // rather than put this html string right in your code - would be better to + // save the html in a file and read it (using NodeJS file reading) - Harold let html = ` diff --git a/helpers/scrapeAndSyncRunner.js b/helpers/scrapeAndSyncRunner.js index ff39f00..388693e 100644 --- a/helpers/scrapeAndSyncRunner.js +++ b/helpers/scrapeAndSyncRunner.js @@ -1,3 +1,4 @@ +// since you are using babel-node on the server, you can use import - Harold let mongoose = require("mongoose"); let uriUtil = require('mongodb-uri'); mongoose.Promise = global.Promise; diff --git a/helpers/sync.js b/helpers/sync.js index 473ddc9..764f759 100644 --- a/helpers/sync.js +++ b/helpers/sync.js @@ -1,5 +1,7 @@ //You scrape petango and you get one pet object back. //You want to look that pet up in your database by animalId. + +// Let's get import working (and ES6 export at bottom)- Harold let Pet = require('../models/pet'); let sync = {}; diff --git a/helpers/syncRunner.js b/helpers/syncRunner.js index b690a2e..ef4a979 100644 --- a/helpers/syncRunner.js +++ b/helpers/syncRunner.js @@ -4,6 +4,7 @@ //Loki is not in the scrape and needs to be removed from the database. //Baltazaar is in both the scrape and the DB so he should stay put. +// since you are using babel-node on the server, you can use import - Harold let mongoose = require("mongoose"); let uriUtil = require('mongodb-uri'); mongoose.Promise = global.Promise; diff --git a/models/pet.js b/models/pet.js index c31e0a8..7e18d01 100644 --- a/models/pet.js +++ b/models/pet.js @@ -1,3 +1,4 @@ +// since you are using babel-node on the server, you can use import - Harold let mongoose = require("mongoose"); let PetSchema = new mongoose.Schema({ diff --git a/routes/petRoutes.js b/routes/petRoutes.js index 90b6e0e..0ebc368 100644 --- a/routes/petRoutes.js +++ b/routes/petRoutes.js @@ -1,5 +1,6 @@ import React from 'react'; import webpack from 'webpack'; +// Use import instead of require below - Harold const Pet = require ('../models/pet'); let express = require('express'); let router = express.Router(); diff --git a/routes/userRoutes.js b/routes/userRoutes.js index c6449d1..4359a1d 100644 --- a/routes/userRoutes.js +++ b/routes/userRoutes.js @@ -4,7 +4,7 @@ import hash from 'password-hash'; import User from '../models/user'; import jwt from 'jsonwebtoken'; import configAuth from '../tools/configAuth'; - +// Use import below - Harold let express = require('express'); let userRoutes = express.Router(); let app = express(); diff --git a/src/components/DisplayPets.js b/src/components/DisplayPets.js index b0630b0..a81a46f 100644 --- a/src/components/DisplayPets.js +++ b/src/components/DisplayPets.js @@ -12,6 +12,7 @@ export default class DisplayPets extends React.Component { super(); this.state = { petPics: [], + // Not clear why the window.location below? - Harold species: window.location.hash.split("species=")[1].split("&")[0] }; this.loadPetsFromDb = this.loadPetsFromDb.bind(this); diff --git a/tools/configAuth.js b/tools/configAuth.js index 9c6e60f..da50771 100644 --- a/tools/configAuth.js +++ b/tools/configAuth.js @@ -1,3 +1,4 @@ +// This isn't safe - let's move this to an environment variable export default { secret: 'ilovedogs' }; diff --git a/tools/srcServer.js b/tools/srcServer.js index c50e164..49eeb76 100644 --- a/tools/srcServer.js +++ b/tools/srcServer.js @@ -12,6 +12,8 @@ import User from '../models/user'; import Pet from'../models/pet'; import petRoutes from '../routes/petRoutes'; import userRoutes from '../routes/userRoutes'; +import scrapeRunner from '../helpers/scrape'; +import syncRunner from '../helpers/sync'; /* eslint-disable no-console */ const port = process.env.PORT || 3000; @@ -41,14 +43,13 @@ mongoose.connect(mongooseUri, options); const PROD = process.env.NODE_ENV === 'production'; //Timed scrape and sync -let scrapeRunner = require('../helpers/scrape'); -let syncRunner = require('../helpers/sync'); -// + +// Not too worried - but may look better to hide in an environment variable let url = "http://ws.petango.com/Webservices/adoptablesearch/" + "wsAdoptableAnimals.aspx?sex=All&agegroup=All&colnum=" + "1&authkey=1t4v495156y98t2wd78317102f933h83or1340ptjm31spd04d"; //Call it when you npm start -// scrapeAndSync(); +scrapeAndSync(); //Call again every hour setInterval(scrapeAndSync, 3600000);