Skip to content

Instantly share code, notes, and snippets.

@INDIAN2020
Created May 16, 2021 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save INDIAN2020/5285c4a2932e802df6ba5b551aa68f33 to your computer and use it in GitHub Desktop.
Save INDIAN2020/5285c4a2932e802df6ba5b551aa68f33 to your computer and use it in GitHub Desktop.
from subprocess import Popen, PIPE
from sys import argv
import platform
import datetime
class Janitor:
start = 0
end = 0
def __init__(self, **kwargs) -> None:
self.start = datetime.datetime.now()
kwargs.setdefault('projects', "gcloud projects list")
self.execute_command(kwargs['projects'])
def execute_command(self, command):
output = Popen([command], stdout=PIPE, shell=True)
process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
(response, err) = process.communicate()
if response.decode("utf-8"):
return response.decode("utf-8").splitlines()
else:
pass
def millis_interval(self, start, end):
diff = end - start
millis = diff.days * 24 * 60 * 60 * 1000
millis += diff.seconds * 1000
millis += diff.microseconds / 1000
return millis
def __del__(self):
self.end = datetime.datetime.now()
print(self.millis_interval(self.start, self.end))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment