K1ngkai

Untitled

May 7th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import urllib.request
  2. import urllib
  3. import json
  4.  
  5.  
  6.  
  7. def get_data():
  8. print('I can help you search for some items!')
  9. print('I can search for movies, TV shows, Music and much more! Please enter a Name, Title, or movie below and I can see if i can help!')
  10. user_search = input('Please enter here or press [ENTER] to exit: ')
  11. if user_search == '':
  12. quit()
  13. else:
  14. payload={'q':user_search}
  15. user_search=urllib.parse.urlencode(payload)
  16. api_url = "https://tastedive.com/api/similar?" + user_search +"&q="
  17. page=urllib.request.Request(api_url,headers={'User-Agent': 'Mozilla/5.0'})
  18. infile=urllib.request.urlopen(page).read()
  19. decoded = infile.decode('utf8')
  20. the_dictionary = json.loads(decoded)
  21. return the_dictionary
  22. results = get_data()
  23. for mydict in results.values():
  24. acc = 0
  25. for inf in mydict['Info']:
  26. print('Here is your results for: ')
  27. print(str(inf).replace('{','').replace('}',''))
  28. for res in mydict['Results']:
  29. acc += 1
  30. for val in res.values():
  31. print(acc,val)
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment