Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const low = require('lowdb')
- const FileSync = require('lowdb/adapters/FileSync')
- const db = low(new FileSync('db.json'))
- const analysisDB = low(new FileSync('analysis.json'))
- const Entities = require('html-entities').Html5Entities
- const entities = new Entities()
- const main = async () => {
- console.log("loading...")
- const chanData = db.getState()
- console.log("DONE")
- const analysis = {}
- for(let board in chanData){
- analysis[board] = {
- threads: 0,
- replies: 0,
- images: 0,
- characters: 0,
- totalThreadAgeSeconds: 0,
- uniqueIPs: 0, // not 'actually' unique IPs, just the sum of the unique posters per thread
- avgRepliesPerMinutePerThread: 0,
- avgPostLength: 0,
- imageRatio: 0,
- avgThreadAgeHours: 0,
- avgPostersPerThread: 0,
- avgPostsByPoster: 0, // per thread
- }
- for(let threadNum in chanData[board]){
- const thread = chanData[board][threadNum]
- const OP = thread.posts[0]
- if(OP.closed || OP.sticky || thread.posts.length == 1) continue // remove
- const threadAge = thread.posts[thread.posts.length - 1].time - OP.time
- /*
- if(OP.sticky){
- threadAge = thread.posts[thread.posts.length - 1].time - thread.posts[1].time
- }
- */
- analysis[board].threads++
- analysis[board].replies += OP.replies
- analysis[board].images += OP.images
- for(let post of thread.posts){
- if(!post.com) post.com = ""
- if(board == "p") post.com = post.com.replace(/<span class="abbr">.+<\/table>/gms,"") //removes EXIF text from /p/ posts
- post.com = post.com.replace(/<a.*?<\/a>|<br>/gm," ") //replace post-links and linebreaks with a space
- post.com = post.com.replace(/<.*?>/gm,"") //remove any other HTML tags; greentext-HTML, /g/ [code], etc., but its text-content is kept
- post.com = entities.decode(post.com) //convert html entities to actual characters: ">" becomes ">"
- post.com = post.com.trim() //remove whitespace from start and end
- analysis[board].characters += post.com.length
- }
- analysis[board].totalThreadAgeSeconds += threadAge
- analysis[board].uniqueIPs += OP.unique_ips
- }
- analysis[board].avgRepliesPerMinutePerThread = analysis[board].replies / (analysis[board].totalThreadAgeSeconds / 60)
- analysis[board].avgPostLength = analysis[board].characters / analysis[board].replies
- analysis[board].imageRatio = analysis[board].images / analysis[board].replies
- analysis[board].avgThreadAgeHours = analysis[board].totalThreadAgeSeconds / 3600 / analysis[board].threads
- analysis[board].avgPostersPerThread = analysis[board].uniqueIPs / analysis[board].threads
- analysis[board].avgPostsByPoster = (analysis[board].replies + analysis[board].threads) / analysis[board].uniqueIPs
- console.log(`/${board}/`)
- console.log(analysis[board])
- }
- analysisDB.setState(analysis)
- analysisDB.write()
- }
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement