Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
thoriqazzikraa committed Mar 19, 2024
1 parent 5224734 commit 069b9ef
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 133 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrape-websitee",
"version": "1.0.70",
"version": "1.0.71",
"description": "Website Scraping",
"main": "index.js",
"scripts": {
Expand Down
254 changes: 122 additions & 132 deletions src/random.js
Original file line number Diff line number Diff line change
@@ -1,154 +1,144 @@
const axios = require("axios");
const cheerio = require("cheerio");
const baseCerpen = "http://cerpenmu.com/100-cerpen-kiriman-terbaru";
const { pickRandom } = require("../function/pickRandom.js");
const { isUrl } = require("../function/isUrl.js");
const axios = require("axios")
const cheerio = require("cheerio")
const baseCerpen = "http://cerpenmu.com/100-cerpen-kiriman-terbaru"
const { pickRandom } = require("../function/pickRandom.js")
const { isUrl } = require("../function/isUrl.js")

async function hubbleImg() {
let result = {};
let result = {}
try {
const randomNumber = Math.floor(Math.random() * 21);
const { data } = await axios.get(
`https://esahubble.org/images/viewall/page/${randomNumber}/`
);
let $ = cheerio.load(data);
const scriptRes = $("script").html().split("=")[1];
const repl = scriptRes.replace(/'/g, '"');
const jsonResult = JSON.parse(JSON.stringify(repl, null, 2));
const pushUrl = isUrl(jsonResult);
const randomResult = Math.floor(Math.random() * pushUrl.length);
const spl = pushUrl[randomResult].split("/")[6];
const randomNumber = Math.floor(Math.random() * 21)
const { data } = await axios.get(`https://esahubble.org/images/viewall/page/${randomNumber}/`)
let $ = cheerio.load(data)
const scriptRes = $("script").html().split("=")[1]
const repl = scriptRes.replace(/'/g, '"')
const jsonResult = JSON.parse(JSON.stringify(repl, null, 2))
const pushUrl = isUrl(jsonResult)
const randomResult = Math.floor(Math.random() * pushUrl.length)
const spl = pushUrl[randomResult].split("/")[6]
const info = jsonResult
.split(`id: "${spl.replace(".jpg", "")}",`)[1]
.split("}")[0]
.trim();
const checkPtw = info.split("potw:")[1];
const evalPtw = eval(checkPtw);
const potw = evalPtw ? evalPtw : "Unknown";
const urlPublic = pushUrl[randomResult].replace(
"thumb300y",
"publicationjpg"
);
const urlLarge = pushUrl[randomResult].replace("thumb300y", "large");
let title = info.split(`title: "`)[1].split(`"`)[0].replace("'", "'");
const images = await fetch(urlPublic);
.trim()
const checkPtw = info.split("potw:")[1]
const evalPtw = eval(checkPtw)
const potw = evalPtw ? evalPtw : "Unknown"
const urlPublic = pushUrl[randomResult].replace("thumb300y", "publicationjpg")
const urlLarge = pushUrl[randomResult].replace("thumb300y", "large")
let title = info.split(`title: "`)[1].split(`"`)[0].replace("'", "'")
const images = await fetch(urlPublic)
if (images.status !== 200) {
var img = urlLarge;
var quality = "Large";
var img = urlLarge
var quality = "Large"
} else {
var img = urlPublic;
var quality = "Publication JPG";
var img = urlPublic
var quality = "Publication JPG"
}
result.title = title;
result.releaseDate = potw;
result.quality = quality;
result.url = img;
return result;
result.title = title
result.releaseDate = potw
result.quality = quality
result.url = img
return result
} catch (err) {
console.log(err);
return String(err);
console.log(err)
return String(err)
}
}

async function randomTiktok(username) {
let result = {};
let result = {}
if (!username.startsWith("@")) {
var user = "@" + username;
var user = "@" + username
} else {
var user = username;
var user = username
}
const { data } = await axios.get(
`https://tiktok-video-no-watermark2.p.rapidapi.com/user/posts?unique_id=${user}&count=1000`,
{
headers: {
Accept: "application/json",
"X-RapidAPI-Key": "533115be6amsh2515f73f171c6f1p160d9djsn833294e42f10",
"X-RapidAPI-Host": "tiktok-video-no-watermark2.p.rapidapi.com",
"User-Agent": "PostmanRuntime/7.32.2",
Referer: "https://tik.storyclone.com/",
},
const { data } = await axios.get(`https://tiktok-video-no-watermark2.p.rapidapi.com/user/posts?unique_id=${user}&count=1000`, {
headers: {
Accept: "application/json",
"X-RapidAPI-Key": "533115be6amsh2515f73f171c6f1p160d9djsn833294e42f10",
"X-RapidAPI-Host": "tiktok-video-no-watermark2.p.rapidapi.com",
"User-Agent": "PostmanRuntime/7.32.2",
Referer: "https://tik.storyclone.com/"
}
);
})
if (data.code != 0) {
result.status = false;
result.message = "Tidak dapat menemukan akun";
console.log(result);
return result;
result.status = false
result.message = "Tidak dapat menemukan akun"
console.log(result)
return result
}
result.status = true;
result.data = pickRandom(data.data.videos);
console.log(result.status);
return result;
result.status = true
result.data = pickRandom(data.data.videos)
console.log(result.status)
return result
}

const listCerpen = async () => {
const { data } = await axios.get(baseCerpen);
let result = [];
const $ = cheerio.load(data);
const { data } = await axios.get(baseCerpen)
let result = []
const $ = cheerio.load(data)
$("#content > article > strong > a").each(function () {
result.push($(this).attr("href"));
});
const rndm = pickRandom(result);
return rndm;
};
result.push($(this).attr("href"))
})
const rndm = pickRandom(result)
return rndm
}

async function getCerpenHorror() {
try {
const getUrl = async () => {
const randomNumber = Math.floor(Math.random() * 127);
const { data } = await axios.get(
`https://cerpenmu.com/category/cerpen-horor-hantu/page/${randomNumber}`
);
const $ = cheerio.load(data);
let result = [];
const randomNumber = Math.floor(Math.random() * 127)
const { data } = await axios.get(`https://cerpenmu.com/category/cerpen-horor-hantu/page/${randomNumber}`)
const $ = cheerio.load(data)
let result = []
$("div#wrap > #content > article > article").each(function () {
result.push($(this).find("h2 > a").attr("href"));
});
return pickRandom(result);
};
const url = await getUrl();
const { data } = await axios.get(url);
let $ = cheerio.load(data);
result.push($(this).find("h2 > a").attr("href"))
})
return pickRandom(result)
}
const url = await getUrl()
const { data } = await axios.get(url)
let $ = cheerio.load(data)
const result = {
status: true,
title: $("#content > article > h1").text(),
creator: $("#content > article > a:nth-child(2)").text(),
category: $("#content > article > a:nth-child(4)").text(),
story: $("#content > article > p").text().split("Cerpen Karangan")[0],
};
return result;
story: $("#content > article > p").text().split("Cerpen Karangan")[0]
}
return result
} catch (err) {
const result = {
status: false,
message: String(err),
};
message: String(err)
}
}
}
async function getCerpen() {
try {
const getUrlCerpen = await listCerpen();
const { data } = await axios.get(getUrlCerpen);
const $ = cheerio.load(data);
const getUrlCerpen = await listCerpen()
const { data } = await axios.get(getUrlCerpen)
const $ = cheerio.load(data)
const result = {
status: true,
title: $("#content > article > h1").text(),
creator: $("#content > article > a:nth-child(2)").text(),
category: $("#content > article > a:nth-child(4)").text(),
cerpen: $("#content > article > p").text(),
};
return result;
cerpen: $("#content > article > p").text()
}
return result
} catch {
const result = {
status: false,
message: "Unknown error occurred",
};
console.log(result);
return result;
message: "Unknown error occurred"
}
console.log(result)
return result
}
}

async function truthOrDare(language) {
const lang = language ? language : "id";
const lang = language ? language : "id"
try {
const dareFunc = async () => {
const { data } = await axios(`https://psycatgames.com/api/tod-v2/`, {
Expand All @@ -157,81 +147,81 @@ async function truthOrDare(language) {
id: "truth-or-dare",
language: lang,
category: "mixed",
type: "dare",
type: "dare"
},
headers: {
Referer: "https://psycatgames.com",
},
});
const randomResult = pickRandom(data.results);
return randomResult;
};
const dare = await dareFunc(lang);
Referer: "https://psycatgames.com"
}
})
const randomResult = pickRandom(data.results)
return randomResult
}
const dare = await dareFunc(lang)
const { data } = await axios(`https://psycatgames.com/api/tod-v2/`, {
method: "post",
data: {
id: "truth-or-dare",
language: lang,
category: "mixed",
type: "truth",
type: "truth"
},
headers: {
Referer: "https://psycatgames.com",
},
});
const randomResult = pickRandom(data.results);
Referer: "https://psycatgames.com"
}
})
const randomResult = pickRandom(data.results)
const result = {
status: true,
dare: dare,
truth: randomResult,
};
return result;
truth: randomResult
}
return result
} catch (err) {
console.log(err);
const res = { status: false, message: "Unknown error occurred." };
return res;
console.log(err)
const res = { status: false, message: "Unknown error occurred." }
return res
}
}

async function neko() {
try {
const { data } = await axios.get("https://api.waifu.pics/sfw/neko");
return data;
const { data } = await axios.get("https://api.waifu.pics/sfw/neko")
return data
} catch (err) {
console.log(err);
return String(err);
console.log(err)
return String(err)
}
}

async function waifu() {
try {
const { data } = await axios.get("https://api.waifu.pics/sfw/waifu");
return data;
const { data } = await axios.get("https://api.waifu.pics/sfw/waifu")
return data
} catch (err) {
console.log(err);
return String(err);
console.log(err)
return String(err)
}
}

async function shinobu() {
try {
const { data } = await axios.get("https://api.waifu.pics/sfw/shinobu");
return data;
const { data } = await axios.get("https://api.waifu.pics/sfw/shinobu")
return data
} catch (err) {
console.log(err);
return String(err);
console.log(err)
return String(err)
}
}

module.exports = {
anime: {
neko,
waifu,
shinobu,
shinobu
},
hubbleImg,
truthOrDare,
getCerpen,
getCerpenHorror,
randomTiktok,
};
randomTiktok
}

0 comments on commit 069b9ef

Please sign in to comment.