Advertisement
Guest User

boilog

a guest
Jan 5th, 2017
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.11 KB | None | 0 0
  1. #!/usr/bin/python3
  2. """Reads from the BoI log file in live.
  3.  
  4. Selectively displays stuff that modders care about.
  5. If you don't want your log filtered, use the "info" argument.
  6.  
  7. The script must be ran after the game is started, and it must be restarted
  8. if the game has been shutdown and relaunched.
  9.  
  10. It will read each line one after the other on an infinit loop.
  11. If the file gets updated (ie: a line is added) it will display it and
  12. lower the reading cooldown.
  13. If nothing happen on the reading loop, it increase the reading cooldown.
  14.  
  15. author: gibonus
  16. """
  17. from os import path
  18. from sys import argv, platform
  19. from time import sleep
  20.  
  21. SHOW_INFO_DEFAULT = False
  22.  
  23. ERR_WORDS = ('Error', 'fail', 'ERR', 'error')
  24. DBG_WORDS = ('Debug',)
  25. WRN_WORDS = ('warn', 'lua', 'Lua', 'collectible')
  26.  
  27. WINDOWS_LOCATION = path.expanduser(
  28.     '~/Documents/My Games/Binding of Isaac Afterbirth+/log.txt')
  29. LINUX_LOCATION = path.expanduser(
  30.     '~/.local/share/binding of isaac afterbirth+/log.txt')
  31. OSX_LOCATION = path.expanduser(
  32.     '~/Library/Application Support/Binding of Isaac Afterbirth+ Mods/log.txt')
  33.  
  34. SYSTEM_LOCATION = \
  35.     WINDOWS_LOCATION if platform == 'win32'  else \
  36.     OSX_LOCATION     if platform == 'darwin' else \
  37.     LINUX_LOCATION
  38. print("Your Isaac log locations is: " + SYSTEM_LOCATION)
  39.  
  40. showInfo = SHOW_INFO_DEFAULT
  41. if len(argv) > 1 and argv[1] == 'info':
  42.     showInfo = True
  43.  
  44. with open(SYSTEM_LOCATION, 'r') as f:
  45.     stime = 0.08
  46.     while True:
  47.         t = f.readline()
  48.         if t != '':
  49.             t = t.replace('[INFO] - ', '')
  50.             stime = 0.08
  51.             hasIssue = False
  52.             hasDebug = False
  53.  
  54.             if any((e in t) for e in ERR_WORDS):
  55.                 print('\033[1;31m', t, end='\033[0m',sep='')
  56.             elif any((e in t) for e in DBG_WORDS):
  57.                 print('\033[1;32m', t, end='\033[0m',sep='')
  58.             elif any((e in t) for e in WRN_WORDS):
  59.                 print('\033[1;33m', t, end='\033[0m',sep='')
  60.             else:
  61.                 if showInfo: print(t,end='')
  62.         else:
  63.             stime = stime * 2 if stime < 1.2 else 1.2
  64.         sleep(stime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement