-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
57 lines (47 loc) · 1.57 KB
/
main.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
import time
import typing
import spotipy
import os
from spotipy.oauth2 import SpotifyOAuth
from telethon.sync import TelegramClient
from telethon import functions, types
import bd
api_id = bd.api_id
api_hash = bd.api_hash
status = bd.status
spotify = spotipy.Spotify(
auth_manager=SpotifyOAuth(
scope="user-read-currently-playing",
client_id=bd.client_id,
client_secret=bd.client_secret,
redirect_uri=bd.redirect_uri,
username=bd.spotiusername,
)
)
current_playing = typing.List[typing.Union[str, str, str]]
def update_status(_current_playing):
current = spotify.current_user_playing_track()
if not current is None:
track = current["item"]["name"]
album = current["item"]["album"]["name"]
artist = current["item"]["artists"][0]["name"]
if _current_playing != [track, album, artist]:
muzon = "🎧 Spotify | " + artist + " - " + track
with TelegramClient('anon', api_id, api_hash) as client:
result = client(functions.account.UpdateProfileRequest(about=muzon))
print(f"🎧 Spotify | {track} - {artist}")
return [track, album, artist]
if not _current_playing is None:
print("None")
time.sleep(6)
with TelegramClient('anon', api_id, api_hash) as client:
result = client(functions.account.UpdateProfileRequest(about=status))
return
if __name__ == '__main__':
try:
while True:
print("Получаю обновления")
current_playing = update_status(current_playing)
time.sleep(8)
except Exception as e:
print(e)