SHARE
TWEET

Untitled

a guest Jul 16th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env python
  2. import sys
  3.  
  4. help_text = "Syntax: tracking_splitter [tracking_num[, tracking_num, ...]]\n"
  5.  
  6. tracking_nums = []
  7. if len(sys.argv) < 2:
  8.     print("Capturing from stdin. Enter tracking numbers separated by newlines.\n"+
  9.             "Enter 'exit' to finish")
  10.     tracking_num = ""
  11.     while True:
  12.         tracking_num = input().strip()
  13.         if tracking_num == "":
  14.             continue
  15.         if 'exit' in tracking_num.lower():
  16.             print()
  17.             break
  18.         tracking_nums.append(tracking_num)
  19. else:
  20.     if sys.argv[1] in ['-h', '--help']:
  21.         print(help_text)
  22.         sys.exit()
  23.     tracking_nums = sys.argv[1:]
  24.  
  25. BOLD_START = "\033[1m"
  26. BOLD_END = "\033[0m"
  27.  
  28. result = []
  29. bold_on = False
  30. for tracking_num in tracking_nums:
  31.     for idx, c in enumerate(tracking_num):
  32.         is_mod_4 = idx % 4 == 0
  33.         if is_mod_4 and idx != 0:
  34.             if not bold_on:
  35.                 result.append(BOLD_START)
  36.                 bold_on = True
  37.             else:
  38.                 result.append(BOLD_END)
  39.                 bold_on = False
  40.             result.append(' ')
  41.         result.append(c)
  42.  
  43.     if bold_on:
  44.         result.append(BOLD_END)
  45.         bold_on = False
  46.     if tracking_num != tracking_nums[-1]:
  47.         result.append('\n')
  48.  
  49. print("".join(result))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top