IMKYZABITCHES

ARK: Survival Evolved | arkSummary.py | Python 3.11 | WebAPI Population

Jun 26th, 2023 (edited)
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.73 KB | Source Code | 0 0
  1. #                                                   Author: kek/bitwise/kyza
  2.  
  3.  
  4.  
  5. #       Utilises wildcards available webAPI to get the current player count on Xbox, Playstation and Mobile.
  6. #                       Also displays the amount of banned players per platform (not mobile)
  7. #                                       Includes top servers per platform (population)
  8.  
  9.  
  10. #       python -m pip install urllib3
  11. #       python -m pip uninstall urllib3-secure-extra
  12.  
  13. import urllib3, json, time
  14.  
  15. from threading import Thread
  16.  
  17. from datetime import datetime, date
  18.  
  19. from enum import IntEnum
  20.  
  21.  
  22. total = []
  23.  
  24. TOTAL = 0
  25.  
  26. XBOX = 0
  27. PSN = 1
  28. MOBILE = 2
  29.  
  30. OFFICIAL = 0
  31. SMALLS = 1
  32. NOTEK = 2
  33. CROSS = 3
  34. BEGINNER = 4
  35. SOTF = 5
  36. ARKPOC = 6
  37. HARDCORE = 7
  38. LDL = 8
  39. PRIMPLUS = 9
  40. PVE = 10
  41. UNOFFICIAL = 11
  42.  
  43. count = 0
  44.  
  45. now = {"day": datetime.now().day, "month": datetime.now().month, "year": datetime.now().year, "hr": datetime.now().hour, "min": datetime.now().minute, "sec": datetime.now().second, "ms": datetime.now().microsecond}
  46.  
  47. platformID = [ "xbox", "sotfps4", "mobile" ]
  48.  
  49. serverID = [ "official", "smalls", "notek", "cross", "beginner", "sotf", "arkpoc", "hardcore", "LDL", "primplus", "pve", "unofficial" ]
  50.  
  51. dayNT = [ "st", "nd", "rd" ]
  52.  
  53. class Day(IntEnum):
  54.     Monday = 0
  55.     Tuesday = 1
  56.     Wednesday = 2
  57.     Thursday = 3
  58.     Friday = 4
  59.     Saturday = 5
  60.     Sunday = 6
  61.  
  62.     @classmethod
  63.     def today(cls):
  64.         return cls(date.today().weekday()).name
  65.  
  66. class Month(IntEnum):
  67.     January = 1
  68.     Febuary = 2
  69.     March = 3
  70.     April = 4
  71.     May = 5
  72.     June = 6
  73.     July = 7
  74.     August = 8
  75.     September = 9
  76.     October = 10
  77.     November = 11
  78.     December = 12
  79.  
  80.     @classmethod
  81.     def today(cls):
  82.         return cls(datetime.now().month).name
  83.  
  84.  
  85. def GetPopulationForPlatform(pL, sID=OFFICIAL):
  86.     population = {"Name":[],"Population":[], "CanHold":[], "Num":0}
  87.     if pL >= XBOX and pL <= MOBILE: JSON = json.loads(urllib3.request("GET",
  88.                                                                       f"""http://arkdedicated.com/{platformID[pL] if sID != UNOFFICIAL else platformID[pL].replace("sotfps4", "ps4")}/cache/{"official" if sID != UNOFFICIAL else "unofficial"}serverlist.json""").data.decode("utf-8"))
  89.     else:
  90.         print("Incorrect platform ID\n")
  91.         return -1
  92.     for i in range(len(JSON)-1):    #   loop through json (all servers)
  93.         if pL < MOBILE:
  94.             name = JSON[i]["Name"]      #   store server name in local var
  95.             match sID:
  96.                 case 0:     #   OFFICIAL
  97.                     if "PVP" in name and "Small" not in name and "legacy" not in name.lower() and "NoTek" \
  98.                        not in name and "Cross" not in name and "Beginner" \
  99.                        not in name and "SOTF" not in name and "poc" not in \
  100.                        name and "Hardcore" not in name and "LDL" not in name and "PrimPlus" not in name:
  101.                         population["Name"].append(name)
  102.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  103.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  104.                         population["Num"] += 1
  105.                 case 1:     #   SMALLS
  106.                     if "PVP" in name and "Small" in name and "LDL" not in name:
  107.                         population["Name"].append(name)
  108.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  109.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  110.                         population["Num"] += 1
  111.                 case 2:     #   NOTEK
  112.                     if "PVP" in name and "NoTek" in name:
  113.                         population["Name"].append(name)
  114.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  115.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  116.                         population["Num"] += 1
  117.                 case 3:     #   CROSS
  118.                     if "PVP" in name and "Cross" in name and "NoTek" not in name:
  119.                         population["Name"].append(name)
  120.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  121.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  122.                         population["Num"] += 1
  123.                 case 4:     #   BEGINNER
  124.                     if "PVP" in name and "Beginner" in name:
  125.                         population["Name"].append(name)
  126.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  127.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  128.                         population["Num"] += 1
  129.                 case 5:     #   SOTF
  130.                     if "SOTF" in name:
  131.                         population["Name"].append(name)
  132.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  133.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  134.                         population["Num"] += 1
  135.                 case 6:     #   ARKPOC
  136.                     if "PVP" in name and "poc" in name:
  137.                         population["Name"].append(name)
  138.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  139.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  140.                         population["Num"] += 1
  141.                 case 7:     #   HARDCORE
  142.                     if "PVP" in name and "Hardcore" in name:
  143.                         population["Name"].append(name)
  144.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  145.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  146.                         population["Num"] += 1
  147.                 case 8:     #   LDL
  148.                     if "LDL" in name:
  149.                         population["Name"].append(name)
  150.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  151.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  152.                         population["Num"] += 1
  153.                 case 9:     #   PRIMPLUS
  154.                     if "PVP" in name and "Prim" in name:
  155.                         population["Name"].append(name)
  156.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  157.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  158.                         population["Num"] += 1
  159.                 case 10:
  160.                     if "PVE" in name:
  161.                         population["Name"].append(name)
  162.                         population["Population"].append(int(JSON[i]["NumPlayers"]))
  163.                         population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  164.                         population["Num"] += 1
  165.                 case 11:
  166.                     population["Name"].append(name)
  167.                     population["Population"].append(int(JSON[i]["NumPlayers"]))
  168.                     population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  169.                     population["Num"] += 1
  170.                 case _:
  171.                     print("Incorrect session ID\n")
  172.                     return -1
  173.            
  174.         else:
  175.             population["Name"].append(JSON[i]["Name"])
  176.             population["Population"].append(int(JSON[i]["NumPlayers"]))
  177.             population["CanHold"].append(int(JSON[i]["MaxPlayers"]))
  178.             population["Num"] += 1
  179.     print(f'{platformID[pL].upper() if pL != PSN else "PSN"} {serverID[sID]}:\n')
  180.     print(f'\tHighest pop: \n\n\t\t{population["Name"][population["Population"].index(max(population["Population"]))]} with population of {max(population["Population"])}/{population["CanHold"][population["Population"].index(max(population["Population"]))]} players\n\n')
  181.     print(f'\tNumber of Empty Servers: {population["Population"].count(0)}\n')
  182.     return list([sum(population["Population"]), population["Num"]])
  183.  
  184. def displayPop(pL, sID=OFFICIAL):
  185.     global TOTAL
  186.     x = GetPopulationForPlatform(pL, sID)
  187.     total.append(x[0])
  188.     TOTAL = x[1]
  189.     return x[0]
  190.  
  191.  
  192. def clearTotal():
  193.     global total, TOTAL
  194.     TOTAL = 0
  195.     total = []
  196.     return "players"
  197.  
  198.  
  199. def getNotation():
  200.     nDay = int(str(now["day"]/10)[2])-1
  201.     if (int(str(now["day"]/10)[0]) == 1 and int(str(now["day"]/10)[2]) < 4) or (nDay+1 > 3 and nDay+1 < 20): # 11th, 12th, 13th, 21st, 22nd, 23rd, 31st and NOT 11rd, 12nd, 13rd, 21th, 22th, 23th, 31th
  202.         return "th"
  203.     return dayNT[nDay]
  204.  
  205.  
  206. def main():
  207.     global count, now
  208.     while True:
  209.         count = 0
  210.         now = {"day": datetime.now().day, "month": datetime.now().month, "year": datetime.now().year, "hr": datetime.now().hour, "min": datetime.now().minute, "sec": datetime.now().second, "ms": datetime.now().microsecond}
  211.         print(f"""
  212.  
  213.        Number online players as of {Day.today()} {now["day"]}{getNotation()} of {Month.today()} {now["year"]} at {now["hr"]-12 if now["hr"] > 12 else now["hr"]}:{now["min"] if now["min"] >= 10 else f"0{now['min']}"}{"PM" if (now["hr"] >= 12) else "AM"}:
  214.  
  215.            XBOX:
  216.                OFFICIAL: {displayPop(XBOX, OFFICIAL)}      (out of {TOTAL} servers)
  217.                SMALLS: {displayPop(XBOX, SMALLS)}          (out of {TOTAL} servers)
  218.                NOTEK: {displayPop(XBOX, NOTEK)}            (out of {TOTAL} servers)
  219.                CROSS: {displayPop(XBOX, CROSS)}            (out of {TOTAL} servers)
  220.                BEGINNER: {displayPop(XBOX, BEGINNER)}      (out of {TOTAL} servers)
  221.                SOTF: {displayPop(XBOX, SOTF)}              (out of {TOTAL} servers)
  222.                ARKPOC: {displayPop(XBOX, ARKPOC)}          (out of {TOTAL} servers)
  223.                HARDCORE: {displayPop(XBOX, HARDCORE)}      (out of {TOTAL} servers)
  224.                LDL: {displayPop(XBOX, LDL)}                (out of {TOTAL} servers)
  225.                PRIMPLUS: {displayPop(XBOX, PRIMPLUS)}      (out of {TOTAL} servers)
  226.                PVE: {displayPop(XBOX, PVE)}                (out of {TOTAL} servers)
  227.                UNOFFICIAL: {displayPop(XBOX, UNOFFICIAL)}  (out of {TOTAL} servers)
  228.  
  229.                TOTAL: {sum(total)} {clearTotal()}
  230.  
  231.  
  232.            PSN:
  233.                OFFICIAL: {displayPop(PSN)}                 (out of {TOTAL} servers)
  234.                SMALLS: {displayPop(PSN, SMALLS)}           (out of {TOTAL} servers)
  235.                NOTEK: {displayPop(PSN, NOTEK)}             (out of {TOTAL} servers)
  236.                CROSS: {displayPop(PSN, CROSS)}             (out of {TOTAL} servers)
  237.                BEGINNER: {displayPop(PSN, BEGINNER)}       (out of {TOTAL} servers)
  238.                SOTF: {displayPop(PSN, SOTF)}               (out of {TOTAL} servers)
  239.                ARKPOC: {displayPop(PSN, ARKPOC)}           (out of {TOTAL} servers)
  240.                HARDCORE: {displayPop(PSN, HARDCORE)}       (out of {TOTAL} servers)
  241.                LDL: {displayPop(PSN, LDL)}                 (out of {TOTAL} servers)
  242.                PRIMPLUS: {displayPop(PSN, PRIMPLUS)}       (out of {TOTAL} servers)
  243.                PVE: {displayPop(PSN, PVE)}                 (out of {TOTAL} servers)
  244.                UNOFFICIAL: {displayPop(PSN, UNOFFICIAL)}   (out of {TOTAL} servers)
  245.  
  246.                TOTAL: {sum(total)} {clearTotal()}
  247.  
  248.  
  249.            MOBILE:
  250.                OFFICIAL: {displayPop(MOBILE)}              (out of {TOTAL} servers)\n\n""")
  251.  
  252.  
  253.         xuidList = urllib3.request("GET", "http://arkdedicated.com/xboxbanlist.txt").data
  254.         psnList = urllib3.request("GET", "http://arkdedicated.com/ps4banlist.txt").data
  255.         pcList = urllib3.request("GET", "http://arkdedicated.com/banlist.txt").data
  256.         sgList = urllib3.request("GET", "http://arkdedicated.com/conquestbanlist.txt").data
  257.  
  258.         xuidList = str(xuidList).replace("b'", "").replace("'","").split("\\r\\n")
  259.         psnList = str(psnList).replace("b'", "").replace("'","").split("\\r\\n")
  260.         pcList = str(pcList).replace("b'", "").replace("'","").split("\\r\\n")
  261.         sgList = str(sgList).replace("b'", "").replace("'","").split("\\r\\n")
  262.  
  263.         banMessage = f"""
  264.  
  265.                Xbox Banned Players: {len(list(xuidList))}
  266.                PSN Banned Players: {len(list(psnList))}
  267.                PC Banned Players (Wildcard): {len(list(pcList))}
  268.                PC Banned Players (Snail Games): {len(list(sgList))}
  269.  
  270.                Total Banned Players: {len(list(xuidList)) + len(list(psnList))+ len(list(pcList)) + len(list(sgList))}
  271.                """
  272.  
  273.         print(f"""Number online players as of {Day.today()} {now["day"]}{getNotation()} of {Month.today()} {now["year"]} at {now["hr"]-12 if now["hr"] > 12 else now["hr"]}:{now["min"] if now["min"] >= 10 else f"0{now['min']}"}{"PM" if (now["hr"] >= 12) else "AM"}:\n\n{banMessage}""")
  274.         print(f"Took {count} seconds to complete\n")
  275.         input()
  276. Thread(target=main).start()
  277. while True:
  278.     count = count + 1
  279.     time.sleep(1)
Add Comment
Please, Sign In to add comment