From 31a4777d7cddf747bc36a241d81c03752afa2643 Mon Sep 17 00:00:00 2001 From: "Glitch (cs4241-19a-a2-shortstack-4)" Date: Mon, 9 Sep 2019 13:50:18 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=9B=B3=F0=9F=8E=8A=20Updated=20with?= =?UTF-8?q?=20Glitch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +- public/css/style.css | 5 +- public/index.html | 74 +++++-- server.improved.js | 60 ++++- shrinkwrap.yaml | 513 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 633 insertions(+), 23 deletions(-) create mode 100644 shrinkwrap.yaml diff --git a/package.json b/package.json index 988f135f..859ad268 100755 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "start": "node server.improved.js" }, "dependencies": { - "mime": "^2.4.4" + "mime": "^2.4.4", + "request": "^2.88.0", + "cheerio": "^0.22.0" } } diff --git a/public/css/style.css b/public/css/style.css index d5f842ab..97d46a42 100755 --- a/public/css/style.css +++ b/public/css/style.css @@ -1 +1,4 @@ -/*Style your own assignment! This is fun! */ \ No newline at end of file +/*Style your own assignment! This is fun! */ +.recipe{ + +} \ No newline at end of file diff --git a/public/index.html b/public/index.html index c56d620e..40e6b106 100755 --- a/public/index.html +++ b/public/index.html @@ -1,41 +1,89 @@ - CS4241 Assignment 2 +
- + + + +
+
+ +
+
+ +
- + \ No newline at end of file diff --git a/server.improved.js b/server.improved.js index 26673fc0..c89e7206 100644 --- a/server.improved.js +++ b/server.improved.js @@ -1,5 +1,7 @@ const http = require( 'http' ), fs = require( 'fs' ), + request = require('request'), + cheerio = require('cheerio'), // IMPORTANT: you must run `npm install` in the directory for this assignment // to install the mime library used in the following line of code mime = require( 'mime' ), @@ -7,11 +9,47 @@ const http = require( 'http' ), port = 3000 const appdata = [ - { 'model': 'toyota', 'year': 1999, 'mpg': 23 }, - { 'model': 'honda', 'year': 2004, 'mpg': 30 }, - { 'model': 'ford', 'year': 1987, 'mpg': 14} + { 'yourname': 'Rafael', 'dish': "cookie", 'ingredient': "chocolate" }, + { 'yourname': 'Nasim', 'dish': "roll", 'ingredient': "strawberry" }, + { 'yourname': 'Shine', 'dish': "duck", 'ingredient': "orange"} ] +const recipe = function(data){ + const new_recipe = data; + const str = "" + request(str.concat('https://www.allrecipes.com/search/results/?wt=',new_recipe.dish,'&ingIncl=',new_recipe.ingredient,'&sort=re'), (error, response, html) => { + if (!error && response.statusCode == 200) { + const $ = cheerio.load(html); + + const link = $('.fixed-recipe-card__h3 a').first().attr('href'); + return recipeview(link); + } + }) +} + +const recipeview = function(link){ + const new_recipe = link; + const str = "" + request(link, (error, response, html) => { + if (!error && response.statusCode == 200) { + const $ = cheerio.load(html); + + const ingredients = $('.checkList__item').each((i, el) => { + const title = $(el).attr('title') + } + ); + const instructions = $('.recipe-directions__list--item').each((i, el) => { + const title = $(el).text() + }); + + return { + ingredients: ingredients, + instructions: instructions + } + } + }) +} + const server = http.createServer( function( request,response ) { if( request.method === 'GET' ) { handleGet( request, response ) @@ -32,21 +70,27 @@ const handleGet = function( request, response ) { const handlePost = function( request, response ) { let dataString = '' - request.on( 'data', function( data ) { dataString += data }) request.on( 'end', function() { - console.log( JSON.parse( dataString ) ) - + const data = JSON.parse( dataString ) + addLog(data); + const answer = recipe(data) // ... do something with the data here!!! - response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) - response.end() + response.writeHead( 200, "OK", {'Content-Type': 'application/json' }) + response.end(answer) + console.log(answer); + }) } +const addLog = function(data){ + appdata.push(data) +} + const sendFile = function( response, filename ) { const type = mime.getType( filename ) diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml new file mode 100644 index 00000000..d137e6a0 --- /dev/null +++ b/shrinkwrap.yaml @@ -0,0 +1,513 @@ +dependencies: + cheerio: 0.22.0 + mime: 2.4.4 + request: 2.88.0 +packages: + /ajv/6.10.2: + dependencies: + fast-deep-equal: 2.0.1 + fast-json-stable-stringify: 2.0.0 + json-schema-traverse: 0.4.1 + uri-js: 4.2.2 + dev: false + resolution: + integrity: sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw== + /asn1/0.2.4: + dependencies: + safer-buffer: 2.1.2 + dev: false + resolution: + integrity: sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg== + /assert-plus/1.0.0: + dev: false + engines: + node: '>=0.8' + resolution: + integrity: sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU= + /asynckit/0.4.0: + dev: false + resolution: + integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k= + /aws-sign2/0.7.0: + dev: false + resolution: + integrity: sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg= + /aws4/1.8.0: + dev: false + resolution: + integrity: sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== + /bcrypt-pbkdf/1.0.2: + dependencies: + tweetnacl: 0.14.5 + dev: false + resolution: + integrity: sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4= + /boolbase/1.0.0: + dev: false + resolution: + integrity: sha1-aN/1++YMUes3cl6p4+0xDcwed24= + /caseless/0.12.0: + dev: false + resolution: + integrity: sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= + /cheerio/0.22.0: + dependencies: + css-select: 1.2.0 + dom-serializer: 0.1.1 + entities: 1.1.2 + htmlparser2: 3.10.1 + lodash.assignin: 4.2.0 + lodash.bind: 4.2.1 + lodash.defaults: 4.2.0 + lodash.filter: 4.6.0 + lodash.flatten: 4.4.0 + lodash.foreach: 4.5.0 + lodash.map: 4.6.0 + lodash.merge: 4.6.2 + lodash.pick: 4.4.0 + lodash.reduce: 4.6.0 + lodash.reject: 4.6.0 + lodash.some: 4.6.0 + dev: false + engines: + node: '>= 0.6' + resolution: + integrity: sha1-qbqoYKP5tZWmuBsahocxIe06Jp4= + /combined-stream/1.0.8: + dependencies: + delayed-stream: 1.0.0 + dev: false + engines: + node: '>= 0.8' + resolution: + integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + /core-util-is/1.0.2: + dev: false + resolution: + integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= + /css-select/1.2.0: + dependencies: + boolbase: 1.0.0 + css-what: 2.1.3 + domutils: 1.5.1 + nth-check: 1.0.2 + dev: false + resolution: + integrity: sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg= + /css-what/2.1.3: + dev: false + resolution: + integrity: sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg== + /dashdash/1.14.1: + dependencies: + assert-plus: 1.0.0 + dev: false + engines: + node: '>=0.10' + resolution: + integrity: sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA= + /delayed-stream/1.0.0: + dev: false + engines: + node: '>=0.4.0' + resolution: + integrity: sha1-3zrhmayt+31ECqrgsp4icrJOxhk= + /dom-serializer/0.1.1: + dependencies: + domelementtype: 1.3.1 + entities: 1.1.2 + dev: false + resolution: + integrity: sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA== + /dom-serializer/0.2.1: + dependencies: + domelementtype: 2.0.1 + entities: 2.0.0 + dev: false + resolution: + integrity: sha512-sK3ujri04WyjwQXVoK4PU3y8ula1stq10GJZpqHIUgoGZdsGzAGu65BnU3d08aTVSvO7mGPZUc0wTEDL+qGE0Q== + /domelementtype/1.3.1: + dev: false + resolution: + integrity: sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w== + /domelementtype/2.0.1: + dev: false + resolution: + integrity: sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ== + /domhandler/2.4.2: + dependencies: + domelementtype: 1.3.1 + dev: false + resolution: + integrity: sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA== + /domutils/1.5.1: + dependencies: + dom-serializer: 0.2.1 + domelementtype: 1.3.1 + dev: false + resolution: + integrity: sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8= + /domutils/1.7.0: + dependencies: + dom-serializer: 0.2.1 + domelementtype: 1.3.1 + dev: false + resolution: + integrity: sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg== + /ecc-jsbn/0.1.2: + dependencies: + jsbn: 0.1.1 + safer-buffer: 2.1.2 + dev: false + resolution: + integrity: sha1-OoOpBOVDUyh4dMVkt1SThoSamMk= + /entities/1.1.2: + dev: false + resolution: + integrity: sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w== + /entities/2.0.0: + dev: false + resolution: + integrity: sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw== + /extend/3.0.2: + dev: false + resolution: + integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== + /extsprintf/1.3.0: + dev: false + engines: + '0': node >=0.6.0 + resolution: + integrity: sha1-lpGEQOMEGnpBT4xS48V06zw+HgU= + /extsprintf/1.4.0: + dev: false + engines: + '0': node >=0.6.0 + resolution: + integrity: sha1-4mifjzVvrWLMplo6kcXfX5VRaS8= + /fast-deep-equal/2.0.1: + dev: false + resolution: + integrity: sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk= + /fast-json-stable-stringify/2.0.0: + dev: false + resolution: + integrity: sha1-1RQsDK7msRifh9OnYREGT4bIu/I= + /forever-agent/0.6.1: + dev: false + resolution: + integrity: sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= + /form-data/2.3.3: + dependencies: + asynckit: 0.4.0 + combined-stream: 1.0.8 + mime-types: 2.1.24 + dev: false + engines: + node: '>= 0.12' + resolution: + integrity: sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ== + /getpass/0.1.7: + dependencies: + assert-plus: 1.0.0 + dev: false + resolution: + integrity: sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo= + /har-schema/2.0.0: + dev: false + engines: + node: '>=4' + resolution: + integrity: sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI= + /har-validator/5.1.3: + dependencies: + ajv: 6.10.2 + har-schema: 2.0.0 + dev: false + engines: + node: '>=6' + resolution: + integrity: sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g== + /htmlparser2/3.10.1: + dependencies: + domelementtype: 1.3.1 + domhandler: 2.4.2 + domutils: 1.7.0 + entities: 1.1.2 + inherits: 2.0.4 + readable-stream: 3.4.0 + dev: false + resolution: + integrity: sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ== + /http-signature/1.2.0: + dependencies: + assert-plus: 1.0.0 + jsprim: 1.4.1 + sshpk: 1.16.1 + dev: false + engines: + node: '>=0.8' + npm: '>=1.3.7' + resolution: + integrity: sha1-muzZJRFHcvPZW2WmCruPfBj7rOE= + /inherits/2.0.4: + dev: false + resolution: + integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + /is-typedarray/1.0.0: + dev: false + resolution: + integrity: sha1-5HnICFjfDBsR3dppQPlgEfzaSpo= + /isstream/0.1.2: + dev: false + resolution: + integrity: sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo= + /jsbn/0.1.1: + dev: false + resolution: + integrity: sha1-peZUwuWi3rXyAdls77yoDA7y9RM= + /json-schema-traverse/0.4.1: + dev: false + resolution: + integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== + /json-schema/0.2.3: + dev: false + resolution: + integrity: sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM= + /json-stringify-safe/5.0.1: + dev: false + resolution: + integrity: sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= + /jsprim/1.4.1: + dependencies: + assert-plus: 1.0.0 + extsprintf: 1.3.0 + json-schema: 0.2.3 + verror: 1.10.0 + dev: false + engines: + '0': node >=0.6.0 + resolution: + integrity: sha1-MT5mvB5cwG5Di8G3SZwuXFastqI= + /lodash.assignin/4.2.0: + dev: false + resolution: + integrity: sha1-uo31+4QesKPoBEIysOJjqNxqKKI= + /lodash.bind/4.2.1: + dev: false + resolution: + integrity: sha1-euMBfpOWIqwxt9fX3LGzTbFpDTU= + /lodash.defaults/4.2.0: + dev: false + resolution: + integrity: sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw= + /lodash.filter/4.6.0: + dev: false + resolution: + integrity: sha1-ZosdSYFgOuHMWm+nYBQ+SAtMSs4= + /lodash.flatten/4.4.0: + dev: false + resolution: + integrity: sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8= + /lodash.foreach/4.5.0: + dev: false + resolution: + integrity: sha1-Gmo16s5AEoDH8G3d7DUWWrJ+PlM= + /lodash.map/4.6.0: + dev: false + resolution: + integrity: sha1-dx7Hg540c9nEzeKLGTlMNWL09tM= + /lodash.merge/4.6.2: + dev: false + resolution: + integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== + /lodash.pick/4.4.0: + dev: false + resolution: + integrity: sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM= + /lodash.reduce/4.6.0: + dev: false + resolution: + integrity: sha1-8atrg5KZrUj3hKu/R2WW8DuRTTs= + /lodash.reject/4.6.0: + dev: false + resolution: + integrity: sha1-gNZJLcFHCGS79YNTO2UfQqn1JBU= + /lodash.some/4.6.0: + dev: false + resolution: + integrity: sha1-G7nzFO9ri63tE7VJFpsqlF62jk0= + /mime-db/1.40.0: + dev: false + engines: + node: '>= 0.6' + resolution: + integrity: sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA== + /mime-types/2.1.24: + dependencies: + mime-db: 1.40.0 + dev: false + engines: + node: '>= 0.6' + resolution: + integrity: sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ== + /mime/2.4.4: + dev: false + engines: + node: '>=4.0.0' + hasBin: true + resolution: + integrity: sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA== + /nth-check/1.0.2: + dependencies: + boolbase: 1.0.0 + dev: false + resolution: + integrity: sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg== + /oauth-sign/0.9.0: + dev: false + resolution: + integrity: sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ== + /performance-now/2.1.0: + dev: false + resolution: + integrity: sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= + /psl/1.3.1: + dev: false + resolution: + integrity: sha512-2KLd5fKOdAfShtY2d/8XDWVRnmp3zp40Qt6ge2zBPFARLXOGUf2fHD5eg+TV/5oxBtQKVhjUaKFsAaE4HnwfSA== + /punycode/1.4.1: + dev: false + resolution: + integrity: sha1-wNWmOycYgArY4esPpSachN1BhF4= + /punycode/2.1.1: + dev: false + engines: + node: '>=6' + resolution: + integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== + /qs/6.5.2: + dev: false + engines: + node: '>=0.6' + resolution: + integrity: sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== + /readable-stream/3.4.0: + dependencies: + inherits: 2.0.4 + string_decoder: 1.3.0 + util-deprecate: 1.0.2 + dev: false + engines: + node: '>= 6' + resolution: + integrity: sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ== + /request/2.88.0: + dependencies: + aws-sign2: 0.7.0 + aws4: 1.8.0 + caseless: 0.12.0 + combined-stream: 1.0.8 + extend: 3.0.2 + forever-agent: 0.6.1 + form-data: 2.3.3 + har-validator: 5.1.3 + http-signature: 1.2.0 + is-typedarray: 1.0.0 + isstream: 0.1.2 + json-stringify-safe: 5.0.1 + mime-types: 2.1.24 + oauth-sign: 0.9.0 + performance-now: 2.1.0 + qs: 6.5.2 + safe-buffer: 5.2.0 + tough-cookie: 2.4.3 + tunnel-agent: 0.6.0 + uuid: 3.3.3 + dev: false + engines: + node: '>= 4' + resolution: + integrity: sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg== + /safe-buffer/5.2.0: + dev: false + resolution: + integrity: sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg== + /safer-buffer/2.1.2: + dev: false + resolution: + integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + /sshpk/1.16.1: + dependencies: + asn1: 0.2.4 + assert-plus: 1.0.0 + bcrypt-pbkdf: 1.0.2 + dashdash: 1.14.1 + ecc-jsbn: 0.1.2 + getpass: 0.1.7 + jsbn: 0.1.1 + safer-buffer: 2.1.2 + tweetnacl: 0.14.5 + dev: false + engines: + node: '>=0.10.0' + hasBin: true + resolution: + integrity: sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg== + /string_decoder/1.3.0: + dependencies: + safe-buffer: 5.2.0 + dev: false + resolution: + integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== + /tough-cookie/2.4.3: + dependencies: + psl: 1.3.1 + punycode: 1.4.1 + dev: false + engines: + node: '>=0.8' + resolution: + integrity: sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ== + /tunnel-agent/0.6.0: + dependencies: + safe-buffer: 5.2.0 + dev: false + resolution: + integrity: sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0= + /tweetnacl/0.14.5: + dev: false + resolution: + integrity: sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= + /uri-js/4.2.2: + dependencies: + punycode: 2.1.1 + dev: false + resolution: + integrity: sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ== + /util-deprecate/1.0.2: + dev: false + resolution: + integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= + /uuid/3.3.3: + dev: false + hasBin: true + resolution: + integrity: sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ== + /verror/1.10.0: + dependencies: + assert-plus: 1.0.0 + core-util-is: 1.0.2 + extsprintf: 1.4.0 + dev: false + engines: + '0': node >=0.6.0 + resolution: + integrity: sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA= +registry: 'https://registry.npmjs.org/' +shrinkwrapMinorVersion: 9 +shrinkwrapVersion: 3 +specifiers: + cheerio: ^0.22.0 + mime: ^2.4.4 + request: ^2.88.0 From d7c2b4ee73c450d011b3c87e033daef5a8e04a96 Mon Sep 17 00:00:00 2001 From: "Glitch (cs4241-19a-a2-shortstack-4)" Date: Mon, 9 Sep 2019 13:55:13 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E2=98=95=EF=B8=8F=F0=9F=8D=8F=20Updated=20?= =?UTF-8?q?with=20Glitch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 94d10752b7704c0909cae77175c8ddaca3976ecf Mon Sep 17 00:00:00 2001 From: "Glitch (cs4241-19a-a2-shortstack-4)" Date: Mon, 9 Sep 2019 15:53:20 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=8E=B3=F0=9F=8C=8D=20Updated=20with?= =?UTF-8?q?=20Glitch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +- package.json | 3 +- public/index.html | 152 ++++++++++++++++++++++++++++++++++++++++----- server.improved.js | 5 ++ shrinkwrap.yaml | 11 ++++ 5 files changed, 159 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 304a16f1..846459ab 100755 --- a/README.md +++ b/README.md @@ -81,9 +81,9 @@ Here is a sample formula for summarizing your activities, talk about: http://a2-charlieroberts.glitch.me ## Technical Achievements -- **Tech Achievement 1**: Using a combination of... -- **Tech Achievement 2**: ... +- **Tech Achievement 1**: Used Webscraping to make a recipe lookup tool that takes in a dish and a ingredient, all data comes from allrecipes.com +- **Tech Achievement 2**: CSS styling ### Design/Evaluation Achievements -- **Design Achievement 1**: Shown in `style.css`, the code... +- **Design Achievement 1**: Went for something simple and easily understandable - **Design Achievement 2**: We tested the application with n=X users, finding that... diff --git a/package.json b/package.json index 859ad268..7450a08f 100755 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "dependencies": { "mime": "^2.4.4", "request": "^2.88.0", - "cheerio": "^0.22.0" + "cheerio": "^0.22.0", + "bootstrap": "^4.3.1" } } diff --git a/public/index.html b/public/index.html index 40e6b106..4dbf544b 100755 --- a/public/index.html +++ b/public/index.html @@ -1,24 +1,122 @@ - - CS4241 Assignment 2 - - - - -
+ +CSS Template + + + + + + +
+

