import requests 
#software list API for "python"
r = requests.get("http://usesthis.com/api/v1/software/"+ input("Enter the name of a software product or web app:").lower())
#view the generated url, response status, and content-type
print(r.url + '\nstatus:' + str(r.status_code) + '\ncontent-type:' + r.headers['content-type'])

import json
#get json text
j = json.loads(r.text)
print(j)

#loop through interviews and store software titles in a list
software = []
#print('People that use python use:')
for i in j['gear']['interviews']:
    #print('\n' + i['name'])
    #do another request to the interview api to get each person's software
    r2 = requests.get("http://usesthis.com/api/v1/interviews/" + i['slug'])
    intvw = json.loads(r2.text)
    for s in intvw['interview']['gear']['software']:
        #print(s['name'], end=', ')
        software.append(s['name'])
from collections import Counter
counts = Counter(software)
#only get the items that are used by more than 4 people, and remove the python count since they all have it
#got this from here: http://stackoverflow.com/questions/4484690/how-to-filter-dictionary-in-python
counts_over4 = dict([(labels, values) for labels, values in counts.items() if values > 4 if labels != 'Python'])
#print(counts_over4)

#sort the list
from operator import itemgetter
#create a visual of the items that more than 2 people use
#got this from here: http://stackoverflow.com/questions/19198920/using-counter-in-python-to-build-histogram
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
labels, values = zip(*sorted(counts_over4.items(), key=itemgetter(1)))
indexes = np.arange(len(labels))
height = 0.25
plt.figure(num=1,figsize=(10,15))
plt.barh(indexes, values, height)
plt.yticks(indexes, labels, size='small')
plt.show()