first commit
This commit is contained in:
56
sacrap/fx.js
Normal file
56
sacrap/fx.js
Normal file
@ -0,0 +1,56 @@
|
||||
exports.db_put = {db_put};
|
||||
function db_put(callback,arg){
|
||||
pool.query("UPDATE `pills` SET `json`='",'"',arg,'"', function(err, result){
|
||||
if (err) console.log(err,null);
|
||||
else callback(null,result[0]);
|
||||
});
|
||||
}
|
||||
function jwrite(jdata){
|
||||
// console.log(jdata);
|
||||
let wdata = JSON.stringify(jdata);
|
||||
fs.writeFile('./mods/pills.json', wdata, 'utf8', err => {
|
||||
if (err) {
|
||||
console.log(`Error writing file: ${err}`)
|
||||
} else {
|
||||
console.log(`File is written successfully!`)
|
||||
}
|
||||
})
|
||||
}
|
||||
function jwrite_pill(name,pill,date,comment){
|
||||
comment = (comment==""||comment==null&&comment==" ")? "-":comment;
|
||||
fs.readFile('./mods/pills.json','utf8',(err,data)=>{
|
||||
let jdata = JSON.parse(data);
|
||||
jdata[name] = {
|
||||
"date":date,
|
||||
"pill":pill,
|
||||
"comment":comment
|
||||
};
|
||||
// console.log(jdata);
|
||||
let wdata = JSON.stringify(jdata);
|
||||
fs.writeFile('./mods/pills.json', wdata, 'utf8', err => {
|
||||
if (err) {
|
||||
console.log(`Error writing file: ${err}`)
|
||||
} else {
|
||||
console.log(`File is written successfully!`)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
function j_max(arg){
|
||||
let max = 0;
|
||||
for (const key in arg) {
|
||||
let num = parseInt(key.split("_")[parseInt(key.split("_").length-1)]);
|
||||
// console.log(key);
|
||||
max = (num>max)? num:max;
|
||||
}
|
||||
console.log(max);
|
||||
return max;
|
||||
}
|
||||
function dict_reverse(obj) {
|
||||
new_obj= {}
|
||||
rev_obj = Object.keys(obj).reverse();
|
||||
rev_obj.forEach(function(i) {
|
||||
new_obj[i] = obj[i];
|
||||
})
|
||||
return new_obj;
|
||||
}
|
15
sacrap/i2.ejs
Normal file
15
sacrap/i2.ejs
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
bye
|
||||
</body>
|
||||
|
||||
</html>
|
127
sacrap/inde2.js
Normal file
127
sacrap/inde2.js
Normal file
@ -0,0 +1,127 @@
|
||||
const mysql = require("mysql");
|
||||
const express = require('express');
|
||||
const {
|
||||
response,
|
||||
request
|
||||
} = require('express');
|
||||
const app = express();
|
||||
var vars = require('./vars.js');
|
||||
const { json } = require("body-parser");
|
||||
const { pathToFileURL } = require("url");
|
||||
app.set('view engine','ejs');
|
||||
app.use(express.urlencoded({extended: false}));
|
||||
app.use(express.static('public'));
|
||||
const {
|
||||
readFile
|
||||
} = require('fs').promises;
|
||||
const fs = require('fs');
|
||||
const pool = mysql.createPool({
|
||||
connectionLimit: 100,
|
||||
host: "172.18.0.2",
|
||||
user: "root",
|
||||
password: "root",
|
||||
database: "pills",
|
||||
debug: false,
|
||||
});
|
||||
|
||||
|
||||
// database
|
||||
function db_get(callback){
|
||||
pool.query('SELECT * FROM pills', function(err, result){
|
||||
if (err) console.log(err,null);
|
||||
else callback(null,result[0]);
|
||||
});
|
||||
};
|
||||
function db_put(callback,arg){
|
||||
pool.query("UPDATE `pills` SET `json`='",'"',arg,'"', function(err, result){
|
||||
if (err) console.log(err,null);
|
||||
else callback(null,result[0]);
|
||||
});
|
||||
};
|
||||
// get(function(err,data){
|
||||
// vars.d = data["id"];
|
||||
// console.log(vars.d);
|
||||
// })
|
||||
|
||||
// async function s() {
|
||||
// const promise = await new Promise((resolve, reject) => {pool.query(`SELECT * FROM pills`, (err, result) => {resolve(result[0])})});
|
||||
// return promise["json"];
|
||||
// }
|
||||
// // // s();
|
||||
// async function l(){
|
||||
// let json = JSON.parse(await s());
|
||||
// // console.log(json);
|
||||
// return json;
|
||||
// }
|
||||
// l();
|
||||
|
||||
|
||||
|
||||
app.get('/', async (req, res) => {
|
||||
res.render('index');
|
||||
});
|
||||
|
||||
|
||||
app.get('/user', (req,res) => {
|
||||
db_get(function(err,data){
|
||||
let jdata = JSON.parse(data["json"]);
|
||||
// window.localStorage.setItem("pill/jdata?/","jdata");
|
||||
let pills = [];
|
||||
let ids = [];
|
||||
for (const key in jdata) {
|
||||
if (jdata.hasOwnProperty.call(jdata, key)) {
|
||||
const element = jdata[key];
|
||||
if(element["pill"]!=""&&element["pill"]!=null&&element["pill"]!=" "&&element["pill"]!="undefined"){
|
||||
pills.push(element["pill"]);
|
||||
ids.push(key);
|
||||
// console.log(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
// console.log(JSON.stringify(jdata));
|
||||
res.render(`user`, { data:JSON.stringify(jdata)});
|
||||
})
|
||||
})
|
||||
|
||||
// function name(params) {
|
||||
// .then(response => response.json())
|
||||
// .then(responseJson => {
|
||||
// // set localStorage with your preferred name,..
|
||||
// // ..say 'my_token', and the value sent by server
|
||||
// window.localStorage.setItem('my_token', responseJson.my_token)
|
||||
// // you may also want to redirect after you have saved localStorage:
|
||||
// // window.location.assign("http://www.example.org")
|
||||
// // you may even want to return responseJson or something else or assign it to some variable
|
||||
// // return responseJson;
|
||||
// })
|
||||
// }
|
||||
function get_json() {
|
||||
fs.readFile('./pills.json', 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.log(`Error reading file from disk: ${err}`)
|
||||
} else {
|
||||
// parse JSON string to JSON object
|
||||
const pills = JSON.parse(data)
|
||||
for (const key in pills) {
|
||||
if (Object.hasOwnProperty.call(pills, key)) {
|
||||
const element = pills[key];
|
||||
console.log(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
get_json();
|
||||
// app.post('/scripts',(req,res) => {
|
||||
// console.log(req.body);
|
||||
// db_get(function(err,data){
|
||||
// let jdata = JSON.parse(data["json"]);
|
||||
// // jdata[]
|
||||
// })
|
||||
// })
|
||||
|
||||
|
||||
app.all('*', (req, res) => {
|
||||
res.status(404).send('<h1>404! Page not</h1>');
|
||||
});
|
||||
app.listen(process.env.PORT || 8080, () => console.log("started"));
|
15
sacrap/index.ejs
Normal file
15
sacrap/index.ejs
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
hi
|
||||
</body>
|
||||
|
||||
</html>
|
38
sacrap/index1.js
Executable file
38
sacrap/index1.js
Executable file
@ -0,0 +1,38 @@
|
||||
const {
|
||||
response,
|
||||
request
|
||||
} = require('express');
|
||||
|
||||
const express = require('express');
|
||||
var vars = require('./vars.js');
|
||||
|
||||
const mysql = require("mysql");
|
||||
|
||||
const pool = mysql.createPool({
|
||||
connectionLimit: 100,
|
||||
host: "localhost",
|
||||
server: "db",
|
||||
user: "root",
|
||||
password: "root",
|
||||
database: "clicker",
|
||||
debug: false,
|
||||
});
|
||||
|
||||
pool.query("SELECT * from table_name LIMIT 10", (err, rows) => {
|
||||
if (err) {
|
||||
console.log("error occurred during the connection.");
|
||||
}
|
||||
// console.log(rows[0]);
|
||||
});
|
||||
|
||||
|
||||
const {
|
||||
readFile
|
||||
} = require('fs').promises;
|
||||
|
||||
const app = express();
|
||||
app.get('/', async (request, response) => {
|
||||
response.send(await readFile(`html/${dt.page}`, 'utf8'));
|
||||
});
|
||||
|
||||
app.listen(process.env.PORT || 3000, () => console.log("started"));
|
1
sacrap/pills copy.json
Normal file
1
sacrap/pills copy.json
Normal file
File diff suppressed because one or more lines are too long
2
sacrap/vars.js
Normal file
2
sacrap/vars.js
Normal file
@ -0,0 +1,2 @@
|
||||
exports.page = "i2.html";
|
||||
exports.d = "as";
|
Reference in New Issue
Block a user