Created
May 16, 2021 10:01
-
-
Save INDIAN2020/5285c4a2932e802df6ba5b551aa68f33 to your computer and use it in GitHub Desktop.
This file contains 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
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