-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommands.py
154 lines (111 loc) · 3.67 KB
/
commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
These commands are functions that ChatGPT will use
if the user requests it.
So far the user can ask ChatGPT to:
- Open or close an application
- Interact with their spotify by:
- Playing an album, playlist, or song.
"""
# ************************************************
# * Utilities
import AppOpener
from dotenv import load_dotenv
import psutil
import traceback
from spotify_player import Spotify_Player
load_dotenv('.env')
# ************************************************
# * Utility functions
def is_open(app_name: str, include_exe: bool = False) -> bool:
"""
Confirms if an application is open or not.
Parameters:
- include_exe : bool (optional)
- Determines if .exe should be included in the application
name to search for.
Returns:
"""
if include_exe:
app_name = str.strip(app_name) + ".exe"
opened = False
for i in psutil.process_iter():
if str.lower(app_name) in str.lower(i.name()):
opened = True
break
return opened
# *********************************
# * Commands
# * Open an app
def open_app(name: str) -> str:
"""
Uses the AppOpener python package to open an application
Parameters:
- name : str
- The name of the application
"""
# * First check if the app is already opened
# for i in psutil.process_iter():
# if str.lower(name) in str.lower(i.name()):
# print(i.name())
# not_opened = False
# opened = is_open(name)
# if not opened:
try:
print("Attempting to open app")
AppOpener.open(name, match_closest=True, throw_error=True, output=False)
except:
error = traceback.format_exc
traceback.print_exc()
return error
else:
output = format("{name} was successfully opened")
return output
# * Close an app
def close_app(name: str) -> str:
"""
Uses the AppOpener python package to close an application
Parameters:
- name : str
- The name of the application
"""
try:
AppOpener.close(name, match_closest=True, throw_error=True, output=False)
except:
traceback.print_exc()
else:
output = format("{name} was successfully closed".format(name=name))
return output
# * Commands that will use the Spotify_Player class
def use_spotify_player(spotify_object: type[Spotify_Player], play_option: bool = True, item: str = "", type: str="track"):
"""
Uses an instance of the Spotify_Player class to play music on Spotify.
Parameters:
- spotify_object : type[Spotify_Player]
- An instance of the Spotify_Player class
- play_option : bool, optional
- Determines whether to play or pause the user's music on spotify.
True --> play, False --> pause
- item : str, optional
- The item that the user wants to play on Spotify.
- type : str
- The type of the item the user wants to play.
Options --> "Track", "Album", "Playlist"
"""
# * Determine if the user wants to play or pause the playback on Spotify
if play_option:
# * Determine if type is track, album, or playlist
if "track" in type.lower():
spotify_object.play_track(item)
elif "album" in type.lower():
spotify_object.play_album(item)
elif "playlist" in type.lower():
spotify_object.play_playlist(item)
else:
spotify_object.pause()
return "success"
def sleep() -> None:
"""
This function will be passed to ChatGPT. This function will help
determine if user input should continue to be processed or not.
"""
return ""