Food app

+
+ +
+ + +
- +
+
+ +
+

Footer

+
+ + \ No newline at end of file diff --git a/server.improved.js b/server.improved.js index c89e7206..d6d6d268 100644 --- a/server.improved.js +++ b/server.improved.js @@ -63,11 +63,16 @@ const handleGet = function( request, response ) { if( request.url === '/' ) { sendFile( response, 'public/index.html' ) + } else if ( request.url === '/orders' ) { + response.writeHeader( 200, { 'Content-Type': 'application/json' }) + console.log(appdata) + response.end( JSON.stringify(appdata) ) }else{ sendFile( response, filename ) } } + const handlePost = function( request, response ) { let dataString = '' request.on( 'data', function( data ) { diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml index d137e6a0..35238eb9 100644 --- a/shrinkwrap.yaml +++ b/shrinkwrap.yaml @@ -1,4 +1,5 @@ dependencies: + bootstrap: 4.3.1 cheerio: 0.22.0 mime: 2.4.4 request: 2.88.0 @@ -46,6 +47,15 @@ packages: dev: false resolution: integrity: sha1-aN/1++YMUes3cl6p4+0xDcwed24= + /bootstrap/4.3.1: + dev: false + engines: + node: '>=6' + peerDependencies: + jquery: 1.9.1 - 3 + popper.js: ^1.14.7 + resolution: + integrity: sha512-rXqOmH1VilAt2DyPzluTi2blhk17bO7ef+zLLPlWvG494pDxcM234pJ8wTc/6R40UWizAIIMgxjvxZg5kmsbag== /caseless/0.12.0: dev: false resolution: @@ -508,6 +518,7 @@ registry: 'https://registry.npmjs.org/' shrinkwrapMinorVersion: 9 shrinkwrapVersion: 3 specifiers: + bootstrap: ^4.3.1 cheerio: ^0.22.0 mime: ^2.4.4 request: ^2.88.0 From 7bb992c3dd8024fd02dbb37ad7532c0e8a714307 Mon Sep 17 00:00:00 2001 From: "Glitch (a2-repimentel)" Date: Mon, 9 Sep 2019 18:43:08 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=91=BB=F0=9F=91=AF=20Updated=20with?= =?UTF-8?q?=20Glitch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .glitch-assets | 0 README.md | 77 +++++----------------------------------------- public/index.html | 76 ++++++++++++++++++++++++++++----------------- server.improved.js | 70 ++++++++++++++++++++++------------------- 4 files changed, 93 insertions(+), 130 deletions(-) create mode 100644 .glitch-assets diff --git a/.glitch-assets b/.glitch-assets new file mode 100644 index 00000000..e69de29b diff --git a/README.md b/README.md index 846459ab..daf5bbe7 100755 --- a/README.md +++ b/README.md @@ -8,77 +8,16 @@ This assignment aims to introduce you to the concepts and practice involved in c The baseline aims of this assignment involve creating an application that demonstrates the use of several specific pieces of HTML, CSS, JavaScript, and Node.js functionality. Another aim of this assignment is to establish creative boundaries in which you and your partner can explore designing, implementing, and evaluating usable, useful, novel, and technically efficient web applications. -Baseline Requirements ---- -Note that there is a very large range of application areas and possibilities that meet these baseline requirements. -Games, internet of things, organizational tools, commerce, media - all are possibilities with a two-tiered form-focused web application. +## Foodify (Recipe lookup tool) + Web scraper that gets meal recipes from allrecipes.com, displays a recipe and shows past searches from other users -Do not limit yourselves to any of the examples given below. -Examples like the upcoming `efficiency_ratio` idea for the `cars` dataset are meant to be illustrative and easy to understand. -They are not intended to be sensible or useful ideas. +- I used web scraping for this project (library called cheerio), the library was awful but I managed to make it work, I used descriptive tags (nav, article and such), and styled my css properly +- I had already done a web scraper for this website for a discord bot in C#, so thats where I got the idea +- I think it came out pretty well, even though it took a little to get use to the tools I was using +- I would love to add a little bit more to the scraper, to display an image of the recipe and show the calories -Your application is required to implement the following functionalities: - -- a `Server` which not only serves files, but also maintains a tabular dataset with 3 or more fields related to your application -- a `Results` functionality which shows the entire dataset residing in the server's memory -- a `Form/Entry` functionality which allows a user to add, modify, or delete data items residing in the server's memory -- a `Server Logic` which, upon receiving new or modified "incoming" data, includes and uses a function that adds at least one additional derived field to this incoming data before integrating it with the existing dataset - - the `Derived field` for a new row of data must be computed based on fields already existing in the row. For example, a `cars` dataset with `year`, `horsepower`, and `fuel_efficiency` may create a new field `efficiency_ratio` by dividing `fuel_efficiency` by `horsepower` - -Your application is required to demonstrate the use of the following concepts: - -HTML: -- One or more [HTML Forms](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms), with any combination of form tags appropriate for the user input portion of the application - - Clarification: the results page can be implemented in any way. `
`s, `table`s, and `list`s are common choices - -CSS: -- CSS styling of the primary visual elements in the application -- Various CSS Selector functionality must be demonstrated: - - Element selectors - - ID selectors - - Class selectors -- CSS positioning and sizing of the primary visual elements in the application: - - CSS to cause at least one element to be horizontally centered on the page - - CSS to cause at least one pair of elements to appear side-by-side - - CSS defined in a maintainable, readable form, in external stylesheets - -JavaScript: -- At minimum, a small amount of front-end JavaScript to get / fetch data from the server; a sample is provided in this repository. - -Node.js: -- An HTTP Server that delivers all necessary files and data for the application. A starting point is provided in this repository. - -Deliverables ---- - -Do the following to complete this assignment: - -1. Fork the starting project code. This repo contains some starter code that may be used or discarded as needed. -2. Implement your project with the above requirements. -3. Test your project to make sure that when someone goes to your main page, it displays correctly. -4. Deploy your project to Glitch, and fill in the appropriate fields in your package.json file. -5. Ensure that your project has the proper naming scheme `a2-yourname` so we can find it. -6. Modify the Readme to the specifications below. -7. Create and submit a Pull Request to the original repo. Label the pull request as follows: a2-gitusername-firstname-lastname - -Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions) ---- - -## Your Web Application Title -Include a very brief summary of your project here. -Images are encouraged, along with concise, high-level text. - -Here is a sample formula for summarizing your activities, talk about: -- the domain area the project pertains to -- the main challenges or problems the application addresses -- the key innovations that make it possible to address the problem -- the main results of the implementation, does it really address the problem? -- any additional implications of the resulting application, or possibly areas for future work that have been discovered as part of the design and implementation activities - -(Note that when I use the above formula, I aim to have only one sentence per thought in order to remain concise.) - -http://a2-charlieroberts.glitch.me +https://a2-repimentel.glitch.me/ ## Technical Achievements - **Tech Achievement 1**: Used Webscraping to make a recipe lookup tool that takes in a dish and a ingredient, all data comes from allrecipes.com @@ -86,4 +25,4 @@ http://a2-charlieroberts.glitch.me ### Design/Evaluation Achievements - **Design Achievement 1**: Went for something simple and easily understandable -- **Design Achievement 2**: We tested the application with n=X users, finding that... +- **Design Achievement 2**: used descriptive tags (nav, article and such) diff --git a/public/index.html b/public/index.html index 4dbf544b..2b9f29da 100755 --- a/public/index.html +++ b/public/index.html @@ -7,12 +7,6 @@ * { box-sizing: border-box; } - -tr { - display: table-row; - vertical-align: inherit; - border-color: inherit; -} body { font-family: Arial, Helvetica, sans-serif; @@ -47,7 +41,6 @@ padding: 20px; width: 70%; background-color: #f1f1f1; - height: 300px; /* only for demonstration, should be removed */ } /* Clear floats after the columns */ @@ -65,7 +58,7 @@ color: white; } -/* Responsive layout - makes the two columns/boxes stack on top of each other instead of next to each other, on small screens */ +/* makes the two columns/boxes stack on top of each other instead of next to each other, on small screens */ @media (max-width: 600px) { nav, article { width: 100%; @@ -73,11 +66,12 @@ } } +
-

Food app

+

Foodify

@@ -103,17 +97,38 @@

Food app

-
- -
-
- -
+ + + + + + + + +
+ + + + + + + + +
+ + + + + + + + +
Past Searches
-

Footer

+

Made by Rafael Pimentel

@@ -122,6 +137,8 @@

Food app

const submit = function( e ) { // prevent default form action from being carried out e.preventDefault() + document.getElementById('hidden').style.display = 'block'; + document.getElementById('hidden1').style.display = 'block'; const input = document.querySelector( '#yourname' ); const input2 = document.querySelector( '#dish' ); const input3 = document.querySelector( '#ingredient' ); @@ -136,13 +153,10 @@

Food app

body }) .then( function( response ) { - // do something with the reponse - window.location.reload(); - - displayData(response) - - debugger; - + response.json().then(data => { + console.log("Response received", data) + displayData(data) + }); }) return false } @@ -154,13 +168,17 @@

Food app

} const displayData = function(arrays){ - for (let i = 0; i < arrays.ingredient; i++) { - const ing = arrays.ingredient; + + document.querySelector("#ingredients").innerHTML = "" + document.querySelector("#instructions").innerHTML = "" + + for (let i = 0; i < arrays.ingredients.length; i++) { + const ing = arrays.ingredients[i]; displayIngredients(ing); } - for (let i = 0; i < arrays.instruction; i++) { - const ins = arrays.dish; + for (let i = 0; i < arrays.instructions.length; i++) { + const ins = arrays.instructions[i]; displayInstructions(ins); } } @@ -197,9 +215,9 @@

Food app

} const displayOrder = function(order) { - const template = '{name} {orbit} {launch}
' + const template = '{name}{orbit}{launch}
' const row = template.replace("{name}", order.yourname).replace("{orbit}", order.dish).replace("{launch}", order.ingredient) - const tbody = document.querySelector("#ingredients") + const tbody = document.querySelector("#search") tbody.innerHTML += row } diff --git a/server.improved.js b/server.improved.js index d6d6d268..4bf3205e 100644 --- a/server.improved.js +++ b/server.improved.js @@ -14,38 +14,43 @@ const appdata = [ { 'yourname': 'Shine', 'dish': "duck", 'ingredient': "orange"} ] -const recipe = function(data){ +const recipe = function (data, callback) { const new_recipe = data; const str = "" - request(str.concat('https://www.allrecipes.com/search/results/?wt=',new_recipe.dish,'&ingIncl=',new_recipe.ingredient,'&sort=re'), (error, response, html) => { - if (!error && response.statusCode == 200) { - const $ = cheerio.load(html); - - const link = $('.fixed-recipe-card__h3 a').first().attr('href'); - return recipeview(link); + let url = str.concat('https://www.allrecipes.com/search/results/?wt=', new_recipe.dish, '&ingIncl=', new_recipe.ingredient, '&sort=re') + console.log("Recipe site url:", url) + request(url, (error, response, html) => { + if (!error && response.statusCode == 200) { + const $ = cheerio.load(html); + + const link = $('.fixed-recipe-card__h3 a').first().attr('href'); + recipeview(link, data => { + callback(data) + }); } }) } -const recipeview = function(link){ +const recipeview = function (link, callback) { + console.log("Recipe url:", link) const new_recipe = link; const str = "" request(link, (error, response, html) => { - if (!error && response.statusCode == 200) { - const $ = cheerio.load(html); - - const ingredients = $('.checkList__item').each((i, el) => { - const title = $(el).attr('title') - } - ); - const instructions = $('.recipe-directions__list--item').each((i, el) => { - const title = $(el).text() - }); - - return { - ingredients: ingredients, - instructions: instructions - } + if (!error && response.statusCode == 200) { + const $ = cheerio.load(html); + + const ingredients = $('#polaris-app li > label[title]').map((i, el) => { + return $(el).attr('title') + }).get(); + + const instructions = $('ol.list-numbers:nth-child(2) > li .recipe-directions__list--item').map((i, el) => { + return $(el).text() + }).get(); + + callback({ + ingredients: ingredients, + instructions: instructions + }) } }) } @@ -79,16 +84,17 @@ const handlePost = function( request, response ) { dataString += data }) - request.on( 'end', function() { - const data = JSON.parse( dataString ) + request.on('end', function () { + const data = JSON.parse(dataString) + console.log("Client sent:", data) addLog(data); - const answer = recipe(data) - // ... do something with the data here!!! - - response.writeHead( 200, "OK", {'Content-Type': 'application/json' }) - response.end(answer) - console.log(answer); - + recipe(data, answer => { + console.log(answer); + response.writeHead(200, "OK", { + 'Content-Type': 'application/json' + }) + response.end(JSON.stringify(answer)) + }); }) }