Artist Picker. Python


SUBMITTED BY: Guest

DATE: Nov. 29, 2013, 2:20 a.m.

FORMAT: Text only

SIZE: 2.0 kB

HITS: 996

  1. # This program will pick an artist from a text file
  2. import random
  3. import time
  4. import webbrowser
  5. import urllib.parse
  6. musicChecked = 0
  7. # You can get rid of the next 4 lines
  8. isfilethere = input('Is a text file created already[y/n]? >> ')
  9. if isfilethere == 'y':
  10. whatisnameoffile = input('Enter the exact name of the file with .txt >> ')
  11. print('If the file is empty, nothing will appear.')
  12. # If you got rid of the 4 lines above, be sure to correctly fix the layout
  13. while True:
  14. print("\n")
  15. # If you got rid of the 4 lines, make 'whatisnameoffile' to '[insert file name here.txt]'
  16. file = open(whatisnameoffile, 'r')
  17. line = random.choice(file.readlines())
  18. print("----------------------------------------------")
  19. print("Band/Artist: ", line)
  20. musicChecked = musicChecked + 1
  21. print("You checked out " + str(musicChecked) + " band(s)/artist(s)")
  22. openpage = input('\nWant to open the artist page on last.fm? >> ')
  23. if openpage == 'y':
  24. url = urllib.parse.urljoin('http://www.last.fm/music/',line)
  25. webbrowser.open(url)
  26. elif openpage == 'n':
  27. pass
  28. time.sleep(.5)
  29. again = input("\nAgain? >> ")
  30. print("----------------------------------------------")
  31. if again == "end":
  32. print("ok")
  33. break
  34. # Finally, if you got rid of the 4 lines, you can get rid of everything below
  35. elif isfilethere == 'n':
  36. nameoffile = input('Name the file and add .txt at the end >> ')
  37. time.sleep(1)
  38. file = open(nameoffile, 'w')
  39. file.write('One item per line.')
  40. file.close()
  41. print('Edit the file with the artists and run the program again.')
  42. else:
  43. print('N/A')

comments powered by Disqus