def fake_session(): session = Session() screenshots = load_all_screenshots( Paths.shots_dir ) screenshots.sort( key=operator.attrgetter('time') ) session_shots = screenshots[-100:] start_time = session_shots[0].time-1 end_time = session_shots[-1].time+1 session.start = start_time session.end = end_time api.create_session( session ) api.start_session( session ) map( upload_shot, session_shots ) api.end_session( session )
def stock_stores(conn, some_bar, window, some_label, some_queue): # TODO: This is a seam canceled = False count = 0 time_to_install = time.time() store_dict = stores.stores() # {'some_store':[1,2,3,4,5]} Used to tell which items in which stores - ints are ids url = api.construct_api_url('equipment') s = api.create_session() response = api.call_api(url, s) response_dict = api.get_api_all(response) usable_dict = api.get_nested_api_dict(response_dict, 'results') # [{'name': 'some_name', 'url': 'some_url'}] # TODO: This is a seam for dic in usable_dict: temp = {} # TODO: Make sure to do with conn: around phases instead of each sql statement. Will require need execute_sql. for key, value in dic.items(): # TODO: First thing will always be to slice ID off url via regex and add to dictionary as 'index' # TODO: Then add item name, url and index to temp dictionary for DB insertion if not temp: # If temp dictionary is empty temp['item'] = value # add value with key 'item' else: temp['api'] = value # add value with key 'api' # TODO: This will be a pool of API calls, post phase1 DB insertion item_value = api.get_item_value(temp['item'], character.Character.list_of_item_dicts, s) temp['currency'] = item_value # TODO: This should be done prior to phase1 DB insertion. if value[0:37] == url: # if one of those values beings with a url like string num = api.regex(value, 'equipment/') # slices number off url and captures as variable # This logic compares the captured number to the numbers in the dict imported earlier # Then it adds a 'store':'some_store' key:value to the temp dictionary if num in store_dict['GS']: temp['store'] = 'General Store' elif num in store_dict['BS']: temp['store'] = 'Blacksmith' elif num in store_dict['Ship']: temp['store'] = 'Shipyard' elif num in store_dict['Stables']: temp['store'] = 'Stables' else: temp['store'] = 'No Store' # TODO: This will be phase2 DB insertion. Inserting the item values where index # TODO: add_store_item will need to be reworked, and, most likely, split into multiple functions # adds an item to a store table based on information stored in dictionary database.add_store_item(conn, sql.add_store_item(), temp) count += 1 print(count) # TODO: Change this to a Daemon thread to avoid having to do this cancel workaround if not some_queue.empty(): canceled = some_queue.get() update_mainloop(some_bar, count, some_label, window, canceled) print('done in: ', time.time() - time_to_install) print('Done with everything.')
#get the exe path, which is the absolute path to the parent directory of the module's direcotry exe_path = os.path.dirname(os.path.abspath(__file__)) exe_path = exe_path[:-1] if exe_path[len(exe_path) - 1] == '/' else exe_path exe_path = exe_path[:exe_path.rfind('/') + 1] #add module lookup paths to sys.path so that import can find them #we are inserting at the begining of sys.path so that we can be sure that we are importing the right module sys.path.insert(0, exe_path + 'lib/websocket_client') sys.path.insert(0, exe_path + 'src') sys.path.insert(0, exe_path + 'lib') #to avoid the bug reported at http://bugs.python.org/issue13684 we use a stable httplib version available with CPython 2.7.3 and 3.2.3 #since httplib has been renamed to http, we have to add that also in the path so that import can find it if sys.version_info[0] == 3: sys.path.insert(0, exe_path + 'lib/httplib') import exit_status try: #it is possible that the agent was removed from the UI, in that case it already had removed config files. so import api can raise an exception import api api.create_session() except: sys.exit(exit_status.AGENT_ERR_SUCCESS ) #any exception should be considered as success api.session.ping( ) #required to set the post event, as the post event is set only after auth status = api.session.unregister() #unregister the agent sys.exit(exit_status.AGENT_ERR_SUCCESS if api.is_not_connected(status) == False else exit_status.AGENT_ERR_FAILED_CONNECT)
import sys #get the exe path, which is the absolute path to the parent directory of the module's direcotry exe_path = os.path.dirname(os.path.abspath(__file__)) exe_path = exe_path[:-1] if exe_path[len(exe_path) - 1] == '/' else exe_path exe_path = exe_path[:exe_path.rfind('/') + 1] #add module lookup paths to sys.path so that import can find them #we are inserting at the begining of sys.path so that we can be sure that we are importing the right module sys.path.insert(0, exe_path + 'lib/websocket_client') sys.path.insert(0, exe_path + 'src') sys.path.insert(0, exe_path + 'lib') #to avoid the bug reported at http://bugs.python.org/issue13684 we use a stable httplib version available with CPython 2.7.3 and 3.2.3 #since httplib has been renamed to http, we have to add that also in the path so that import can find it if sys.version_info[0] == 3: sys.path.insert(0, exe_path + 'lib/httplib') import exit_status try: #it is possible that the agent was removed from the UI, in that case it already had removed config files. so import api can raise an exception import api api.create_session() except: sys.exit(exit_status.AGENT_ERR_SUCCESS) #any exception should be considered as success api.session.ping() #required to set the post event, as the post event is set only after auth status = api.session.unregister() #unregister the agent sys.exit(exit_status.AGENT_ERR_SUCCESS if api.is_not_connected(status) == False else exit_status.AGENT_ERR_FAILED_CONNECT)