summaryrefslogtreecommitdiff
path: root/src/check.js
diff options
context:
space:
mode:
authorFivePixels <37427166+FivePixels@users.noreply.github.com>2021-04-10 22:40:50 -0500
committerGitHub <noreply@github.com>2021-04-10 22:40:50 -0500
commit0007b7e4fb5b48334b35e1fd77c2bcf814089f7a (patch)
treeb3337895a40e0c7b047089fbdcbf32023732683b /src/check.js
parentd3d9f7e6b69a84ea4da04609642f309134f0a346 (diff)
parent74598733bcc7b39b8a9b6521195545c543e38850 (diff)
downloadStreamFinder-0007b7e4fb5b48334b35e1fd77c2bcf814089f7a.tar.xz
StreamFinder-0007b7e4fb5b48334b35e1fd77c2bcf814089f7a.zip
Merge pull request #3 from FivePixels/dylan
Complete implementation for check.js, complete scrape.js
Diffstat (limited to 'src/check.js')
-rw-r--r--src/check.js52
1 files changed, 46 insertions, 6 deletions
diff --git a/src/check.js b/src/check.js
index c7085ca..0b52ece 100644
--- a/src/check.js
+++ b/src/check.js
@@ -1,18 +1,58 @@
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.
const scraper = require('./scraper/scrape')
-exports.performCheck = async function performCheck(query, type) {
- // if (!exist in database) {
- await scraper.performSearch(query, type);
- // }
+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)
- performDatabaseSearch(query, type);
+ var array = await performDatabaseSearch(id, type); // returns values
+ await client.close();
+ return array;
}
-async function performDatabaseSearch(query, type) {
+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