def aggregate(data) -> list: result = {} for line in tqdm(data): user_name = line['フルネーム'] user_id = line['Q00_Aizu Online Judgeのアカウント名'] user_id = user_id.split('/')[-1] if '/' in user_id else user_id user_id = user_id.split('=')[-1] if '=' in user_id else user_id accepted = aggregator.main(user_id) result[user_name] = accepted return result
def main(): markets = stockmarket.main() aggr = aggregator.main(markets) viewer.main(aggr) print("\nPress enter to quit.\n") input()
def main(duration): # Fetch all active workstations in the past 30 days from aggregator workstations_from_tool_aggregator, jamf_devices_with_serial_numbers = aggregator.main( duration) # Push all workstations to service now cmdb if workstations_from_tool_aggregator: # Get all workstation from Computers table total_count = active_workstations_service_now.get_assets_total() if int(total_count) > 0: workstations_from_service_now = active_workstations_service_now.fetch_categorized_workstations( total_count, jamf_devices_with_serial_numbers) records_that_need_to_be_updated = [] records_that_need_to_be_created = [] logger.info( 'Checking if devices from aggregator are present in service now table or not' ) with concurrent.futures.ThreadPoolExecutor( max_workers=MAX_THREADS) as executor: for asset, status in zip( workstations_from_tool_aggregator.keys(), executor.map( lambda asset: divide_devices_based_on_insert_or_update( asset, workstations_from_service_now.keys()), workstations_from_tool_aggregator.keys())): if status[0]: records_that_need_to_be_updated.append(asset) if status[1]: records_that_need_to_be_created.append(asset) # A list of service now devices that need to be updated devices_that_need_to_be_updated = [] if records_that_need_to_be_updated: logger.info( 'Checking if the device actually needs to be modified in service now table' ) with concurrent.futures.ThreadPoolExecutor( max_workers=MAX_THREADS) as executor: for update_needed, snowobj in executor.map( lambda asset: update_service_now_workstation( workstations_from_service_now[asset], workstations_from_tool_aggregator[asset]), records_that_need_to_be_updated): if update_needed: devices_that_need_to_be_updated.append(snowobj) # A list of devices that need to be created in Service Now if records_that_need_to_be_created: logger.info("Devices that need to be added to the table: %d" % len(records_that_need_to_be_created)) with concurrent.futures.ThreadPoolExecutor( max_workers=MAX_THREADS) as executor: for asset in records_that_need_to_be_created: executor.submit( active_workstations_service_now.insert_asset_data, workstations_from_tool_aggregator[asset]) if devices_that_need_to_be_updated: logger.info( "Devices that need to be modified in the table: %d" % len(devices_that_need_to_be_updated)) with concurrent.futures.ThreadPoolExecutor( max_workers=MAX_THREADS) as executor: for asset in devices_that_need_to_be_updated: executor.submit( active_workstations_service_now.update_asset_data, asset) else: # Create new devices in service now from all devices in the aggregator logger.info( "Active Workstations is completely empty. Filling up the devices from the aggregator" ) logger.info("Devices that need to be added to the table: %d" % len(workstations_from_tool_aggregator)) with concurrent.futures.ThreadPoolExecutor( max_workers=MAX_THREADS) as executor: for asset in workstations_from_tool_aggregator.keys(): executor.submit( active_workstations_service_now.insert_asset_data, workstations_from_tool_aggregator[asset]) # Cross check if all deivces were created total_count = active_workstations_service_now.get_assets_total() if int(total_count) == len(workstations_from_tool_aggregator): logger.info('Completed adding all devices into the table') else: logger.info('Devices skipped while adding to table: %d' % (len(workstations_from_tool_aggregator) - int(total_count)))
def run_aggregator(): aggregator.main()
import aggregator if __name__ == "__main__": aggregator.main()