classifier.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. from Naked.toolshed.system import exit_success
  4. class Classifier:
  5. def __init__(self, search_string):
  6. self.needle = search_string
  7. self.url = 'https://pypi.python.org/pypi?%3Aaction=list_classifiers'
  8. def run(self):
  9. from Naked.toolshed.network import HTTP
  10. http = HTTP(self.url) # use the python.org url for the classifier list
  11. print('•naked• Pulling the classifier list from python.org...')
  12. res = http.get() # get the list
  13. test_list = res.split('\n') # split on newlines
  14. if self.needle == "": # user did not enter a search string, print the entire list
  15. print("•naked• You did not provide a search string. Here is the entire list:")
  16. print(' ')
  17. for item in test_list:
  18. print(item)
  19. else: # user entered a search string, find it
  20. lower_needle = self.needle.lower()
  21. print("•naked• Performing a case insensitive search for '" + self.needle + "'")
  22. print(' ')
  23. filtered_list = [ x for x in test_list if lower_needle in x.lower() ] #case insensitive match for the search string
  24. for item in filtered_list:
  25. print(item)
  26. exit_success() # exit with zero status code
  27. def help():
  28. help_string = """
  29. Naked classify Command Help
  30. ===========================
  31. The classify command performs a case-insensitive search of the PyPI application classifier list and displays the results.
  32. USAGE
  33. naked classify [search string]
  34. The search string argument is optional. If you do not include a search string, the entire classifier list is displayed.
  35. SECONDARY COMMANDS
  36. none
  37. OPTIONS
  38. none
  39. EXAMPLES
  40. naked classify
  41. naked classify Internet
  42. """
  43. print(help_string)
  44. exit_success()
  45. if __name__ == '__main__':
  46. pass