Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # * * * * * cd <folder with project>; /usr/bin/python3 <folder with project>/main.py > <folder with project>/log.txt
- # Replace EVERY "<>" with the correct content (should be 3)
- import asyncio
- from pyppeteer import launch
- import requests
- threadName = "<>"
- fileName = "store.txt"
- webhookUrl = "<>"
- async def getPostCount(threadName):
- browser = await launch(headless=True)
- page = await browser.newPage()
- await page.goto('<>', {'waitUntil' : 'domcontentloaded'})
- await page.waitFor(2000) # wait for js
- namesAndComments = await page.evaluate('''() => {
- namesAndComments = [...document.querySelector("table").querySelector("tbody").querySelectorAll("tr")].map(e => [e.children[0].innerText, e.children[4].innerText]);
- return namesAndComments;
- }''')
- for pair in namesAndComments:
- if pair[0] == threadName:
- toReturn = pair[1]
- await browser.close()
- return toReturn
- async def main():
- numPosts = -1
- try:
- file = open(fileName, "r")
- numPosts = int(file.read())
- file.close()
- file = open(fileName, "w")
- except FileNotFoundError:
- file = open(fileName, "w+")
- newNumPosts = int(await getPostCount(threadName))
- if(newNumPosts > numPosts):
- print("number changed")
- data = {"content": f"New post(s) created! [{numPosts}] -> [{newNumPosts}]"}
- numPosts = newNumPosts
- requests.post(webhookUrl, data=data)
- print(numPosts)
- file.write(str(numPosts))
- file.close()
- asyncio.get_event_loop().run_until_complete(main())
Advertisement
Add Comment
Please, Sign In to add comment