Last active
October 7, 2020 21:59
-
-
Save rchrd2/3a5c6cedccb75b0088a3748e93ab801a to your computer and use it in GitHub Desktop.
stash.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" | |
The idea is to take stdin, and write it to a new unique log file | |
php myscript.php | newlog filename | |
""" | |
import os | |
import sys | |
import datetime | |
import time | |
# Logs go to example /home/richard/logs | |
logdir = os.path.expanduser('~/logs') | |
# Set timezone for filename | |
os.environ['TZ'] = 'America/Los_Angeles' | |
time.tzset() | |
def parse_stream(): | |
now = datetime.datetime.now() | |
filename = now.strftime("%Y%m%dT%I%M%p") | |
if len(sys.argv) > 1: | |
filename = filename + '_' + sys.argv[1] | |
filename = logdir + '/' + filename + '.txt' | |
with open(filename, 'w') as outfile: | |
for line in sys.stdin: | |
#print(line, end="") | |
outfile.write(line) | |
print(filename) | |
#print(" ".join(sys.argv)) | |
if __name__ == '__main__': | |
parse_stream() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment