def properties_check(server, info, config_list): try: from jproperties import Properties p_list = Properties() with open(properties_path, "rb") as f: p_list.load(f) server.tell( info.player, system_return + "§eServer's §aport§r is §d[" + str(p_list.get('server-port').data) + ']§r') server.tell( info.player, system_return + "§eMCDR's§r §arcon port§r is §d[" + str(config_list['rcon_port']) + ']§r') server.tell( info.player, system_return + "§eServer's§r §arcon port§r is §d[" + str(p_list.get('rcon.port').data) + ']§r') if str(p_list.get('rcon.port').data) == str(config_list['rcon_port']): server.tell(info.player, system_return + '§aRcon port§r are §bsame') else: error_msg(server, info.player, 1) if p_list.get('rcon.password').data == config_list['rcon_password']: server.tell(info.player, system_return + '§aRcon password§r are §bsame') else: error_msg(server, info.player, 2) except ModuleNotFoundError: error_msg(server, info.player, 3)
def getProp(): configs = Properties() with open('fire.properties', 'rb') as config_file: configs.load(config_file) print('Service properties') print(configs.get("service_type")) print(configs.get("service_name")) print(configs.get("service_description")) print(configs.get("service_port"))
def paymentProperties(): configs = Properties() with open('payment.properties', 'rb') as config_file: configs.load(config_file) print('Service properties') print(configs.get("payment_service_type")) print(configs.get("payment_service_name")) print(configs.get("payment_service_description")) print(configs.get("payment_service_port"))
def read_config(): global HOST, PORT config = Properties() with open('config.env', 'rb') as config_file: config.load(config_file) HOST = config.get("SOCKET_HOST").data PORT = int(config.get("SOCKET_PORT").data) ENCODING = config.get("ENCODING").data
def get_connection(): properties = Properties() with open("environment.properties", "rb") as f: properties.load(f, "utf-8") return psycopg2.connect(host=properties.get('HOST').data, port=int(properties.get('PORT').data), database=properties.get('DATABASE').data, user=properties.get('USER').data, password=properties.get('PASSWORD').data)
def read_config(): global EMAIL_LOGIN, EMAIL_PASSWORD, IMAP_HOST, IMAP_PORT, PERIOD_CHECK config = Properties() with open('config.env', 'rb') as config_file: config.load(config_file) EMAIL_LOGIN = config.get("EMAIL_LOGIN").data EMAIL_PASSWORD = config.get("EMAIL_PASSWORD").data IMAP_HOST = config.get("IMAP_HOST").data IMAP_PORT = int(config.get("IMAP_PORT").data) PERIOD_CHECK = int(config.get("PERIOD_CHECK").data)
def getChromeDriver(self): if WebDriver.__instance == None: print("creating new driver") options = webdriver.ChromeOptions() prop = Properties() with open('resources/properties/config.properties', 'rb') as config_file: prop.load(config_file) print(prop.get("ENV")) print(platform.system()) if platform.system() == 'Linux': options.add_argument('--no-sandbox') options.add_argument('headless') options.add_argument('window-size=1200x600') options.add_argument('--disable-dev-shm-usage') self.driver = webdriver.Chrome( executable_path='resources/drivers/chromedriver-linux', chrome_options=options) elif platform.system() == 'Darwin': self.driver = webdriver.Chrome( executable_path='resources/drivers/chromedriver-84', chrome_options=options) else: self.driver = webdriver.Chrome( executable_path='resources/drivers/chromedriver.exe', chrome_options=options) self.driver.maximize_window() self.driver.implicitly_wait(5) else: print("using existing driver") return self.driver
def start_browser(): configs = Properties() configs.load(open(os.path.join(PROJECT_ROOT, 'app.properties'), 'rb')) browser_name = configs.get("browser").data option = webdriver.ChromeOptions() option.add_argument('--no-sandbox') option.add_argument('--disable-gpu') option.add_argument('--window-size=1920,1080') option.add_argument('lang=ru') if browser_name == 'Chrome': driver = webdriver.Chrome( executable_path=CHROME_DRIVER_DICT[sys.platform], options=option) elif browser_name == 'Opera': driver = webdriver.Opera( executable_path=OPERA_DRIVER_DICT[sys.platform], options=option) elif browser_name == 'Yandex': driver = webdriver.Opera( executable_path=YANDEX_DRIVER_DICT[sys.platform], options=option) else: driver = webdriver.Chrome( executable_path=CHROME_DRIVER_DICT[sys.platform], options=option) yield driver if sys.exc_info(): allure.attach(body=driver.get_screenshot_as_png(), name='screenshot', attachment_type=AttachmentType.PNG) driver.quit()
def parse_and_store__artifact_display_name(): for dir_path in software_directory_paths: language_path = SOFTWARES_PATH + dir_path + ARTIFACTS_LANG_PATH file_names = [] for (dirpath, dirnames, filenames) in walk(language_path): file_names.extend(filenames) break for file_name in file_names: if (not file_name.endswith('_en_US.properties')) and ( not file_name.endswith('locale.properties')): continue configs = Properties() path = SOFTWARES_PATH + dir_path + ARTIFACTS_LANG_PATH + file_name # print("Artifact lang :path",path) with open(path, 'rb') as read_prop: configs.load(read_prop) prop_view = configs.items() for item in prop_view: if len(item[0].split('.')) > 1 and item[0].split( '.')[1] == 'displayName': display_name = configs.get(item[0]).data artifact_id = item[0].split('.')[0].lower() artifact_object[artifact_id] = Artifact( artifact_id, display_name)
def parse_and_store__component_display_name(): for dir_path in software_directory_paths: language_path = SOFTWARES_PATH + dir_path + COMPONENTS_LANG_PATH file_names = [] for (dirpath, dirnames, filenames) in walk(language_path): file_names.extend(filenames) break for file_name in file_names: if (not file_name.endswith('_en_US.properties')) and ( not file_name.endswith('locale.properties')): continue configs = Properties() path = SOFTWARES_PATH + dir_path + COMPONENTS_LANG_PATH + file_name with open(path, 'rb') as read_prop: configs.load(read_prop) prop_view = configs.items() #print(type(prop_view)) for item in prop_view: #print(item) if len(item[0].split('.')) > 1 and item[0].split( '.')[1] == 'displayName' and item[0].split( '.')[0] in component_object: display_name = configs.get(item[0]).data component_id = item[0].split('.')[0] component_object[component_id].set_component_display_name( display_name)
def get_endpoint_url(account_id): """returns the API endpoint by concatenating the base url and account_id Parameters: account_id (string) returns: string: endpoint url """ request_url='' if account_id: configs = Properties() with open('app-config.properties', 'rb') as config_file: configs.load(config_file) request_url = configs.get("REQUEST_URL").data.strip() # check for API url if request_url: return request_url + str(account_id).strip() else: raise ValueError ("Endpoint url cannot be None") else: raise ValueError ("account id cannot be None")
class Settings: def __init__(self, filename): self._file_data = Properties() self._filename = filename self._load_data() @property def get_apples(self): return self._file_data.get("apple_numbers").data[1:-1] @property def get_dimension(self): return self._file_data.get("board_dimension").data[1:-1] def _load_data(self): with open(self._filename, 'rb') as files: self._file_data.load(files)
def getconfigdata(propertyname): log = Logger.getlogger() try: configs = Properties() with open(path, 'rb') as config_file: configs.load(config_file) return configs.get(propertyname).data except Exception as e: log.exception("Exception Occurred", exc_info=True)
def getFavorites(): configs = Properties() try: with open('config/config.ini', 'rb') as config_file: configs.load(config_file) my_list = configs.get("favorites").data.replace(" ", "").split(',') return my_list except: return ['Biot', 'Eysines', 'Ustaritz']
class Prop(object): def __init__(self): self.root = '/Users/muks/Scandic/code/python_projects/plp/' self.config = Properties() with open(f'{self.root}/app-config.properties', 'rb') as config_file: self.config.load(config_file) def get_prop(self, key: str) -> str: return self.config.get(key).data
class __ConfParams: configs = None def __init__(self): self.configs = Properties() with open('app-config.properties', 'rb') as config_file: self.configs.load(config_file) def getParam(self, name): return self.configs.get(name).data
class GenericLib: def get_data_from_properties(self, file_path, key): self.prop = Properties() with open(file_path, 'rb') as config_file: self.prop.load(config_file, 'utf-8') return self.prop.get(key).data def move_and_hover(self, driver, locator, value): action = ActionChains(driver) action.move_to_element(driver.find_element(locator, value)).perform() def move_and_click_by_offset(self, driver, locator, value, xoffset, yoffset): action = ActionChains(driver) action.move_to_element(driver.find_element( locator, value)).move_by_offset(xoffset, yoffset).click().perform() def scroll_to_end(self, driver): driver.execute_script( 'window.scrollTo(0, document.body.scrollHeight);') def scroll_to_element(self, driver, element): driver.execute_script('arguments[0].scrollIntoView(true);', element) def batch_cleanup(self): FILE_PATH_WINDOWS = os.getcwd() + '/batches/process_kill_windows.bat' FILE_PATH_UNIX = os.getcwd() + '/batches/process_kill_unix.sh' # platform.system() = Linux: Linux / Mac: Darwin / Windows: Windows if platform.system() == 'Windows': subprocess.call(['cmd.exe', '/c', FILE_PATH_WINDOWS]) else: if os.access(FILE_PATH_UNIX, os.X_OK): os.chmod(FILE_PATH_UNIX, 0o777) subprocess.call(['sh', '-p', FILE_PATH_UNIX]) def wait_for_download_to_complete(self, download_dir, target_file_regex, max_secs_to_wait): secs_elapsed = 0 while True: list = glob.glob(download_dir + target_file_regex) time.sleep(1) secs_elapsed += 1 if len(list) > 0 or secs_elapsed == max_secs_to_wait: break return secs_elapsed
def read_config(): global HOST, PORT, ENCODING, EMAIL_LOGIN, EMAIL_PASSWORD, SMTP_HOST, SMTP_PORT config = Properties() with open('config.env', 'rb') as config_file: config.load(config_file) HOST = config.get("SOCKET_HOST").data PORT = int(config.get("SOCKET_PORT").data) ENCODING = config.get("ENCODING").data EMAIL_LOGIN = config.get("EMAIL_LOGIN").data EMAIL_PASSWORD = config.get("EMAIL_PASSWORD").data SMTP_HOST = config.get("SMTP_HOST").data SMTP_PORT = int(config.get("SMTP_PORT").data)
class PropertiesLoader: def __init__(self,logger): self.configs = Properties() self.logger = logger def loadProperties(self,propertiesFileName): with open(propertiesFileName, 'rb') as config_file: self.configs.load(config_file) self.logger.info("Properties file " + str(propertiesFileName) + "has been loaded to the code") #get the property name. return structure of tuple, getting the property name from data field def getProperty(self,propertyName): try: result = self.configs.get(propertyName).data return result except KeyError as ke: self.logger.error("the property has not found: ",ke)
def start_browser(): configs = Properties() configs.load(open(os.path.join(PROJECT_ROOT, 'app.properties'), 'rb')) browser_name = configs.get("browser").data options = webdriver.ChromeOptions() options.add_argument('--no-sandbox') options.add_argument('--disable-gpu') options.add_argument('--window-size=1920,1080') options.add_argument('lang=ru') if browser_name == "chrome": driver = webdriver.Chrome( executable_path=CHROME_DRIVER_DICT[sys.platform], options=options) elif browser_name == "opera": driver = webdriver.Opera( executable_path=OPERA_DRIVER_DICT[sys.platform], options=options) driver.maximize_window() elif browser_name == "yandex": driver = webdriver.Opera( executable_path=YANDEX_DRIVER_DICT[sys.platform], options=options) driver.maximize_window() else: driver = webdriver.Chrome( executable_path=CHROME_DRIVER_DICT[sys.platform], options=options) listener = LoggedListener() driver = EventFiringWebDriver(driver=driver, event_listener=listener) yield driver if sys.exc_info(): allure.attach(body=driver.get_screenshot_as_png(), name='screenshot', attachment_type=AttachmentType.PNG) driver.quit()
def loadProps(param): from jproperties import Properties configs = Properties() with open('config.properties', 'rb') as config_file: configs.load(config_file) return int(configs.get(param).data)
import os from jproperties import Properties configs = Properties() with open('app-config.properties', 'rb') as config_file: configs.load(config_file) os.environ["DB_USER"] = configs.get("DB_USER").data os.environ["DB_PASS"] = configs.get("DB_PASS").data os.environ["DB_NAME"] = configs.get("DB_NAME").data os.environ["DB_HOST"] = configs.get("DB_HOST").data os.environ["TOKEN"] = configs.get("TOKEN").data os.environ["CHAT_ID"] = configs.get("CHAT_ID").data os.environ['ADMIN_CHAT_ID'] = configs.get("ADMIN_CHAT_ID").data os.environ['URL'] = configs.get("URL").data print('test local before execution') if __name__ == '__main__': from bot import * import threading # recording_on = Value('b', True) print('testlocal file execution started') p = threading.Thread(target=localpoll, args=(cbot, )) p.start() userids.add(int(ADMIN_CHAT_ID)) # print("running app") # server.run(threaded=True) # p.join()
from jproperties import Properties config = Properties() file_obj = codecs.open( 'C:\\Users\\Vignesh\\Cucumber_AutomationBytes\\Booking\\Config.Properties', 'rb') with open( 'C:\\Users\\Vignesh\\Cucumber_AutomationBytes\\Booking\\Config.Properties', 'rb') as config_file: config.load(config_file) print(config.get("user")) items_view = config.items() for item in items_view: print(item[0], '=', item[1].data)
import os import connexion from jproperties import Properties from flask_sqlalchemy import SQLAlchemy from flask_marshmallow import Marshmallow basedir = os.path.abspath(os.path.dirname(__file__)) configsProperty = Properties() with open('config.properties', 'rb') as config_file: configsProperty.load(config_file) # Create the connexion application instance connex_app = connexion.App(__name__, specification_dir=basedir) # Get the underlying Flask app instance app = connex_app.app app.config["template_folder"] = "templates" # Configure the SqlAlchemy part of the app instance app.config["SQLALCHEMY_ECHO"] = True app.config["SQLALCHEMY_DATABASE_URI"] = configsProperty.get( "SQLALCHEMY_DATABASE_URI").data app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True # Create the SqlAlchemy db instance db = SQLAlchemy(app) # Initialize Marshmallow ma = Marshmallow(app)
print(f"Message: {e.get_message()}") def on_service_interrupted(self, e: "ServiceEvent"): print("\non_service_interrupted") print(f"Error cause: {e.get_cause()}") print(f"Message: {e.get_message()}") # Broker Config. Note: Could pass other properties Look into solace_configs = Properties() with open('solace.properties', 'rb') as read_prop: solace_configs.load(read_prop) broker_props = { "solace.messaging.transport.host": solace_configs.get("SOLACE_HOST").data, "solace.messaging.service.vpn-name": solace_configs.get('SOLACE_VPN').data, "solace.messaging.authentication.scheme.basic.username": solace_configs.get("SOLACE_USERNAME").data, "solace.messaging.authentication.scheme.basic.password": solace_configs.get("SOLACE_PASSWORD").data } # Handle received messages class MessageHandlerImpl(MessageHandler): def on_message(self, message: InboundMessage): payload_str = message.get_payload_as_string() #print("\n" + f"Message Payload String: {payload_str} \n")
def scraping_job(): target_resource = props.get("targetResource").data if target_resource == "tutBy": region_code = props.get("tutBy.cityCode").data target_job = props.get("tutBy.targetJob").data tutBySkillsInfo(region_code, target_job) else: if target_resource == "indeed": city = props.get("indeed.city").data state = props.get("indeed.state").data target_job = props.get("indeed.targetJob").data skills_info(city, state, target_job) start_time = props.get("system.startTime").data schedule.every().day.at(str(start_time)).do(scraping_job) while True: schedule.run_pending() # Right now we are searching for data scientist jod, it's hardcoded for now in functions. # skills_info() takes city name and state code like on indeed.com # tutBySkillsInfo() takes region id from jobs.tut.by. # 16 - Belarus # 1002 - Minsk # 1003 - Gomel # 1005 - Vitebsk # 1007 - Brest # 1006 - Hrodno
def endpoint_file_reader(property_name: str): configs = Properties() with open('endPoint.properties', 'rb') as config_file: configs.load(config_file) return configs.get(property_name)
from jproperties import Properties configs = Properties() with open('app-config.properties', 'rb') as config_file: configs.load(config_file) print(configs.get("DB_User").data) print(configs.get("DB_HOST").data)
class ChromeComplatibility: def __init__(self): self.driver=None self.chromeVersion=None self.config = Properties() self.dir = "driversEx" self.fileName="chromedriver_win32.zip" # path= {chromeVersion} self.driverDownloadUrl = None try: self.driver = webdriver.Chrome(self.dir+"/chromedriver") self.chromeVersion=self.driver.capabilities['browserVersion'] self.driver.close() except SessionNotCreatedException as e: print("___________________________________________________") self.chromeVersion = e.args[0].split("Current browser version is ")[1].split(" ")[0] print("Compatible error") self.driverDownloadUrl = "https://chromedriver.storage.googleapis.com/"+self.chromeVersion+"/"+self.fileName f=open(self.dir+"/application.properties",'r+b') self.config.load(f) f.close() self.checkVersion() def checkVersion(self): version = self.config.get("version").data print("browser version: "+self.chromeVersion) print("old version : "+version) if(version!=self.chromeVersion): # update version and download new browser version driver print("version isn't compatible.") self.downloadWebDriver() self.extractFile() self.changeDriverVersion() else: print("Version is complatible.") def downloadWebDriver(self): print("wait for some minutes") flie = downloadFile(self.driverDownloadUrl) print("driver downloaded.") def extractFile(self): with zipfile.ZipFile(self.dir+"/"+self.fileName, 'r') as zip_ref: zip_ref.extractall(self.dir) def changeDriverVersion(self): data = "version="+self.chromeVersion with open(self.dir+"/application.properties",'w') as f: f.write(data)
def app_file_reader(property_name): configs = Properties() with open('application.properties', 'rb') as config_file: configs.load(config_file) return configs.get(property_name)