Advertisement
Guest User

Untitled

a guest
Jun 4th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.96 KB | Music | 0 0
  1. import spotipy
  2. from spotipy.oauth2 import SpotifyClientCredentials
  3.  
  4. dicto = {"BASS": ["ALLEYCVT",
  5. "ATLiens",
  6. "Barclay Crenshaw",
  7. "Black Tiger Sex Machine",
  8. "Caspa",
  9. "Chase & Status",
  10. "Dimension",
  11. "Excision",
  12. "Gigantic NGHTMRE",
  13. "Hamdi",
  14. "LEVEL UP",
  15. "Lucii",
  16. "LYNY",
  17. "LSZEE",
  18. "Sammy Virji",
  19. "Subtronics",
  20. "venbee",
  21. "Whyte Fang",
  22. "Wooli",
  23. "Seven lions",
  24. "G jones",
  25. "Boogie T",
  26. "CannaBliss",
  27. "Ivy Lab",
  28. "levity",
  29. "Super Future",
  30. "Zen Selekta",],
  31. "HOUSE": ["ACRAZE",
  32. "AYYBO",
  33. "Ben Bohmer",
  34. "Calussa",
  35. "Cassian",
  36. "Charlotte De Witte",
  37. "Coco & Breezy",
  38. "DJ Tennis",
  39. "DRAMA",
  40. "EVERYTHING ALWAYS",
  41. "Green Velvet",
  42. "it's murph",
  43. "John Summit",
  44. "Knock2",
  45. "Le Youth",
  46. "LP Giobbi",
  47. "Major League Djz",
  48. "Matroda",
  49. "Mau P",
  50. "Michael Brun",
  51. "ODEN & Fatzo",
  52. "Ranger Trucco",
  53. "Sultan + Shepard",
  54. "TSHA",
  55. "Vini Vici",
  56. "VNSSA B2B Nala",
  57. "Westend",
  58. "Will Clarke",
  59. "Sara Landry",
  60. "Baggi",
  61. "Brandi Cyrus",
  62. "Chaos in CBD",
  63. "DJ Susan",
  64. "H&RRY",
  65. "Layton Giordani",
  66. "marsh",
  67. "MASONIC",
  68. "Mojave Grey",
  69. "odd Mob",
  70. "Only fire",
  71. "Rayben",
  72. "Shae District",
  73. "Swaylo",],
  74. "INDIE": ["Cuco",
  75. "NEIL FRANCES",
  76. "Peach Tree Rascals",
  77. "Emo Nite",
  78. "Equanimous",
  79. "Kiltro",],
  80. "POP": ["Cannons",
  81. "Mascolo",
  82. "Nelly Furtado",
  83. "Slayyyter",
  84. "Neoma",
  85. "Unusual demont",],
  86. "JAM": ["Dirtwire",
  87. "Dumpstaphunk",
  88. "Eggy",
  89. "Lettuce",
  90. "Pretty Lights",
  91. "Disco Biscuits",
  92. "String Cheese Incident",
  93. "Umphrey's McGee",
  94. "Jjuujjuu",
  95. "Proxima Parada",],
  96. "TRAP": ["INZO",
  97. "Juelz",
  98. "Maddy O'Neal",
  99. "Redrum",
  100. "Thought process",
  101. "Tripp St.",],
  102. "RAP": ["Kenny Beats",
  103. "Libianca",
  104. "Ludacris",
  105. "PAPERWATER",
  106. "hiatus kaiyote",
  107. "Little stranger",],
  108. "SOUL": ["Dixon's Violin",
  109. "Rawayana",
  110. "Polyrhythmics",]
  111. }
  112.  
  113.  
  114. for_spotify ={ "Chaos in CBD" : "Chaos In The CBD",
  115. "Disco Biscuits": "The Disco Biscuits",
  116. "Proxima Parada" : "Próxima Parada",
  117. "String Cheese Incident" : "The String Cheese Incident",
  118. "Gigantic NGHTMRE" : "Big Gigantic",
  119. "EVERYTHING ALWAYS" : "Dom Dolla",
  120. "LSZEE": "CloZee",
  121. "Michael Brun" : "Michaël Brun",
  122. "Ben Bohmer" : "Ben Böhmer"}
  123.  
  124.  
  125. STAGES = [ "RANCH_ARENA", "SHERWOOD_COURT", "TRIPOLEE", "CAROUSEL_CLUB", "OBSERVATORY", "HONEYCOMB"]
  126.  
  127. '''
  128. {
  129. .artist = "EZBK ",
  130. .stage = RANCH_ARENA,
  131. .start_time = {.unit.year = 4, .unit.month = 6, .unit.day = 20, .unit.hour = 15, .unit.minute = 0},
  132. .end_time = {.unit.year = 4, .unit.month = 6, .unit.day = 20, .unit.hour = 16, .unit.minute = 0},
  133. .genre = TRAP,
  134. },
  135.  
  136.  
  137. '''
  138.  
  139. def get_artist(artist_name):
  140. client_id = 'REDACTED'
  141. client_secret = 'REDACTED'
  142. artist_name = for_spotify.get(artist_name, artist_name)
  143. first_match = False
  144. if "'" in artist_name:
  145. first_match = True
  146. artist_name = artist_name.replace("'", "")
  147.  
  148. # Authenticate with Spotify
  149. auth_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
  150. sp = spotipy.Spotify(auth_manager=auth_manager)
  151.  
  152. # Search for the artist
  153. result = sp.search(q='artist:' + artist_name, type='artist')
  154. artist_results = result['artists']['items']
  155. if not artist_results:
  156. print(f"FAILED TO FIND: {artist_name}")
  157. return None
  158. artist_info = None
  159. names_in_search = []
  160. for option in artist_results:
  161. name = option['name']
  162. if first_match:
  163. #print(f"BEST MATCH for :{artist_name} is {name}")
  164. artist_info = option
  165. break
  166. names_in_search.append(name)
  167. if name.upper() == artist_name.upper():
  168. #print(f"Found {name}")
  169. artist_info = option
  170. break
  171. if artist_info is None:
  172. print(f"FAILED TO FIND: {artist_name}, BUT FOUND {names_in_search}")
  173. return None
  174. return artist_info
  175.  
  176. def get_artist_followers_popularity(artist_name):
  177. artist_info = get_artist(artist_name)
  178. if artist_info is None:
  179. return 0,0
  180. followers = artist_info['followers']['total']
  181. popularity = artist_info['popularity']
  182. return followers, popularity
  183.  
  184.  
  185. def rank_artists_by_popularity(artists):
  186. # Sort artists by popularity in descending order
  187. sorted_artists = sorted(artists, key=lambda x: x['followers'], reverse=True)
  188.  
  189. # Create a dictionary to store the ranks
  190. artist_ranks = {}
  191.  
  192. # Assign ranks starting from 1
  193. for rank, artist in enumerate(sorted_artists, start=1):
  194. artist_ranks[artist['name']] = rank
  195.  
  196. return artist_ranks
  197.  
  198. def findGenre(act):
  199. for key in dicto:
  200. for i in dicto[key]:
  201. if i.upper() == act.upper():
  202. return key.upper()
  203. return -1
  204.  
  205. def get_overall_ranking(artists, name):
  206. for artist in artists:
  207. if artist['name'].lower() == name.lower():
  208. return artist['overall']
  209. return None
  210.  
  211. # Spits out the array of acts in alphabetically order.
  212. listActs = []
  213. for key in dicto:
  214. for i in dicto[key]:
  215. listActs.append(i)
  216. listActs = sorted(listActs, key=str.casefold)
  217.  
  218. listActsPop = []
  219. print("act, followers, popularity")
  220. for act in listActs:
  221. followers, popularity = get_artist_followers_popularity(act)
  222. print(f"{act}, {followers}, {popularity}")
  223. listActsPop.append({'name':act, 'followers' : followers, "popularity" : popularity})
  224.  
  225. sorted_listing = sorted(listActsPop, key=lambda x: (x['popularity'], x['followers']), reverse=True)
  226.  
  227. # Add an "overall" key
  228. for i, artist in enumerate(sorted_listing):
  229. artist['overall'] = i + 1
  230.  
  231. for i, act in enumerate(listActs):
  232. print(" {")
  233. print(f' .artist = "{act.upper()[:6]}",')
  234. print(f' .stage = {STAGES[i % len(STAGES)]},')
  235. print(" .start_time = {.unit.year = 4, .unit.month = 6, .unit.day = 20, .unit.hour = 15, .unit.minute = 0},")
  236. print(" .end_time = {.unit.year = 4, .unit.month = 6, .unit.day = 20, .unit.hour = 16, .unit.minute = 0},")
  237. print(f' .genre = {findGenre(act)},')
  238. print(f' .popularity = {get_overall_ranking(sorted_listing, act)}')
  239. print(" },")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement