Skip to content

Commit

Permalink
message
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfzkn committed Jul 1, 2021
1 parent 8895d41 commit 5f114b5
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 189 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"lockfileVersion": 0,
"dependencies": {
"axios": "^0.21.1",
"express": "^4.17.1"
"express": "^4.17.1",
"python-shell": "^3.0.0"
},
"name": "jsapp",
"version": "1.0.0",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"test": "start",
"start": "nodemon index.js"
"start": "nodemon src/index.js"
},
"author": "",
"license": "ISC",
Expand Down
Binary file added public/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions public/stlye.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
a{
color:white;
}

#header{
font-size: 25px;
}

#loading{
display:none;
}
78 changes: 78 additions & 0 deletions public/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

const searchCar = document.querySelector("#search-car");

// const button = document.querySelector("#button");

document.querySelector('#getads').addEventListener('click',loadads);


function loadads(){

console.log("fonksiyon çalışıyor")
var loadImage = document.querySelector('#loading');
loadImage.style.display = 'block';

var url ='/v1/spawn/sahibinden'
const xhr = new XMLHttpRequest();

xhr.open('GET', url, true);

setTimeout(() =>
{
xhr.onload = function()
{
loadImage.style.display="none";
console.log(this.responseText);

if(this.status === 200)
{

let ads = JSON.parse(this.responseText)
console.log(ads)

let html="";

ads.forEach(ad => {
console.log(ad.price)
html+= `<tr>
<td id="price">${ad.price}</td>
<td id="year">${ad.year}</td>
<td id="km">${ad.km}</td>
<td id="color">${ad.color}</td>
</tr>`;
});

document.querySelector('#ads').innerHTML = html;

}
}
xhr.send();

}, 1500);
}

searchCar.addEventListener("keypress", (event)=>
{
let text = event.target.value;

if(text !== "")
{
console.log(text);
}

})


// button.addEventListener('click', (updateButton)=>
// {
// if (button.value === 'Start machine')
// {
// button.value = 'Stop machine';
// alert("The machine has started!");
// }
// else
// {
// button.value = 'Start machine';
// alert('The machine is stopped.');
// }
// })
20 changes: 20 additions & 0 deletions result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{"price": "194.900TL", "year": "2018", "km": "80.450", "color": "Beyaz"},
{"price": "159.500TL", "year": "2015", "km": "147.000", "color": "Beyaz"},
{"price": "77.000TL", "year": "2004", "km": "270.000", "color": "G\u00fcm\u00fc\u015f"},
{"price": "81.750TL", "year": "2008", "km": "233.000", "color": "Siyah"},
{"price": "123.850TL", "year": "2008", "km": "170.000", "color": "Gri"},
{"price": "152.950TL", "year": "2012", "km": "125.000", "color": "Beyaz"},
{"price": "86.500TL", "year": "2009", "km": "142.900", "color": "Mavi"},
{"price": "168.500TL", "year": "2015", "km": "99.000", "color": "Beyaz"},
{"price": "127.950TL", "year": "2012", "km": "178.000", "color": "Lacivert"},
{"price": "81.950TL", "year": "2007", "km": "260.919", "color": "Gri"},
{"price": "131.000TL", "year": "2012", "km": "184.000", "color": "Beyaz"},
{"price": "129.750TL", "year": "2013", "km": "124.000", "color": "Beyaz"},
{"price": "183.750TL", "year": "2017", "km": "63.500", "color": "Beyaz"},
{"price": "199.950TL", "year": "2018", "km": "97.000", "color": "Beyaz"},
{"price": "156.750TL", "year": "2016", "km": "70.910", "color": "Beyaz"},
{"price": "102.000TL", "year": "2004", "km": "193.500", "color": "Lacivert"},
{"price": "262.950TL", "year": "2021", "km": "0", "color": "Beyaz"},
{"price": "152.950TL", "year": "2012", "km": "151.000", "color": "F\u00fcme"}
]
111 changes: 58 additions & 53 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@

const express = require('express')
const app = express()
const port = 3000
const child = require("child_process");
const path = require("path")
const util = require("util")
const axios = require("axios")

const exec = util.promisify(child.exec);

app.get('/v1/spawn/sahibinden' ,async (req, res) =>
{
const { stdout, stderr } = await exec(`python ${path.join(__dirname,'./sahibinden.py')}`)

if(stderr) {
return res.send({error:stderr.toString()})
}

res.send({stdout:stdout})
})

app.get('/', async (req, res) =>
{
res.status(200).send({message:'tamam'})
})

app.get('/auth', async (req, res) =>
{
const sessionId = req.query.sessionId

if(!sessionId) {
return res.status(422).send({message:'sessionId gerekli.'})
}

const response = await axios.get('http://api.app-platform.rgmbeta.com/api/v1/auth/getSessionInfo',{
params:{
sessionId:sessionId,
appName:'ebrutezel/sahibinden-scrapper',
secretKey:'ca139f7a53fc441189639251ac3688d9'
}
})

if(!response.data.data) {
return res.status(403).send({message:'yetkilendirme başarısız'})
}

res.redirect('/')
})

app.listen(port, () =>
{
console.log(`http://localhost:${port}`)

const express = require("express");
const app = express()
const port = 3000
const child = require("child_process");
const path = require("path")
const util = require("util")
const axios = require("axios")

const exec = util.promisify(child.exec);
app.use("public",express.static('../public'))

app.get('/v1/spawn/sahibinden' ,async (req, res) =>
{
const { stdout, stderr } = await exec(`python ${path.join(__dirname,'/script/sahibinden.py')}`)

if(stderr) {
return res.send({error:stderr.toString()})
}

res.send({stdout:stdout})
})

app.get('/', async (req, res) =>
{
res.sendFile(path.join(__dirname+'/template/form.html'));
})

app.get('/auth', async (req, res) =>
{
const sessionId = req.query.sessionId

if(!sessionId)
{
return res.status(422).send({message:'sessionId gerekli.'})
}

const response = await axios.get('http://api.app-platform.rgmbeta.com/api/v1/auth/getSessionInfo',
{
params:
{
sessionId:sessionId,
appName:'ebrutezel/sahibinden-scrapper',
secretKey:'ca139f7a53fc441189639251ac3688d9'
}
})

if(!response.data.data)
{
return res.status(403).send({message:'yetkilendirme başarısız'})
}

res.redirect('/')
})

app.listen(port, () =>
{
console.log(`http://localhost:${port}`)
})
Loading

0 comments on commit 5f114b5

Please sign in to comment.