Skip to content

Instantly share code, notes, and snippets.

@Chaos53925
Last active February 23, 2023 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chaos53925/08c5b8e0475f9c4b8a65affb92cb3736 to your computer and use it in GitHub Desktop.
Save Chaos53925/08c5b8e0475f9c4b8a65affb92cb3736 to your computer and use it in GitHub Desktop.
A Python script that reads the Player.log file from the game Rail Route and displays the stations and train numbers that are too late or too early. The display of the trains arriving too early can be switched off.
import os
import platform
# Get the operating system
system = platform.system()
# Set the path to the log file based on the operating system
if system == 'Windows':
log_path = os.path.join(os.environ['USERPROFILE'], 'AppData', 'LocalLow', 'bitrich', 'Rail Route', 'Player.log')
elif system == 'Linux':
log_path_1 = os.path.join(os.path.expanduser('~'), '.config', 'unity3d', 'bitrich', 'Rail Route', 'Player.log')
log_path_2 = os.path.join(os.path.expanduser('~'), '.var', 'app', 'com.valvesoftware.Steam', '.config', 'unity3d', 'bitrich', 'Rail Route', 'Player.log')
# Check if both log files exist
if os.path.exists(log_path_1) and os.path.exists(log_path_2):
print('Two possible log files found:')
print('1:', log_path_1)
print('2:', log_path_2)
choice = input('Which log file do you want to read? (1/2) ')
if choice == '1':
log_path = log_path_1
elif choice == '2':
log_path = log_path_2
else:
print('Invalid choice.')
exit()
elif os.path.exists(log_path_1):
log_path = log_path_1
elif os.path.exists(log_path_2):
log_path = log_path_2
else:
print('Log file not found.')
exit()
elif system == 'Darwin':
log_path = os.path.join(os.path.expanduser('~/Library/Logs'), 'bitrich', 'Rail Route', 'Player.log')
else:
print('Unsupported operating system:', system)
exit()
# Check if the log file exists
if not os.path.exists(log_path):
print('Log file not found.')
exit()
# Open the log file in read mode and read the lines
with open(log_path, 'r') as f:
lines = f.readlines()
# Ask the user if trains that arrived too early should also be displayed
show_negative = input("Should trains that arrived too early be displayed? (y/n) ") == "y"
# Go through each line and search for the string "Difference in minutes for".
for line in lines:
if 'Difference in minutes for train ' in line:
if line.strip().endswith(':0'):
continue # Jump to next line
rest_of_line = line.replace('Difference in minutes for train ', '')
if not show_negative and rest_of_line.split(":")[-1].startswith('-'):
continue # Jump to next line if negative values should not be displayed
print(rest_of_line)
if system == 'Windows':
os.system('pause')
else:
input('Press Enter to exit...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment