Created
November 28, 2022 19:33
-
-
Save aMir733/72b1455f3b1eb3f51a826893da2c0dcc to your computer and use it in GitHub Desktop.
Updates your telegram bio to the name of the song that you're listening to on Spotify
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 pyrogram import Client | |
from apscheduler.schedulers.asyncio import AsyncIOScheduler | |
import requests | |
from multiprocessing import Manager | |
api_id = 0 | |
api_hash = "" | |
app = Client("my_account", api_id, api_hash) | |
form = "{0} - {1}" # 0: song name | 1: artist name | |
default = "" # Default bio | |
async def go_default(): | |
print("something went wrong. changing to default: " + default) | |
await app.update_protfile(bio=default) | |
async def status(): | |
headers = { | |
"Accept": "applictaion/json", | |
"Content-Type": "application/json", | |
"Authorization": "Bearer " | |
"SPOTIFY-OAUTH-TOKEN", | |
} | |
try: | |
r = requests.get("https://api.spotify.com/v1/me/player/currently-playing", headers=headers).json() | |
name = r['item']['name'] | |
num = len(r['item']['artists']) | |
artists = [r['item']['artists'][i]['name'] for i in range(num)] | |
final = form.format(name, ', '.join(artists)) | |
if final == last.value: | |
return | |
last.value = final | |
print("changing to: " + final) | |
await app.update_profile(bio=final) | |
except: | |
await go_default() | |
exit(1) | |
manager = Manager() | |
last = manager.Value('l', '') | |
scheduler = AsyncIOScheduler() | |
scheduler.add_job(status, "interval", seconds=10) | |
scheduler.start() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment