diff --git a/build/lib/datetime-utils/__init__.py b/build/lib/datetime-utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/datetime-utils/get_day.py b/build/lib/datetime-utils/get_day.py similarity index 100% rename from datetime-utils/get_day.py rename to build/lib/datetime-utils/get_day.py diff --git a/build/lib/datetimeutils/__init__.py b/build/lib/datetimeutils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/build/lib/datetimeutils/get_day.py b/build/lib/datetimeutils/get_day.py new file mode 100644 index 0000000..ec855e6 --- /dev/null +++ b/build/lib/datetimeutils/get_day.py @@ -0,0 +1,63 @@ +from datetime import datetime + +class GetDay(): + + def __init__(self, datetime_class=None): + if datetime_class: + self.day = datetime_class + else: + self.day = datetime.now() + + def get_weekday(self) -> str: + day_number = self.day.weekday() + day_and_number = { + "Monday" : 0, + "Tuesday" : 1, + "Wednesday" : 2, + "Thursday" : 3, + "Friday" : 4, + "Saturday" : 5, + "Sunday" : 6 + } + for day, number in day_and_number.items(): + if day_number == number: + return day + + @classmethod + def get_weekday_from_number(cls, day_number: int) -> str: + day_and_number = { + "Monday" : 0, + "Tuesday" : 1, + "Wednesday" : 2, + "Thursday" : 3, + "Friday" : 4, + "Saturday" : 5, + "Sunday" : 6 + } + for day, number in day_and_number.items(): + if day_number == number: + return day + + +# Sample usage + +# Create the instance +# today = GetDay() +# or +# today = GetDay(datetime(2017, 2, 2)) + +# print the date you've passed into the class +# print(today.day) + +# get the day of the week in text - this will either return today +# or the day of the datetime object you passed in +# print(today.get_weekday()) + +# or you can get the day of the week based on the number +# like in the following scenario +# >>> import datetime +# >>> datetime.datetime.today() +# datetime.datetime(2012, 3, 23, 23, 24, 55, 173504) +# >>> number = datetime.datetime.today().weekday() +# >>> print(GetDay.get_weekday_from_number(number)) +# 'Wednesday' diff --git a/build/lib/processor-utils/__init__.py b/build/lib/processor-utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/processor-utils/process.py b/build/lib/processor-utils/process.py similarity index 100% rename from processor-utils/process.py rename to build/lib/processor-utils/process.py diff --git a/build/lib/processorutils/__init__.py b/build/lib/processorutils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/build/lib/processorutils/process.py b/build/lib/processorutils/process.py new file mode 100644 index 0000000..c83bdcb --- /dev/null +++ b/build/lib/processorutils/process.py @@ -0,0 +1,111 @@ +import psutil + + +class Process(): + + def __init__( + self, pid: int = None, + name: str = None + ): + self.pid = pid + self.name = name + + + def is_running(self) -> bool: + """ + Takes the name of a process and + returns True if it is running, + False if it isn't""" + if self.name: + target_process_name = self.name + for process in psutil.process_iter(): + if self.name.lower() == process.name().lower(): + return True + return False + # if the name isn't specified, use the pid instead + elif self.pid: + for process in psutil.process_iter(): + if self.pid == process.pid: + return True + return False + + + def get_pid(self) -> int: + """ + Uses self.name to get the pid + of the specified process""" + if not self.name: + print("Name not provided in instance") + else: + for process in psutil.process_iter(): + if self.name.lower() == process.name().lower(): + return process.pid + return "Process not found" + + + def get_name(self) -> str: + """ + Uses self.pid to get the name + of the specifried process""" + if not self.pid: + print("PID not provided in instance") + else: + for process in psutil.process_iter(): + if self.pid == process.pid: + return process.name() + return False + + + def get_run_time(self) -> str: + """ + Uses self.pid or self.name + to get the specified process + and returns it's runtime""" + if self.name: + from datetime import datetime + for process in psutil.process_iter(): + if self.name.lower() == process.name().lower(): + epoch_created_time = process.create_time() + dt_created_time = datetime.fromtimestamp(epoch_created_time) + time_elapsed = datetime.now() - dt_created_time + # https://stackoverflow.com/a/10981895 + hours, remainder = divmod(time_elapsed.seconds, 3600) + minutes, seconds = divmod(remainder, 60) + if time_elapsed.days != 0: + return ( + f"{time_elapsed.days} day/s" + f"{hours} hour/s" + f"{minutes}minute/s" + ) + else: + return f"{hours} hour/s {minutes} minute/s" + return "Process not found" + elif self.pid: + from datetime import datetime + for process in psutil.process_iter(): + if self.pid == process.pid: + epoch_created_time = process.create_time() + dt_created_time = datetime.fromtimestamp(epoch_created_time) + time_elapsed = datetime.now() - dt_created_time + # https://stackoverflow.com/a/10981895 + hours, remainder = divmod(time_elapsed.seconds, 3600) + minutes, seconds = divmod(remainder, 60) + if time_elapsed.days != 0: + return ( + f"{time_elapsed.days} day/s" + f"{hours} hour/s" + f"{minutes}minute/s" + ) + else: + return f"{hours} hour/s {minutes} minute/s" + return "Process not found" + + + + +a = Process(pid=10678) +# print(a.pid) +# print(a.name) + +print(a.get_name()) +print(a.get_run_time()) diff --git a/dist/wise_py_utils-0.0.1-py3-none-any.whl b/dist/wise_py_utils-0.0.1-py3-none-any.whl new file mode 100644 index 0000000..cf1fdd5 Binary files /dev/null and b/dist/wise_py_utils-0.0.1-py3-none-any.whl differ diff --git a/enter-typos/README.md b/enter-typos/README.md deleted file mode 100644 index dda6f42..0000000 --- a/enter-typos/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Enter typos - -Often when hitting enter, I accidentally hit a key next to it. Often the resulting input can end up looking like this. - -```py -characters = ["/", "'" "\" "]"] -input = " " -``` - -This library is designed to remove trailing special characters from strings and integers and return what the user actually mean to enter. - diff --git a/scan-file/README.md b/scan-file/README.md deleted file mode 100644 index 9910ea3..0000000 --- a/scan-file/README.md +++ /dev/null @@ -1 +0,0 @@ -Scans a specified file for a regex or string pattern and returns a list of all the results diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..0507f36 --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +from setuptools import setup, find_packages + + +setup( + name='wise-py-utils', + version='0.0.1', + description='Python utils created by Zac the Wise', + packages=find_packages( + where='src', + ), + package_dir={"": "src"} + #package_dir={'get_day': 'src/datetime-utils',}, + # packages=find_packages(where="src") + #py_modules=('datetimeutils'), + #packages=['datetime-utils'] +) diff --git a/datetime-utils/README.md b/src/datetimeutils/README.md similarity index 100% rename from datetime-utils/README.md rename to src/datetimeutils/README.md diff --git a/src/datetimeutils/__init__.py b/src/datetimeutils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/datetimeutils/get_day.py b/src/datetimeutils/get_day.py new file mode 100644 index 0000000..ec855e6 --- /dev/null +++ b/src/datetimeutils/get_day.py @@ -0,0 +1,63 @@ +from datetime import datetime + +class GetDay(): + + def __init__(self, datetime_class=None): + if datetime_class: + self.day = datetime_class + else: + self.day = datetime.now() + + def get_weekday(self) -> str: + day_number = self.day.weekday() + day_and_number = { + "Monday" : 0, + "Tuesday" : 1, + "Wednesday" : 2, + "Thursday" : 3, + "Friday" : 4, + "Saturday" : 5, + "Sunday" : 6 + } + for day, number in day_and_number.items(): + if day_number == number: + return day + + @classmethod + def get_weekday_from_number(cls, day_number: int) -> str: + day_and_number = { + "Monday" : 0, + "Tuesday" : 1, + "Wednesday" : 2, + "Thursday" : 3, + "Friday" : 4, + "Saturday" : 5, + "Sunday" : 6 + } + for day, number in day_and_number.items(): + if day_number == number: + return day + + +# Sample usage + +# Create the instance +# today = GetDay() +# or +# today = GetDay(datetime(2017, 2, 2)) + +# print the date you've passed into the class +# print(today.day) + +# get the day of the week in text - this will either return today +# or the day of the datetime object you passed in +# print(today.get_weekday()) + +# or you can get the day of the week based on the number +# like in the following scenario +# >>> import datetime +# >>> datetime.datetime.today() +# datetime.datetime(2012, 3, 23, 23, 24, 55, 173504) +# >>> number = datetime.datetime.today().weekday() +# >>> print(GetDay.get_weekday_from_number(number)) +# 'Wednesday' diff --git a/src/datetimeutils/wise_py_utils.egg-info/PKG-INFO b/src/datetimeutils/wise_py_utils.egg-info/PKG-INFO new file mode 100644 index 0000000..c8ff229 --- /dev/null +++ b/src/datetimeutils/wise_py_utils.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: wise-py-utils +Version: 0.0.1 +Summary: Python utils created by Zac the Wise +Home-page: UNKNOWN +Author: UNKNOWN +Author-email: UNKNOWN +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN diff --git a/src/datetimeutils/wise_py_utils.egg-info/SOURCES.txt b/src/datetimeutils/wise_py_utils.egg-info/SOURCES.txt new file mode 100644 index 0000000..c538522 --- /dev/null +++ b/src/datetimeutils/wise_py_utils.egg-info/SOURCES.txt @@ -0,0 +1,6 @@ +README.md +setup.py +datetime-utils/wise_py_utils.egg-info/PKG-INFO +datetime-utils/wise_py_utils.egg-info/SOURCES.txt +datetime-utils/wise_py_utils.egg-info/dependency_links.txt +datetime-utils/wise_py_utils.egg-info/top_level.txt \ No newline at end of file diff --git a/src/datetimeutils/wise_py_utils.egg-info/dependency_links.txt b/src/datetimeutils/wise_py_utils.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/datetimeutils/wise_py_utils.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/src/datetimeutils/wise_py_utils.egg-info/top_level.txt b/src/datetimeutils/wise_py_utils.egg-info/top_level.txt new file mode 100644 index 0000000..342e9a1 --- /dev/null +++ b/src/datetimeutils/wise_py_utils.egg-info/top_level.txt @@ -0,0 +1,10 @@ +- +a +d +e +i +l +m +s +t +u diff --git a/src/processorutils/__init__.py b/src/processorutils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/processorutils/process.py b/src/processorutils/process.py new file mode 100644 index 0000000..c83bdcb --- /dev/null +++ b/src/processorutils/process.py @@ -0,0 +1,111 @@ +import psutil + + +class Process(): + + def __init__( + self, pid: int = None, + name: str = None + ): + self.pid = pid + self.name = name + + + def is_running(self) -> bool: + """ + Takes the name of a process and + returns True if it is running, + False if it isn't""" + if self.name: + target_process_name = self.name + for process in psutil.process_iter(): + if self.name.lower() == process.name().lower(): + return True + return False + # if the name isn't specified, use the pid instead + elif self.pid: + for process in psutil.process_iter(): + if self.pid == process.pid: + return True + return False + + + def get_pid(self) -> int: + """ + Uses self.name to get the pid + of the specified process""" + if not self.name: + print("Name not provided in instance") + else: + for process in psutil.process_iter(): + if self.name.lower() == process.name().lower(): + return process.pid + return "Process not found" + + + def get_name(self) -> str: + """ + Uses self.pid to get the name + of the specifried process""" + if not self.pid: + print("PID not provided in instance") + else: + for process in psutil.process_iter(): + if self.pid == process.pid: + return process.name() + return False + + + def get_run_time(self) -> str: + """ + Uses self.pid or self.name + to get the specified process + and returns it's runtime""" + if self.name: + from datetime import datetime + for process in psutil.process_iter(): + if self.name.lower() == process.name().lower(): + epoch_created_time = process.create_time() + dt_created_time = datetime.fromtimestamp(epoch_created_time) + time_elapsed = datetime.now() - dt_created_time + # https://stackoverflow.com/a/10981895 + hours, remainder = divmod(time_elapsed.seconds, 3600) + minutes, seconds = divmod(remainder, 60) + if time_elapsed.days != 0: + return ( + f"{time_elapsed.days} day/s" + f"{hours} hour/s" + f"{minutes}minute/s" + ) + else: + return f"{hours} hour/s {minutes} minute/s" + return "Process not found" + elif self.pid: + from datetime import datetime + for process in psutil.process_iter(): + if self.pid == process.pid: + epoch_created_time = process.create_time() + dt_created_time = datetime.fromtimestamp(epoch_created_time) + time_elapsed = datetime.now() - dt_created_time + # https://stackoverflow.com/a/10981895 + hours, remainder = divmod(time_elapsed.seconds, 3600) + minutes, seconds = divmod(remainder, 60) + if time_elapsed.days != 0: + return ( + f"{time_elapsed.days} day/s" + f"{hours} hour/s" + f"{minutes}minute/s" + ) + else: + return f"{hours} hour/s {minutes} minute/s" + return "Process not found" + + + + +a = Process(pid=10678) +# print(a.pid) +# print(a.name) + +print(a.get_name()) +print(a.get_run_time()) diff --git a/tests/README.md b/src/tests/README.md similarity index 100% rename from tests/README.md rename to src/tests/README.md diff --git a/tests/test_get_day.py b/src/tests/test_get_day.py similarity index 100% rename from tests/test_get_day.py rename to src/tests/test_get_day.py diff --git a/src/wise_py_utils.egg-info/PKG-INFO b/src/wise_py_utils.egg-info/PKG-INFO new file mode 100644 index 0000000..c8ff229 --- /dev/null +++ b/src/wise_py_utils.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: wise-py-utils +Version: 0.0.1 +Summary: Python utils created by Zac the Wise +Home-page: UNKNOWN +Author: UNKNOWN +Author-email: UNKNOWN +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN diff --git a/src/wise_py_utils.egg-info/SOURCES.txt b/src/wise_py_utils.egg-info/SOURCES.txt new file mode 100644 index 0000000..86f7d46 --- /dev/null +++ b/src/wise_py_utils.egg-info/SOURCES.txt @@ -0,0 +1,10 @@ +README.md +setup.py +src/datetimeutils/__init__.py +src/datetimeutils/get_day.py +src/processorutils/__init__.py +src/processorutils/process.py +src/wise_py_utils.egg-info/PKG-INFO +src/wise_py_utils.egg-info/SOURCES.txt +src/wise_py_utils.egg-info/dependency_links.txt +src/wise_py_utils.egg-info/top_level.txt \ No newline at end of file diff --git a/src/wise_py_utils.egg-info/dependency_links.txt b/src/wise_py_utils.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/wise_py_utils.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/src/wise_py_utils.egg-info/top_level.txt b/src/wise_py_utils.egg-info/top_level.txt new file mode 100644 index 0000000..0dd20cc --- /dev/null +++ b/src/wise_py_utils.egg-info/top_level.txt @@ -0,0 +1,2 @@ +datetimeutils +processorutils diff --git a/tests/__pycache__/test_get_day.cpython-39-pytest-7.1.2.pyc b/tests/__pycache__/test_get_day.cpython-39-pytest-7.1.2.pyc deleted file mode 100644 index 09865db..0000000 Binary files a/tests/__pycache__/test_get_day.cpython-39-pytest-7.1.2.pyc and /dev/null differ diff --git a/wise_py_utils.egg-info/PKG-INFO b/wise_py_utils.egg-info/PKG-INFO new file mode 100644 index 0000000..c8ff229 --- /dev/null +++ b/wise_py_utils.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: wise-py-utils +Version: 0.0.1 +Summary: Python utils created by Zac the Wise +Home-page: UNKNOWN +Author: UNKNOWN +Author-email: UNKNOWN +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN diff --git a/wise_py_utils.egg-info/SOURCES.txt b/wise_py_utils.egg-info/SOURCES.txt new file mode 100644 index 0000000..c6f5bd5 --- /dev/null +++ b/wise_py_utils.egg-info/SOURCES.txt @@ -0,0 +1,6 @@ +README.md +setup.py +wise_py_utils.egg-info/PKG-INFO +wise_py_utils.egg-info/SOURCES.txt +wise_py_utils.egg-info/dependency_links.txt +wise_py_utils.egg-info/top_level.txt \ No newline at end of file diff --git a/wise_py_utils.egg-info/dependency_links.txt b/wise_py_utils.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/wise_py_utils.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/wise_py_utils.egg-info/top_level.txt b/wise_py_utils.egg-info/top_level.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/wise_py_utils.egg-info/top_level.txt @@ -0,0 +1 @@ +