mirror of
https://github.com/RustyRaptor/5Anime.git
synced 2026-12-03 15:45:16 -07:00
start developing logic to gather data
This commit is contained in:
1 parent
eb72a18914
commit
db8f479f98
7 files changed
+187
-129
No files matched your search
+2
-1
@@ -31,6 +31,7 @@
|
||||
"semi": [
|
||||
"error",
|
||||
"never"
|
||||
]
|
||||
],
|
||||
"no-console": 0
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -1,6 +1,8 @@
|
||||
var mongoose = require('mongoose');
|
||||
var mongoose = require('mongoose')
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.connect('mongodb://localhost:27017/test');
|
||||
mongoose.Promise = global.Promise
|
||||
mongoose.connect('mongodb://localhost:27017/test', {
|
||||
useMongoClient: true,
|
||||
})
|
||||
|
||||
module.exports = {mongoose};
|
||||
module.exports = { mongoose }
|
||||
@@ -1,86 +1,142 @@
|
||||
const fetch = require('isomorphic-fetch')
|
||||
const {
|
||||
MongoClient,
|
||||
ObjectID
|
||||
MongoClient,
|
||||
ObjectID
|
||||
} = require('mongodb')
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
const {Todo} = require('./models/todo');
|
||||
// const mongoose = require('./db/mongoose')
|
||||
// const bodyParser = require('body-parser')
|
||||
|
||||
// const {Anime} = require('./models/anime')
|
||||
|
||||
var obj = new ObjectID()
|
||||
console.log(obj)
|
||||
|
||||
var query = `
|
||||
query ($id: Int) {
|
||||
Media (id: $id, type: ANIME) {
|
||||
id
|
||||
idMal
|
||||
title {
|
||||
romaji
|
||||
english
|
||||
native
|
||||
}
|
||||
genres
|
||||
episodes
|
||||
description
|
||||
type
|
||||
format
|
||||
status
|
||||
season
|
||||
duration
|
||||
chapters
|
||||
volumes
|
||||
}
|
||||
Media (id: $id, type: ANIME) {
|
||||
id
|
||||
idMal
|
||||
title {
|
||||
romaji
|
||||
english
|
||||
native
|
||||
}
|
||||
genres
|
||||
episodes
|
||||
description
|
||||
type
|
||||
format
|
||||
status
|
||||
season
|
||||
duration
|
||||
chapters
|
||||
volumes
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var variables = {
|
||||
id: 15126
|
||||
id: 15125
|
||||
}
|
||||
|
||||
var url = 'https://graphql.anilist.co',
|
||||
options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: query,
|
||||
variables: variables
|
||||
})
|
||||
}
|
||||
options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: query,
|
||||
variables: variables
|
||||
})
|
||||
}
|
||||
const mongoose = require('mongoose')
|
||||
mongoose.connect('mongodb://localhost:27017/test', { useMongoClient: true })
|
||||
mongoose.Promise = global.Promise
|
||||
|
||||
var Anime = mongoose.model('Anime', {
|
||||
id: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
idMal: {
|
||||
type: Number,
|
||||
},
|
||||
title: {
|
||||
type: Array,
|
||||
required: true,
|
||||
minlength: 1,
|
||||
trim: true,
|
||||
},
|
||||
genres: {
|
||||
type: Array,
|
||||
},
|
||||
episodes: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
required: true,
|
||||
minlength: 1,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
},
|
||||
format: {
|
||||
type: String,
|
||||
},
|
||||
status: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
season: {
|
||||
type: String,
|
||||
},
|
||||
duration: {
|
||||
type: Number,
|
||||
},
|
||||
chapters: {
|
||||
type: Number,
|
||||
},
|
||||
volumes: {
|
||||
type: Number,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
fetch(url, options).then(handleResponse)
|
||||
.then(handleData)
|
||||
.catch(handleError)
|
||||
.then(handleData)
|
||||
.catch(handleError)
|
||||
|
||||
function handleResponse(response) {
|
||||
return response.json().then(function(json) {
|
||||
return response.ok ? json : Promise.reject(json)
|
||||
})
|
||||
return response.json().then(function(json) {
|
||||
return response.ok ? json : Promise.reject(json)
|
||||
})
|
||||
}
|
||||
|
||||
function handleData(data) {
|
||||
console.log(JSON.stringify(data))
|
||||
// MongoClient.connect('mongodb://localhost:27017/5Anime', (err, db) => {
|
||||
// if (err) {
|
||||
// return console.log('unable to connect to mongodb server')
|
||||
// }
|
||||
// console.log('connected to mongodb server')
|
||||
//
|
||||
// db.collection('test').insertOne(data).then((result) => {
|
||||
// console.log(result)
|
||||
// })
|
||||
/
|
||||
/ })
|
||||
|
||||
console.log(JSON.stringify(data.data.Media))
|
||||
var anime = new Anime({
|
||||
id: data.data.Media.id,
|
||||
title: data.data.Media.title,
|
||||
episodes: data.data.Media.episodes,
|
||||
description: data.data.Media.description,
|
||||
status: data.data.Media.status,
|
||||
})
|
||||
anime.save(function (e) {
|
||||
if (e) {
|
||||
console.log(e)
|
||||
} else {
|
||||
console.log('meow')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handleError(error) {
|
||||
alert('Error, check console')
|
||||
console.error(error)
|
||||
console.log('Oh no it failed')
|
||||
console.error(error)
|
||||
}
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
var mongoose = require('mongoose');
|
||||
var mongoose = require('mongoose')
|
||||
|
||||
var Anime = mongoose.model('Anime', {
|
||||
id: {
|
||||
@@ -7,12 +7,12 @@ var Anime = mongoose.model('Anime', {
|
||||
},
|
||||
idMal: {
|
||||
type: Number,
|
||||
}
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
required: true,
|
||||
minlength: 1,
|
||||
trim: true,
|
||||
type: Array,
|
||||
required: true,
|
||||
minlength: 1,
|
||||
trim: true,
|
||||
},
|
||||
genres: {
|
||||
type: Array,
|
||||
@@ -48,6 +48,6 @@ var Anime = mongoose.model('Anime', {
|
||||
volumes: {
|
||||
type: Number,
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
module.exports = {Todo};
|
||||
module.exports = {Anime}
|
||||
+3
-1
@@ -13,7 +13,9 @@
|
||||
"hbs": "^4.0.1",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"mongodb": "^2.2.33",
|
||||
"mongoose": "^4.13.0"
|
||||
"mongoose": "^4.13.0",
|
||||
"popup": "^0.0.3",
|
||||
"popups": "^1.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^4.10.0",
|
||||
|
||||
+39
-57
@@ -1,80 +1,62 @@
|
||||
const fetch = require('isomorphic-fetch')
|
||||
const {
|
||||
MongoClient,
|
||||
ObjectID
|
||||
} = require('mongodb')
|
||||
|
||||
var obj = new ObjectID()
|
||||
console.log(obj)
|
||||
|
||||
var query = `
|
||||
query ($id: Int) {
|
||||
Media (id: $id, type: ANIME) {
|
||||
id
|
||||
idMal
|
||||
title {
|
||||
romaji
|
||||
english
|
||||
native
|
||||
}
|
||||
genres
|
||||
episodes
|
||||
description
|
||||
type
|
||||
format
|
||||
status
|
||||
season
|
||||
duration
|
||||
chapters
|
||||
volumes
|
||||
}
|
||||
Media (id: $id, type: ANIME) {
|
||||
id
|
||||
idMal
|
||||
title {
|
||||
romaji
|
||||
english
|
||||
native
|
||||
}
|
||||
genres
|
||||
episodes
|
||||
description
|
||||
type
|
||||
format
|
||||
status
|
||||
season
|
||||
duration
|
||||
chapters
|
||||
volumes
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var variables = {
|
||||
id: 15126
|
||||
id: 15125
|
||||
}
|
||||
|
||||
var url = 'https://graphql.anilist.co',
|
||||
options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: query,
|
||||
variables: variables
|
||||
})
|
||||
}
|
||||
options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: query,
|
||||
variables: variables
|
||||
})
|
||||
}
|
||||
|
||||
fetch(url, options).then(handleResponse)
|
||||
.then(handleData)
|
||||
.catch(handleError)
|
||||
.then(handleData)
|
||||
.catch(handleError)
|
||||
|
||||
function handleResponse(response) {
|
||||
return response.json().then(function(json) {
|
||||
return response.ok ? json : Promise.reject(json)
|
||||
})
|
||||
return response.json().then(function(json) {
|
||||
return response.ok ? json : Promise.reject(json)
|
||||
})
|
||||
}
|
||||
|
||||
function handleData(data) {
|
||||
console.log(JSON.stringify(data))
|
||||
// MongoClient.connect('mongodb://localhost:27017/5Anime', (err, db) => {
|
||||
// if (err) {
|
||||
// return console.log('unable to connect to mongodb server')
|
||||
// }
|
||||
// console.log('connected to mongodb server')
|
||||
//
|
||||
// db.collection('test').insertOne(data).then((result) => {
|
||||
// console.log(result)
|
||||
// })
|
||||
/
|
||||
/ })
|
||||
console.log(JSON.stringify(data))
|
||||
|
||||
}
|
||||
|
||||
function handleError(error) {
|
||||
alert('Error, check console')
|
||||
console.error(error)
|
||||
console.log('Error, check console')
|
||||
console.error(error)
|
||||
}
|
||||
@@ -414,10 +414,14 @@ commander@2.11.0:
|
||||
version "2.11.0"
|
||||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
|
||||
|
||||
component-emitter@^1.2.0:
|
||||
component-emitter@*, component-emitter@^1.2.0:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
|
||||
|
||||
component-inherit@*:
|
||||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143"
|
||||
|
||||
concat-map@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
||||
@@ -2024,6 +2028,17 @@ pluralize@^7.0.0:
|
||||
version "7.0.0"
|
||||
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
|
||||
|
||||
popup@^0.0.3:
|
||||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/popup/-/popup-0.0.3.tgz#d72953e16bd5a514a0b3e1d0943bed25667eacac"
|
||||
dependencies:
|
||||
component-emitter "*"
|
||||
component-inherit "*"
|
||||
|
||||
popups@^1.1.3:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/popups/-/popups-1.1.3.tgz#6bcce94dffd95b619a013a05a5c0940911510da9"
|
||||
|
||||
prelude-ls@~1.1.2:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
|
||||
|
||||
Reference in new issue
Block a user