Add random status generator

This commit is contained in:
sHa
2024-04-07 01:05:53 +03:00
parent 051b1b4e40
commit 13475a7db4
9 changed files with 157 additions and 55 deletions

View File

@@ -1,4 +1,5 @@
from appscript import app # type: ignore
from appscript import app # type: ignore
class AppleMusic:
def __init__(self):
@@ -7,11 +8,14 @@ class AppleMusic:
def get_current_track_info(self) -> tuple:
try:
current_track = self.music_app.current_track.get()
current_position = self.music_app.player_position.get()
track_duration = current_track.duration.get()
return (
current_track.name.get(),
current_track.artist.get(),
current_track.duration.get(),
track_duration,
current_position,
)
except Exception as e:
print(f"Failed to get current track info: {e}")
return None, None, None
return None, None, None, None

27
connectors/random.py Normal file
View File

@@ -0,0 +1,27 @@
from faker import Faker
import random
import emoji
class Random:
def __init__(self):
self.faker = Faker()
def get_random_activity(self) -> tuple:
activity = self.faker.bs().capitalize() # Generate a random activity
emoji = self.get_random_emoji_name() # Get a random emoji
duration = random.randint(5, 60) # Duration in minutes
return activity, emoji, duration
def get_random_emoji_name(self) -> str:
emoji_names = list(emoji.get_aliases_unicode_dict())
single_char_emoji_names = [
name for name in emoji_names if len(emoji.emojize(name)) == 1
]
random_emoji_name = random.choice(single_char_emoji_names)
return random_emoji_name
def get_random_emoji(self) -> str:
random_emoji = emoji.emojize(self.get_random_emoji_name())
return random_emoji

View File

@@ -1,17 +1,30 @@
import osascript # type: ignore
import osascript # type: ignore
class Spotify:
def get_current_track_info(self) -> tuple:
try:
name_code = 'tell application "Spotify" to name of current track as string'
artist_code = 'tell application "Spotify" to artist of current track as string'
duration_code = 'tell application "Spotify" to duration of current track as string'
artist_code = (
'tell application "Spotify" to artist of current track as string'
)
duration_code = (
'tell application "Spotify" to duration of current track as string'
)
elapsed_time_code = (
'tell application "Spotify" to player position as string'
)
name = osascript.osascript(name_code)[1]
artist = osascript.osascript(artist_code)[1]
duration = int(osascript.osascript(duration_code)[1]) / 1000 # Convert duration from ms to s
duration = (
int(osascript.osascript(duration_code)[1]) / 1000
) # Convert duration from ms to s
elapsed_time = (
float(osascript.osascript(elapsed_time_code)[1].replace(',','.'))
) # Elapsed time in seconds
return name, artist, duration
return name, artist, duration, elapsed_time
except Exception as e:
print(f"Failed to get current track info: {e}")
return None, None, None
return None, None, None, None