Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.0 kB
6
Indexable
Never
import requests
import re
import copy
import time

from datetime import date
from bs4 import BeautifulSoup


class KillStatistics:
    def __init__(self):
        self.records = []
        self.watched_names = ["Test"]
        self.iter = 0

    def parse_records(self):
        r = requests.get("http://149.56.28.71/?subtopic=killstatistics")
        soup = BeautifulSoup(r.content, "html.parser")
        table = soup.findChildren("table")

        for record in table:
            for data in record:
                if data.text == "Last Deaths":
                    pass
                else:
                    entry = data.text
                    entry = re.split("..?(?=[0-9][A-Z]).", data.text)
                    entry[0] = entry[0].split(", ")
                    entry[0][0] = entry[0][0].split(".")

                    entry_id, day, month, year, hour = (
                        entry[0][0][0],
                        entry[0][0][1],
                        entry[0][0][2],
                        entry[0][0][3],
                        entry[0][1],
                    )

                    message = entry[1]
                    nickname = (re.findall(".+?(?=at)", message)[0]).strip()
                    killed_by = (re.findall(r"(?<=\bby).*", message)[0]).strip()
                    if self.iter < 1:
                        self.records.append(f"{nickname} was killed by {killed_by} at {day}-{month}-{year} {hour}")
                    elif self.iter > 1 and f"{nickname} was killed by {killed_by} at {day}-{month}-{year} {hour}" not in self.records:
                        print(f"{nickname} was killed by {killed_by} at {day}-{month}-{year} {hour}")
                        self.records.append(f"{nickname} was killed by {killed_by} at {day}-{month}-{year} {hour}")
                        self.records.pop(0)
        print("---")
        self.iter += 1
                    
ks = KillStatistics()
if __name__ == "__main__":
    while True:
        ks.parse_records()
        #print(ks.records)
        time.sleep(10)