diff options
| author | Ab30657 <amar_ronaldo30657@yahoo.com> | 2021-04-11 09:29:00 +0545 |
|---|---|---|
| committer | Ab30657 <amar_ronaldo30657@yahoo.com> | 2021-04-11 09:29:00 +0545 |
| commit | 8bb9b435244d68297b900e5a14cf90d5b5088b0d (patch) | |
| tree | a6dee4abcdcbbedb3f0a24cb1441b87b857adea7 /src/check.js | |
| parent | 2927b2cbe0e623c0a8c11b92a8dd987e1a03e3e4 (diff) | |
| parent | 0007b7e4fb5b48334b35e1fd77c2bcf814089f7a (diff) | |
| download | StreamFinder-8bb9b435244d68297b900e5a14cf90d5b5088b0d.tar.xz StreamFinder-8bb9b435244d68297b900e5a14cf90d5b5088b0d.zip | |
Merge branch 'main' of https://github.com/FivePixels/StreamFinder into amar
Diffstat (limited to 'src/check.js')
| -rw-r--r-- | src/check.js | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/check.js b/src/check.js index 73c58dd..0b52ece 100644 --- a/src/check.js +++ b/src/check.js @@ -1,4 +1,58 @@ -const mongodb = require('mongodb'); +const MongoClient = require('mongodb').MongoClient; + // This is for passing the parameters of the search to check and see if it already exists in the database -// if it does exist, we're gonna call another function in another file.
\ No newline at end of file +// if it does exist, we're gonna call another function in another file. + +const scraper = require('./scraper/scrape') + +exports.performCheck = async function performCheck(id, query, type) { + const uri = "mongodb+srv://user0:8HL0NBINt6B8mIYF@cluster0.kfyrm.mongodb.net/StreamFinder?retryWrites=true&w=majority"; + const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true }); + + var result; + await client.connect(); + const database = client.db("db"); + const tv = database.collection("tv"); + const movie = database.collection('movie') + const search = { id: `${id}` }; + // check to see if the title is already in the database + switch (type) { + case 'tv': + result = await tv.findOne(search); + break; + case 'movie': + result = await movie.findOne(search); + break; + } + if (result == null) { + await scraper.performSearch(id, query, type) + } + // (if it needed to be scraped, it now is, and its stored. next, we perform the database search for the newly saved entry) + var array = await performDatabaseSearch(id, type); // returns values + await client.close(); + return array; +} + +async function performDatabaseSearch(id, type) { + // do database search + const uri = "mongodb+srv://user0:8HL0NBINt6B8mIYF@cluster0.kfyrm.mongodb.net/StreamFinder?retryWrites=true&w=majority"; + const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true }); + var result; + await client.connect(); + const database = client.db("db"); + const tv = database.collection("tv"); + const movie = database.collection('movie') + const search = { id: `${id}` }; + // check to see if the title is already in the database + switch (type) { + case 'tv': + result = await tv.findOne(search) + break; + case 'movie': + result = await movie.findOne(search) + break; + } + client.close() + return [result.service, result.price] +}
\ No newline at end of file |
