@hook.command('octopart', 'octo')
def octopart(text, reply):
 if (not api_key):
  return 'Octopart API key required.'
 params = {'apikey': api_key, 'q': text, 'start': 0, 'limit': 1}
 try:
  request = requests.get(API_URL, params=params)
  request.raise_for_status()
 except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
  return 'Could not fetch part data: {}'.format(e)
 response = request.json()
 if (not response['results']):
  return 'No results.'
 results = response['results']
 for result in results:
  part = result['item']
  reply('{} - {} - {}'.format(part['brand']['name'], part['mpn'], part['octopart_url']))

@ hook . command ( 'octopart' , 'octo' ) def octopart ( text , reply ) : if ( not api_key ) : return 'Octopart API key required.' params = { 'apikey' : api_key , 'q' : text , 'start' : 0 , 'limit' : 1 } try : request = requests . get ( API_URL , params = params ) request . raise_for_status ( ) except ( requests . exceptions . HTTPError , requests . exceptions . ConnectionError ) as e : return 'Could not fetch part data: {}' . format ( e ) response = request . json ( ) if ( not response [ 'results' ] ) : return 'No results.' results = response [ 'results' ] for result in results : part = result [ 'item' ] reply ( '{} - {} - {}' . format ( part [ 'brand' ] [ 'name' ] , part [ 'mpn' ] , part [ 'octopart_url' ] ) )
octopart <keyword> -- search for any part on the octopart database .