def get_service_update_email_data(self, customer_id, service_id): session = Session(engine) customer_filters = {'customer_id': customer_id} service_filters = {'service_id': service_id} customer = self.clean_records( core.get(session, Customer, customer_filters))[0] service = self.clean_records( core.get(session, Service, service_filters))[0] session.close() return [Customer, Service]
def remove_subscription(self, customer_id, service_id): session = Session(engine) filters = {'customer_id': customer_id, 'service_id': service_id} try: status = core.delete(session, Subscription, filters) status['customer'] = self.clean_records( core.get(session, Customer, {'customer_id': customer_id}))[0] status['service'] = self.clean_records( core.get(session, Service, {'service_id': service_id}))[0] session.close() return status except Exception as e: return {'status': 'failure'}
def add_subscription(self, data): session = Session(engine) try: status = core.insert(session, Subscription, data) status['customer'] = self.clean_records( core.get(session, Customer, {'customer_id': data['customer_id']}))[0] status['service'] = self.clean_records( core.get(session, Service, {'service_id': data['service_id']}))[0] session.close() return status except Exception as e: traceback.print_exc() return {'status': 'failure'}
def __init__(self, host): self.host = host.replace("http://", "http://api.") self.account_id = self.ACCOUNT_ID self.db_actor = core.get(core.res['mysql'], feature="dbaccess") self.REST_CALL = RestClient() self.RPC_CALL = RpcClient()
def get(cls, identifier, **kwargs): version = kwargs.pop("version", config.API_VERSION) url = kwargs.pop("url", config.API_URL) key = kwargs.pop("key", config.API_KEY) secret = kwargs.pop("secret", config.API_SECRET) return cls(**core.get(cls._resource_, identifier, params=kwargs, version=version, url=url, key=key, secret=secret))
def get_on_base_url_catalog_digital_product(self, template): if template == "default": url = self.buy_link_with_one_digital_product_on_default_template() elif template == "one-column": url = self.buy_link_with_one_digital_product_on_one_column_template( ) browser = core.get(core.res['chrome'], feature="browser") browser.get_address(url)
def user_designers(user_id): result = core.get('user/%s/designers' % user_id) if result['paging']['total_pages'] > 1: raise NotImplemented('Cannot handle pages yet') if len(result['items']) != 1: raise NotImplemented('Cannot handle 0 or >1 designers yet') return result['items']
def __init__(self, host): self.host = host self.account_id = self.ACCOUNT_ID self.db_actor = core.get(core.res['mysql'], feature="dbaccess") self.merchant_code = self.db_actor.get_account_details( self.account_id, key_name="ClientCode") self.BUY_LINK = ApiBuilder() # self.merchant = self.MERCHANT self.digital_product_code = self.DIGITAL_PRODUCT self.physical_product_code = self.PHYSICAL_PRODUCT
def before_all(context): global CURRENT_CONFIG global resources config_file = context.config.userdata.get('profile', DEFAULT_CONFIG_PATH) if config_file != DEFAULT_CONFIG_PATH: config_file += "_config.yaml" CURRENT_CONFIG = load_custom_config(config_file) if 'resources' not in CURRENT_CONFIG: raise ValueError("Resources not given in yaml config file") resources = create_resources(CURRENT_CONFIG['resources']) core.res = dict(resources) context.browser = core.get(resources['chrome'], feature="browser") context.browser._res.open_browser_window(browser='chrome')
def __init__(self, account_id=41764): """Init method for APIClient kwargs: :account_id (int): The vendor's account id used for api calls """ self.account_id = account_id self.db_actor = core.get(core.res['mysql'], feature="dbaccess") self.secret_key = self.db_actor.get_account_details( self.account_id, key_name="IpnKey").encode() self.merchant_code = self.db_actor.get_account_details( self.account_id, key_name="ClientCode") self.headers = { "Content-Type": "application/json", "Accept": "application/json", }
def get_customer(self, contact_number=None, email=None): session = Session(engine) if email == None and contact_number == None: return { 'status': 'failure', 'message': 'no filter provided, please send either email or contact number' } elif contact_number != None: filters = {'contact_number': contact_number} else: filters = {'email': email} customer = self.clean_records(core.get(session, Customer, filters))[0] session.close() return customer
def set_x_avangate_auth_header(merchant_code, header_type): """Method to create X-Avangate-Authentication headers. args: :header_type (str): The API version to be used for testing. API(Default)|CONVERT_PLUS. :merchant_code (int): Vendor ID account. returns: An array contains X-Avangate-Authentication headers value. """ account_id = 41764 db_actor = core.get(core.res['mysql'], feature="dbaccess") key = db_actor.get_account_details(account_id, key_name="IpnKey").encode() date = strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) string = (str(len(merchant_code)) + merchant_code + str(len(date)) + date).encode() hash_key = hmac.new(key, string, hashlib.md5) if header_type is "API": header = { "Content-Type": "application/json", "Accept": "application/json", 'X-Avangate-Authentication': f'code="{merchant_code}" date="{date}" hash="{hash_key.hexdigest()}"', } return header elif header_type is "CONVERT_PLUS": header = { "Content-Type": "application/json", 'X-Avangate-Authentication': 'type="private" app="jscart" ver="1" ' 'hash="okA0htp1NARjq0irE37f2uOMnqwuH71subgn3AHjYrcncjxi2m2icCWHA4IO33nY"', } return header else: raise Exception( "Please select header. The two options are 'API' or 'CONVERT_PLUS'." )
def get_series_by_mature(self, matures): return core.get(self, Type.MOVIE, By.MATURE, mature)
def get_series_by_actor(self, actors): return core.get(self, Type.MOVIE, By.ACTOR, actors)
def get_series_by_genre(self, genres): return core.get(self, Type.MOVIE, By.GENRE, genres)
def get_series_by_id(self, ids): return core.get(self, Type.MOVIE, By.ID, ids)
def process(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None, failureLink=None): if core.SAFE_MODE and inputDirectory == core.NZB_DEFAULTDIR: logger.error( 'The input directory:[{0}] is the Default Download Directory. Please configure category directories to prevent processing of other media.' .format(inputDirectory)) return [-1, ""] if not download_id and clientAgent == 'sabnzbd': download_id = get_nzoid(inputName) if clientAgent != 'manual' and not core.DOWNLOADINFO: logger.debug( 'Adding NZB download info for directory {0} to database'.format( inputDirectory)) myDB = nzbToMediaDB.DBConnection() inputDirectory1 = inputDirectory inputName1 = inputName try: encoded, inputDirectory1 = CharReplace(inputDirectory) encoded, inputName1 = CharReplace(inputName) except: pass controlValueDict = {"input_directory": text_type(inputDirectory1)} newValueDict = { "input_name": text_type(inputName1), "input_hash": text_type(download_id), "input_id": text_type(download_id), "client_agent": text_type(clientAgent), "status": 0, "last_update": datetime.date.today().toordinal() } myDB.upsert("downloads", newValueDict, controlValueDict) # auto-detect section if inputCategory is None: inputCategory = 'UNCAT' usercat = inputCategory section = core.CFG.findsection(inputCategory).isenabled() if section is None: section = core.CFG.findsection("ALL").isenabled() if section is None: logger.error( 'Category:[{0}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' .format(inputCategory)) return [-1, ""] else: usercat = "ALL" if len(section) > 1: logger.error( 'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' .format(inputCategory, section.keys())) return [-1, ""] if section: sectionName = section.keys()[0] logger.info('Auto-detected SECTION:{0}'.format(sectionName)) else: logger.error( "Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!" .format(inputCategory)) return [-1, ""] cfg = dict(core.CFG[sectionName][usercat]) extract = int(cfg.get("extract", 0)) try: if int(cfg.get("remote_path")) and not core.REMOTEPATHS: logger.error( 'Remote Path is enabled for {0}:{1} but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!' .format(sectionName, inputCategory)) return [-1, ""] except: logger.error( 'Remote Path {0} is not valid for {1}:{2} Please set this to either 0 to disable or 1 to enable!' .format(core.get("remote_path"), sectionName, inputCategory)) inputName, inputDirectory = convert_to_ascii(inputName, inputDirectory) if extract == 1: logger.debug( 'Checking for archives to extract in directory: {0}'.format( inputDirectory)) extractFiles(inputDirectory) logger.info("Calling {0}:{1} to post-process:{2}".format( sectionName, inputCategory, inputName)) if sectionName == "CouchPotato": result = autoProcessMovie().process(sectionName, inputDirectory, inputName, status, clientAgent, download_id, inputCategory, failureLink) elif sectionName in ["SickBeard", "NzbDrone"]: result = autoProcessTV().processEpisode(sectionName, inputDirectory, inputName, status, clientAgent, download_id, inputCategory, failureLink) elif sectionName == "HeadPhones": result = autoProcessMusic().process(sectionName, inputDirectory, inputName, status, clientAgent, inputCategory) elif sectionName == "Mylar": result = autoProcessComics().processEpisode(sectionName, inputDirectory, inputName, status, clientAgent, inputCategory) elif sectionName == "Gamez": result = autoProcessGames().process(sectionName, inputDirectory, inputName, status, clientAgent, inputCategory) elif sectionName == 'UserScript': result = external_script(inputDirectory, inputName, inputCategory, section[usercat]) else: result = [-1, ""] plex_update(inputCategory) if result[0] == 0: if clientAgent != 'manual': # update download status in our DB update_downloadInfoStatus(inputName, 1) if sectionName not in ['UserScript', 'NzbDrone']: # cleanup our processing folders of any misc unwanted files and empty directories cleanDir(inputDirectory, sectionName, inputCategory) return result
def get_agent(self, email): session = Session(engine) filters = {'email': email} agent = self.clean_records(core.get(session, Agent, filters))[0] session.close() return agent
def startproc(inputDirectory, inputName=None, status=0, clientAgent='manual', download_id=None, inputCategory=None, failureLink=None): if core.SAFE_MODE and inputDirectory == core.NZB_DEFAULTDIR: logger.error( 'The input directory:[{0}] is the Default Download Directory. Please configure category directories to prevent processing of other media.' .format(inputDirectory)) return [-1, ""] if not download_id and clientAgent == 'sabnzbd': download_id = get_nzoid(inputName) if clientAgent != 'manual' and not core.DOWNLOADINFO: logger.debug( 'Adding NZB download info for directory {0} to database'.format( inputDirectory)) myDB = nzbToMediaDB.DBConnection() inputDirectory1 = inputDirectory inputName1 = inputName try: encoded, inputDirectory1 = CharReplace(inputDirectory) encoded, inputName1 = CharReplace(inputName) except: pass controlValueDict = {"input_directory": text_type(inputDirectory1)} newValueDict = { "input_name": text_type(inputName1), "input_hash": text_type(download_id), "input_id": text_type(download_id), "client_agent": text_type(clientAgent), "status": 0, "last_update": datetime.date.today().toordinal() } myDB.upsert("downloads", newValueDict, controlValueDict) # auto-detect section if inputCategory is None: inputCategory = 'UNCAT' usercat = inputCategory section = core.CFG.findsection(inputCategory).isenabled() if section is None: section = core.CFG.findsection("ALL").isenabled() if section is None: logger.error( 'Category:[{0}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.' .format(inputCategory)) return [-1, ""] else: usercat = "ALL" if len(section) > 1: logger.error( 'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.' .format(inputCategory, section.keys())) return [-1, ""] if section: sectionName = section.keys()[0] logger.info('Auto-detected SECTION:{0}'.format(sectionName)) else: logger.error( "Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!" .format(inputCategory)) return [-1, ""] cfg = dict(core.CFG[sectionName][usercat]) extract = int(cfg.get("extract", 0)) try: if int(cfg.get("remote_path")) and not core.REMOTEPATHS: logger.error( 'Remote Path is enabled for {0}:{1} but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!' .format(sectionName, inputCategory)) return [-1, ""] except: logger.error( 'Remote Path {0} is not valid for {1}:{2} Please set this to either 0 to disable or 1 to enable!' .format(core.get("remote_path"), sectionName, inputCategory)) inputName, inputDirectory = convert_to_ascii(inputName, inputDirectory) if extract == 1: logger.debug( 'Checking for archives to extract in directory: {0}'.format( inputDirectory)) extractFiles(inputDirectory) logger.info("Calling Checker to check the Files and Convert them to mp4") result = Filechecker().checkfiles(sectionName, inputDirectory, inputName, status, clientAgent, download_id, inputCategory, failureLink) return result
def get_series_by_rating(self, ratings): return core.get(self, Type.MOVIE, By.ratings, ratings)
def get_all_services(self): session = Session(engine) records = self.clean_records(core.get(session, Service)) session.close() return records
def user_games(user_id): result = core.get('user/%s/games' % user_id) if result['paging']['total_pages'] > 1: raise NotImplemented('Cannot handle pages yet') return result['items']
def process(input_directory, input_name=None, status=0, client_agent='manual', download_id=None, input_category=None, failure_link=None): if core.SAFE_MODE and input_directory == core.NZB_DEFAULTDIR: logger.error( 'The input directory:[{0}] is the Default Download Directory. Please configure category directories to prevent processing of other media.'.format( input_directory)) return ProcessResult( message='', status_code=-1, ) if not download_id and client_agent == 'sabnzbd': download_id = get_nzoid(input_name) if client_agent != 'manual' and not core.DOWNLOADINFO: logger.debug('Adding NZB download info for directory {0} to database'.format(input_directory)) my_db = main_db.DBConnection() input_directory1 = input_directory input_name1 = input_name try: encoded, input_directory1 = char_replace(input_directory) encoded, input_name1 = char_replace(input_name) except Exception: pass control_value_dict = {'input_directory': text_type(input_directory1)} new_value_dict = { 'input_name': text_type(input_name1), 'input_hash': text_type(download_id), 'input_id': text_type(download_id), 'client_agent': text_type(client_agent), 'status': 0, 'last_update': datetime.date.today().toordinal(), } my_db.upsert('downloads', new_value_dict, control_value_dict) # auto-detect section if input_category is None: input_category = 'UNCAT' usercat = input_category section = core.CFG.findsection(input_category).isenabled() if section is None: section = core.CFG.findsection('ALL').isenabled() if section is None: logger.error( 'Category:[{0}] is not defined or is not enabled. Please rename it or ensure it is enabled for the appropriate section in your autoProcessMedia.cfg and try again.'.format( input_category)) return ProcessResult( message='', status_code=-1, ) else: usercat = 'ALL' if len(section) > 1: logger.error( 'Category:[{0}] is not unique, {1} are using it. Please rename it or disable all other sections using the same category name in your autoProcessMedia.cfg and try again.'.format( input_category, section.keys())) return ProcessResult( message='', status_code=-1, ) if section: section_name = section.keys()[0] logger.info('Auto-detected SECTION:{0}'.format(section_name)) else: logger.error('Unable to locate a section with subsection:{0} enabled in your autoProcessMedia.cfg, exiting!'.format( input_category)) return ProcessResult( status_code=-1, message='', ) cfg = dict(core.CFG[section_name][usercat]) extract = int(cfg.get('extract', 0)) try: if int(cfg.get('remote_path')) and not core.REMOTEPATHS: logger.error('Remote Path is enabled for {0}:{1} but no Network mount points are defined. Please check your autoProcessMedia.cfg, exiting!'.format( section_name, input_category)) return ProcessResult( status_code=-1, message='', ) except Exception: logger.error('Remote Path {0} is not valid for {1}:{2} Please set this to either 0 to disable or 1 to enable!'.format( core.get('remote_path'), section_name, input_category)) input_name, input_directory = convert_to_ascii(input_name, input_directory) if extract == 1: logger.debug('Checking for archives to extract in directory: {0}'.format(input_directory)) extract_files(input_directory) logger.info('Calling {0}:{1} to post-process:{2}'.format(section_name, input_category, input_name)) if section_name in ['CouchPotato', 'Radarr']: result = movies.process(section_name, input_directory, input_name, status, client_agent, download_id, input_category, failure_link) elif section_name in ['SickBeard', 'NzbDrone', 'Sonarr']: result = tv.process(section_name, input_directory, input_name, status, client_agent, download_id, input_category, failure_link) elif section_name in ['HeadPhones', 'Lidarr']: result = music.process(section_name, input_directory, input_name, status, client_agent, input_category) elif section_name == 'Mylar': result = comics.process(section_name, input_directory, input_name, status, client_agent, input_category) elif section_name == 'Gamez': result = games.process(section_name, input_directory, input_name, status, client_agent, input_category) elif section_name == 'UserScript': result = external_script(input_directory, input_name, input_category, section[usercat]) else: result = ProcessResult( message='', status_code=-1, ) plex_update(input_category) if result.status_code == 0: if client_agent != 'manual': # update download status in our DB update_download_info_status(input_name, 1) if section_name not in ['UserScript', 'NzbDrone', 'Sonarr', 'Radarr', 'Lidarr']: # cleanup our processing folders of any misc unwanted files and empty directories clean_dir(input_directory, section_name, input_category) return result
def __init__(self, host): self.host = host self.driver = core.get(core.res['chrome'], feature="browser")._res.driver.webdriver
def get_subscription(self, customer_id): session = Session(engine) filters = {'customer_id': customer_id} records = self.clean_records(core.get(session, Subscription, filters)) session.close() return records
def after_scenario(context, scenario): context.browser = core.get(resources['chrome'], feature="browser") if scenario.status == "failed": context.browser._res.screenshot( f"/{scenario.name}_{time.strftime('%d-%m-%Y_%H-%M-%S')}.png") context.browser._res.restart_driver()
#!/usr/bin/env python import nose, core, time from nose.plugins.attrib import attr from common.operations import * from common.homepage import * from core import get, browserType from selenium import webdriver from selenium.webdriver.common.keys import Keys import selenium.webdriver.support.ui as ui data = get() urls = get(r'common\urls.config') driver = browserType(data['browser']) login(driver, urls.home, data.user, data.password) wait = ui.WebDriverWait(driver, 10) wait.until(driver.find_element_by_id('topRightLinks')) driver.close()