67 lines
1.7 KiB
Python
Executable File
67 lines
1.7 KiB
Python
Executable File
#!/usr/bin/python3
|
|
import time
|
|
import os
|
|
import readline
|
|
from datetime import datetime
|
|
|
|
# Changable optonis:
|
|
message = "Testing testing testing..."
|
|
max_iterations = 5
|
|
msg_delay = 0.2
|
|
|
|
# Autocomplete path stuffs:
|
|
def complete_path(text, state):
|
|
expanded = os.path.expanduser(os.path.expandvars(text))
|
|
|
|
if os.path.isdir(expanded):
|
|
try:
|
|
entries = os.listdir(expanded)
|
|
completion_list = [
|
|
os.path.abspath(os.path.join(expanded, entry)) + '/'
|
|
if os.path.isdir(os.path.join(expanded, entry))
|
|
else os.path.abspath(os.path.join(expanded, entry))
|
|
for entry in entries
|
|
]
|
|
except FileNotFoundError:
|
|
completion_list = []
|
|
else:
|
|
dirname = os.path.dirname(expanded)
|
|
basename = os.path.basename(expanded)
|
|
|
|
if not dirname:
|
|
dirname = '.'
|
|
|
|
try:
|
|
entries = [entry for entry in os.listdir(dirname) if entry.startswith(basename)]
|
|
completion_list = [
|
|
os.path.abspath(os.path.join(dirname, entry))
|
|
for entry in entries
|
|
]
|
|
except FileNotFoundError:
|
|
completion_list = []
|
|
|
|
completion_list.sort()
|
|
try:
|
|
return completion_list[state]
|
|
except IndexError:
|
|
return None
|
|
|
|
readline.set_completer_delims(' \t\n;')
|
|
readline.set_completer(complete_path)
|
|
readline.parse_and_bind("tab: complete")
|
|
|
|
file_path = input("File to write to: ")
|
|
|
|
try:
|
|
for i in range(max_iterations):
|
|
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
tm = "{} -- {}: itr=>{}".format(ts, message, i)
|
|
print(f"{file_path} -> {tm}")
|
|
|
|
with open(file_path, "a") as file:
|
|
file.write(tm + '\n')
|
|
|
|
time.sleep(msg_delay)
|
|
except KeyboardInterrupt:
|
|
print("Ctrl-C hit; exiting...")
|