Advertisement
Guest User

Untitled

a guest
Jan 13th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. import datetime
  2. from influxdb import InfluxDBClient
  3. from requests_html import HTMLSession
  4.  
  5.  
  6. categories = {
  7.     "java": {
  8.         "skywars": ["solo", "team"],
  9.         "eggwars": ["solo", "team"],
  10.         "lucky_islands": ["solo", "team"],
  11.         "pvp": ["duels", "FFA", "assassinations"],
  12.         "tower_defence": ["default"],
  13.         "minerware": ["default"],
  14.         "parkour": ["default"],
  15.         "snowman_survival": ["default"]
  16.     },
  17.     "bedrock": {
  18.         "skywars": ["default"],
  19.         "eggwars": ["default"],
  20.         "minerware": ["default"],
  21.         "survival_games": ["default"],
  22.         "snowman_survival": ["default"]
  23.     }
  24. }
  25.  
  26. BASE_URL = "https://www.cubecraft.net/leaderboards/view_leaderboard.php"
  27. INFLUX_HOST = 'localhost'
  28. INFLUX_PORT = 8086
  29. INFLUX_USER = 'ccldb'
  30. INFLUX_PASS = ''
  31. INFLUX_DB = 'ccldb'
  32.  
  33. session = HTMLSession()
  34. dbclient = InfluxDBClient(INFLUX_HOST, INFLUX_PORT, INFLUX_USER, INFLUX_PASS, INFLUX_DB)
  35.  
  36. for network in categories:
  37.     for game in categories[network]:
  38.         r = session.get('{}?network={}&game={}'.format(BASE_URL, network, game))
  39.         if r.status_code != 200:
  40.             print("failed loading leaderboard for {} on {}".format(game, network))
  41.             continue
  42.         for category in categories[network][game]:
  43.             t_accessed = datetime.datetime.utcnow()
  44.             leaderboard = r.html.find('#{}_leaderboard'.format(category), first=True)
  45.             points = []
  46.             for entry in leaderboard.find('tr'):
  47.                 data = entry.find('td')
  48.                 if len(data) != 3:
  49.                     continue
  50.                 position, name, score = int(data[0].text), data[1].text, int(data[2].text)
  51.                 points.append({
  52.                     "measurement": 'leaderboard',
  53.                     "time": t_accessed,
  54.                     "tags": {
  55.                         "network": network,
  56.                         "name": name,
  57.                         "category": category,
  58.                         "game": game
  59.                     },
  60.                     "fields": {
  61.                         "position": position,
  62.                         "score": score
  63.                     }
  64.                 })
  65.             dbclient.write_points(points)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement