Yaoi-Spinner/scraper.js

34 lines
No EOL
1,004 B
JavaScript

import { Scraper } from "@the-convocation/twitter-scraper"
import { flavors, variety } from "./constants.js"
const scraper = new Scraper({
})
await scraper.login(process.env.USERNAME, process.env.PASSWORD)
export async function scrapeYaoi() {
var finalArray = []
for (let typeIndex in flavors) {
let types = flavors[typeIndex]
finalArray[typeIndex] = []
for (let flavor of types) {
// console.log(flavor)
var search = scraper.searchTweets(flavor, variety, "media")
for await (var value of search) {
if (value.html.includes("img") & !finalArray.includes(value)) {
finalArray[typeIndex].push(value)
}
}
}
}
return finalArray
}
export var yaoiList = await scrapeYaoi()
export function getYaoi() {
var yaoi = yaoiList[Math.floor(Math.random() * yaoiList.length)]
yaoi = yaoi[Math.floor(Math.random() * yaoi.length)]
return yaoi
}