def download_snapeda_images(snapeda_data: dict) -> dict: ''' Download symbol and footprint images from SnapEDA's server ''' images = { 'symbol': None, 'footprint': None, } try: if snapeda_data['symbol_image']: # Form path image_name = f'{snapeda_data["part_number"].lower()}_symbol.png' image_location = settings.search_images + image_name # Download symbol image symbol = download_image(snapeda_data['symbol_image'], image_location) if symbol: images['symbol'] = image_location except KeyError: pass try: if snapeda_data['footprint_image']: # Form path image_name = f'{snapeda_data["part_number"].lower()}_footprint.png' image_location = settings.search_images + image_name # Download symbol image footprint = download_image(snapeda_data['footprint_image'], image_location) if footprint: images['footprint'] = image_location except KeyError: pass return images
def upload_part_image(image_url: str, part_id: int) -> bool: ''' Upload InvenTree part thumbnail''' global inventree_api # Get image full path image_name = f'{str(part_id)}_thumbnail.jpeg' image_location = settings.search_images + image_name # Download image (multiple attempts) if not download_image(image_url, image_location): return False # Upload image to InvenTree part = Part(inventree_api, part_id) if part: return part.upload_image(image=image_location) else: return False
categories = {'Capacitors': {'Super': 'Super'}} add_category = config_interface.add_supplier_category( categories, settings.CONFIG_DIGIKEY_CATEGORIES) if not add_category: method_results = False # Synchronize InvenTree and Supplier categories sync_categories = config_interface.sync_inventree_supplier_categories( inventree_config_path=settings.CONFIG_CATEGORIES, supplier_config_path=settings.CONFIG_DIGIKEY_CATEGORIES) if not sync_categories: method_results = False # Test SnapEDA API methods snapeda_success = test_snapeda_api() if not snapeda_success: method_results = False # Test download_image failure modes if download_image('', '', silent=True) or download_image( 'http', '', silent=True): method_results = False if not method_results: cprint('[ FAIL ]') exit_code = -1 else: cprint(f'[ PASS ]') sys.exit(exit_code)