Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- from influxdb import InfluxDBClient
- from requests_html import HTMLSession
- categories = {
- "java": {
- "skywars": ["solo", "team"],
- "eggwars": ["solo", "team"],
- "lucky_islands": ["solo", "team"],
- "pvp": ["duels", "FFA", "assassinations"],
- "tower_defence": ["default"],
- "minerware": ["default"],
- "parkour": ["default"],
- "snowman_survival": ["default"]
- },
- "bedrock": {
- "skywars": ["default"],
- "eggwars": ["default"],
- "minerware": ["default"],
- "survival_games": ["default"],
- "snowman_survival": ["default"]
- }
- }
- BASE_URL = "https://www.cubecraft.net/leaderboards/view_leaderboard.php"
- INFLUX_HOST = 'localhost'
- INFLUX_PORT = 8086
- INFLUX_USER = 'ccldb'
- INFLUX_PASS = ''
- INFLUX_DB = 'ccldb'
- session = HTMLSession()
- dbclient = InfluxDBClient(INFLUX_HOST, INFLUX_PORT, INFLUX_USER, INFLUX_PASS, INFLUX_DB)
- for network in categories:
- for game in categories[network]:
- r = session.get('{}?network={}&game={}'.format(BASE_URL, network, game))
- if r.status_code != 200:
- print("failed loading leaderboard for {} on {}".format(game, network))
- continue
- for category in categories[network][game]:
- t_accessed = datetime.datetime.utcnow()
- leaderboard = r.html.find('#{}_leaderboard'.format(category), first=True)
- points = []
- for entry in leaderboard.find('tr'):
- data = entry.find('td')
- if len(data) != 3:
- continue
- position, name, score = int(data[0].text), data[1].text, int(data[2].text)
- points.append({
- "measurement": 'leaderboard',
- "time": t_accessed,
- "tags": {
- "network": network,
- "name": name,
- "category": category,
- "game": game
- },
- "fields": {
- "position": position,
- "score": score
- }
- })
- dbclient.write_points(points)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement