Skip to content

Instantly share code, notes, and snippets.

@subsr97
Created June 18, 2019 06:10
Show Gist options
  • Save subsr97/bfca76787c45c11cca2645ede6cad55a to your computer and use it in GitHub Desktop.
Save subsr97/bfca76787c45c11cca2645ede6cad55a to your computer and use it in GitHub Desktop.
A python script for Linux, that converts a copied timestamp to date and shows it in a message box.
try:
import pyperclip
import os
from tkinter import Tk, messagebox
import subprocess
except Exception as e:
print("Import Error: Modules pyperclip and Tkinter are needed.")
exit(1)
def executeCommand(command):
try:
subProcess = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE)
subProcess.wait()
(output, _) = subProcess.communicate()
opText = output.decode()
return opText.strip()
except Exception as exception:
print(exception)
exit(0)
def main(timestamp):
top = Tk()
top.withdraw()
dateAndTime = executeCommand("date -d@"+timestamp)
exitCode = executeCommand("echo $?")
if exitCode == "0":
messagebox.showinfo("Timestamp", timestamp+"\n"+dateAndTime)
else:
messagebox.showinfo("Timestamp", "Invalid timestamp!")
if __name__ == "__main__":
timestamp = pyperclip.paste().strip()
if timestamp.isnumeric():
main(timestamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment