Skip to content

Instantly share code, notes, and snippets.

@MobCat
Created April 10, 2023 04:43
Show Gist options
  • Select an option

  • Save MobCat/baf76956f8e4c96c5d511ad844e714b3 to your computer and use it in GitHub Desktop.

Select an option

Save MobCat/baf76956f8e4c96c5d511ad844e714b3 to your computer and use it in GitHub Desktop.
Slow and trash tool for dumping Hydro Thunder scores from Twin Galaxies. This could be used with other TG scores if adjusted.
#!/env/Python3.10.4
#/MobCat (2023)
# A super shit and super slow tool for automatically downloading Hydro Thunder arcade
# times for Twin Galaxies and exporting them into a csv you can use with
# https://github.com/AkBKukU/HydroThunder-TimeTool
# as TG does not seem to display player initials and boats used
# a lookup table was made for players, and boats will be chosen randomly.
# The "Not Accessible" tracks will have default data placed there
# as TG does not have times for these tracks... as they are not accessible in game.
# players.csv can be found here
# https://gist.githubusercontent.com/MobCat/f0ca884d052ea5383c0b7743bd95f7e9/raw/e704a566a92dacc25abf82f2878202f9ce0bdeb4/players.csv
# Download it and stick it in the same folder as this py.
import requests # Slurp data
from bs4 import BeautifulSoup # help us filter through the data we slurped
import os # OS functions like file saveing, loading and cleaning screen
import json # Dump the data we slurped into an easy to read json file
import random # For picking a boat
import datetime # For time stamp for csv file name
import csv # Load players, I should be using this for saveing too...
# URL to rip
def DumpInfo(track):
url = f"https://www.twingalaxies.com/game/hydro-thunder/arcade/{track}/page/1"
rawsteam = requests.get(url).text
soup = BeautifulSoup(rawsteam, 'lxml')
titlels = [] # Game titles
# Build lists
for item in soup.find_all('div', class_ = 'twinga'):
for item2 in item.find_all('ul', class_ = 'gd-rank-list'):
# Split each item into lines, filter out empty strings, strip leading/trailing spaces
lines = [line.strip() for line in filter(bool, item2.text.splitlines())]
titlels.append(lines)
# Split the long list into sub-lists on all instances of the word "Rank"
split_lists = []
current_list = []
for element in [item for w in titlels for item in w]:
if element == "Rank":
if current_list:
split_lists.append(current_list)
current_list = [element]
else:
current_list.append(element)
if current_list:
split_lists.append(current_list)
# Remove empty strings from each sub-list
for lst in split_lists:
lst[:] = filter(bool, lst)
return split_lists
# Load players list once on load
with open('players.csv', 'r', newline='') as file:
players = [item for row in csv.reader(file) for item in row]
'''
print(players)
exit()
'''
# Look up the player
def findName(fineName, players):
# find the index of the player name in the list
if fineName in players:
index = players.index(fineName)
elif fineName[:3] in players:
index = players.index(fineName[:3])
else:
index = -1
# return the index + 1 or the first 3 characters of the player name
return players[index + 1].upper() if index >= 0 else fineName[:3].upper()
# Boat list to randomly pick a boat from.
boats = ["Banshee","Tidal Blade","Rad Hazzard","Miss Behave","Damn the Torpedoes","Cutthroat","Razorback","Thresher","Midway","Chumdinger","Armed Response","Blowfish","Tinytanic"]
# Setup file name to export to.
timestamp = datetime.datetime.now().strftime('%Y%m%d')
exportFile = f'TGHydroThunder-{timestamp}.csv'
print(f"Downloading times to {exportFile}\nPlease wait...")
# Do the things, dump times using DumpInfo() and write to file.
# This is NOT how you make a csv, but im doing it anyways.
with open(exportFile, 'w') as file:
# csv headder
file.write('Track,Initials,Boat,Timestamp\n')
# Ship Graveyard
print('Downloading Ship Graveyard')
for i in DumpInfo('ship-graveyard-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Ship Graveyard,{findName(i[2], players)},{boats[roll]},{time}\n")
# Lost Island
print('Downloading Lost Island')
for i in DumpInfo('lost-island-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Lost Island,{findName(i[2], players)},{boats[roll]},{time}\n")
# Venice Canals
print('Downloading Venice Canals')
for i in DumpInfo('venice-canals-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Venice Canals,{findName(i[2], players)},{boats[roll]},{time}\n")
# Lake Powell
print('Downloading Lake Powell')
for i in DumpInfo('lake-powell-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Lake Powell,{findName(i[2], players)},{boats[roll]},{time}\n")
# Arctic Circle
print('Downloading Arctic Circle')
for i in DumpInfo('arctic-circle-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Arctic Circle,{findName(i[2], players)},{boats[roll]},{time}\n")
# Nile Adventure
print('Downloading Nile Adventure')
for i in DumpInfo('nile-adventure-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Nile Adventure,{findName(i[2], players)},{boats[roll]},{time}\n")
# N.Y. Disaster
print('Downloading N.Y. Disaster')
for i in DumpInfo('n-y-disaster-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"N.Y. Disaster,{findName(i[2], players)},{boats[roll]},{time}\n")
# Greek Isles
print('Downloading Greek Isles')
for i in DumpInfo('greek-isles-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Greek Isles,{findName(i[2], players)},{boats[roll]},{time}\n")
# The Far East
print('Downloading The Far East')
for i in DumpInfo('the-far-east-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"The Far East,{findName(i[2], players)},{boats[roll]},{time}\n")
print('Using defalt data for TEST - Not Accessible')
file.write('TEST - Not Accessible,SER,Cutthroat,05:25.54\n')
file.write('TEST - Not Accessible,MRS,Razorback,05:50.69\n')
file.write('TEST - Not Accessible,SSP,Banshee,06:15.93\n')
file.write('TEST - Not Accessible,SWG,Miss Behave,06:32.59\n')
file.write('TEST - Not Accessible,EDB,Thresher,06:34.13\n')
file.write('TEST - Not Accessible,BAS,Damn the Torpedoes,06:36.83\n') # How is .83 faster??
file.write('TEST - Not Accessible,GTC,Tidal Blade,06:36.43\n')
file.write('TEST - Not Accessible,DJH,Rad Hazzard,06:37.58\n')
file.write('TEST - Not Accessible,AEW,Tidal Blade,06:39.91\n')
file.write('TEST - Not Accessible,O H,Midway,06:40.09\n')
# Thunder Park
print('Downloading Thunder Park')
for i in DumpInfo('thunder-park-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Thunder Park,{findName(i[2], players)},{boats[roll]},{time}\n")
# Hydro Speedway
print('Downloading Hydro Speedway')
for i in DumpInfo('hydro-speedway-fastest-race'):
if int(i[1]) < 11 :
if i[13] == 'Elapsed Time':
time = i[14]
else:
time = i[13]
roll = random.randint(0, 12)
file.write(f"Hydro Speedway,{findName(i[2], players)},{boats[roll]},{time}\n")
# Seems to be just using the same times from the test track?
print('Using defalt data for Castle Von Dandy - Not Accessible')
file.write('Castle Von Dandy - Not Accessible,SER,Cutthroat,05:25.54\n')
file.write('Castle Von Dandy - Not Accessible,MRS,Razorback,05:50.69\n')
file.write('Castle Von Dandy - Not Accessible,SSP,Banshee,06:15.93\n')
file.write('Castle Von Dandy - Not Accessible,SWG,Miss Behave,06:32.59\n')
file.write('Castle Von Dandy - Not Accessible,EDB,Thresher,06:34.13\n')
file.write('Castle Von Dandy - Not Accessible,BAS,Damn the Torpedoes,06:36.83\n') # How is .83 faster??
file.write('Castle Von Dandy - Not Accessible,GTC,Tidal Blade,06:36.43\n')
file.write('Castle Von Dandy - Not Accessible,DJH,Rad Hazzard,06:37.58\n')
file.write('Castle Von Dandy - Not Accessible,AEW,Tidal Blade,06:39.91\n')
file.write('Castle Von Dandy - Not Accessible,O H,Midway,06:40.09')
print("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment