-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (58 loc) · 2.15 KB
/
main.py
File metadata and controls
71 lines (58 loc) · 2.15 KB
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
import dotenv
import time
import os
import random
from util.spotifyApi import getCurrentPlaying
from util.auth import getAuth
from util.insta import customClient
if __name__ == "__main__":
dotenv.load_dotenv()
clientId = os.getenv("CLIENT_ID")
clientSecret = os.getenv("CLIENT_SECRET")
USERNAME = os.getenv("USERNAME")
PASSWORD = os.getenv("PASSWORD")
TOTP_SEED = os.getenv("TOTP_SEED")
instaClient = customClient()
instaClient.login_user(USERNAME, PASSWORD, TOTP_SEED)
previousTrackId = None
noteCount = 178
while True:
# each loop, ensure our token is still valid (will refresh if needed)
tokenInfo = getAuth(clientId, clientSecret)
accessToken = tokenInfo.get("access_token")
current = getCurrentPlaying(accessToken)
item = current.get("item", {})
trackId = item.get("id")
isPlaying = current.get("is_playing", False)
# skip if same track
if trackId == previousTrackId:
time.sleep(10)
continue
name = item.get("name")
album = item.get("album", {}).get("name")
artists = ", ".join(a.get("name") for a in item.get("artists", []))
prog_m, prog_s = divmod(current.get("progress_ms", 0) // 1000, 60)
dur_m, dur_s = divmod(item.get("duration_ms", 0) // 1000, 60)
if isPlaying:
print(f"Currently Playing: {name}")
else:
print(f"Last Played Track: {name}")
print(f"From: {album}")
print(f"By: {artists}")
print(f"Timestamp: {prog_m}:{prog_s:02d}/{dur_m}:{dur_s:02d}")
print("=x=" * 10)
print(" ")
try:
noteCount += 1
note = instaClient.create_note(
f"Just Vibin. Current Note Count: {noteCount}",
song_name=f"{name} {artists.split(',')[0]}",
audience=0
)
print("Note created successfully!", note)
print("=x=" * 10)
print(" ")
except Exception as e:
print("Error creating note:", e)
previousTrackId = trackId
time.sleep(random.randint(100, 140))