def store(self, name, value, default, save=True): if value: self.data[name] = value elif name not in self.data: self.data[name] = default if save: Config.save(settings.RUNTIME_PATH, self.data)
def email_to_send(parameters_, type_email, Subject, destine_email): try: email_conf = emailconfig() config = Config() strFrom = email_conf.get_user() strTo = destine_email msgRoot = MIMEMultipart('related') msgRoot['Subject'] = Subject + ' - ' + config.get_platform_name() msgRoot['From'] = strFrom msgRoot['To'] = strTo msgRoot.preamble = 'This is a multi-part message in MIME format.' msgAlternative = MIMEMultipart('alternative') msgRoot.attach(msgAlternative) msgText = MIMEText('This is the alternative plain text message.') msgAlternative.attach(msgText) # We reference the image in the IMG SRC attribute by the ID we give it below email_content, found, n_parameters = type_of_emails(type_email) print len(parameters_) if not found: return [False, 'Type of email not found'] if len(parameters_) != n_parameters: return [False, 'The number of parameters entered are not valid'] final_email = email_content.format(*parameters_) msgText = MIMEText(final_email, 'html') msgAlternative.attach(msgText) # This example assumes the image is in the current directory fp = file(os.path.join(root_dir(), 'emails/logo.png'), 'rb') msgImage = MIMEImage(fp.read(), _subtype="png") fp.close() # Define the image's ID as referenced above msgImage.add_header('Content-ID', '<image1>') msgRoot.attach(msgImage) # Send the email (this example assumes SMTP authentication is required) smtp = smtplib.SMTP_SSL(email_conf.get_url(), email_conf.get_port()) smtp.ehlo() smtp.login(strFrom, email_conf.get_pass()) smtp.sendmail(strFrom, strTo, msgRoot.as_string()) smtp.quit() print return [True, 'enviado******'] except Exception as e: print e return [False, 'NOOO ENVIADO']
def save_env_vars(self, name = None): self.load_data() env_name = self.get_active_env() if name is None else name variables = { 'ZIMAGI_ENVIRONMENT': env_name } with self.lock: if env_name not in self.data['environments']: raise EnvironmentError("Environment {} is not defined".format(env_name)) for field_name, field_value in self.data['environments'][env_name].items(): variables["ZIMAGI_{}".format(field_name.upper())] = field_value if field_value is not None else '' Config.save(self.get_env_path(), variables)
def create_user(nick_, email_, sex_, school, class_, birth_year_, birth_month_, birth_day_, country_): try: token = get_random(30) c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() pass_ = get_random(8) salt = random_salt() password = encrypt_pass(pass_, salt) query = "INSERT INTO users(nick, email, fk_roluser, password, salt, sex, school, class, birth_year, birth_month, birth_day, fk_country) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);" data = ( nick_, email_, 'Student', password, salt, sex_, school, class_, birth_year_, birth_month_, birth_day_, country_, ) cursor.execute(query, data) cnx.commit() cnx.close() return True, pass_ except Exception as e: print e return False, ''
def __init__(self): self.app_dir = settings.APP_DIR self.data_dir = settings.DATA_DIR self.config = Config.load(settings.RUNTIME_PATH, {}) self.env = self.config.get('ZIMAGI_ENV', settings.DEFAULT_ENV_NAME) self.module_dir = os.path.join(settings.MODULE_BASE_PATH, self.env) super().__init__()
def edit_challenge_professor(id_number_challenge, title, summary, description, aim, category, FK_owner_nick): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "UPDATE all_challenges SET title =%s, summary =%s, description =%s, aim =%s, last_edit=%s, fk_category =%s WHERE id_number =%s AND owner_fk_nick =%s;" data = ( title, summary, description, aim, now, category, id_number_challenge, FK_owner_nick, ) cursor.execute(query, data) cnx.commit() row = cursor.rowcount cnx.close() # pendiente - remover estudiantes al desafio if row >= 1: return True, 'The challenge has been edited successfully' else: return True, 'No changes detected in the challenge' except Exception as e: print e return False, 'Something went wrong'
def new_challenge_p(title_, summary_, description_, aims_, photo_, owner_, category_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() token_ = str(get_random_num(4)) + '-' + str(get_random_str(4)) query = "INSERT INTO all_challenges(title,token_challenge, photourl, summary, description, aim, created, owner_fk_nick, fk_category) VALUES (%s, %s, %s, %s, %s,%s, %s, %s, %s);" data = ( str(title_), str(token_), str(photo_), str(summary_), str(description_), str(aims_), now, str(owner_), str(category_), ) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: print e return False
def edit_class_info_professor(id_class_, school_, identificator_, class_, year_, FK_owner_nick): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "UPDATE class_list SET school =%s, identificator =%s, class =%s, year =%s, d_last_modification =%s WHERE id_number =%s AND FK_owner_nick =%s;" data = ( school_, identificator_, class_, year_, now, id_class_, FK_owner_nick, ) cursor.execute(query, data) cnx.commit() row = cursor.rowcount cnx.close() if row >= 1: return True, 'The class information, has been edited successfully' else: return True, 'No changes detected in the class' except Exception as e: print e return False, 'Something went wrong'
def new_class(school_, identificator_, class_, year_, _FK_owner_nick): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "INSERT INTO class_list(school, identificator, class, year, status, d_creation,FK_owner_nick) VALUES (%s, %s, %s,%s, %s, %s, %s);" data = ( school_, identificator_, class_, year_, 'active', now, str(_FK_owner_nick), ) cursor.execute(query, data) cnx.commit() cnx.close() return True, 'The class has been successfully entered' except Exception as e: print e return False, 'Something went wrong'
def finish_challenge(id_challenge_, nick_student_, last_response, date_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "UPDATE Challenge_last_activity SET last_response =%s, finalized = %s, end_date=%s WHERE FK_challenge_id_number =%s AND FK_student_nick =%s;" data = ( last_response, '1', date_, id_challenge_, nick_student_, ) cursor.execute(query, data) cnx.commit() row = cursor.rowcount cnx.close() if row >= 1: add_interaction(id_challenge_, nick_student_) return True, 'The challenge has been finished' else: return True, 'No changes detected in the challenge' except Exception as e: print e return False, 'Something went wrong'
def remove_challenge_to_class_professor(FK_class_id_number_, FK_challenge_id_number_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "DELETE FROM class_challenges WHERE FK_class_id_number=%s AND FK_challenge_id_number = %s;" data = ( FK_class_id_number_, FK_challenge_id_number_, ) cursor.execute(query, data) row = cursor.rowcount cnx.commit() cnx.close() # pendiente - remover estudiantes al desafio if row >= 1: return True, 'The challenge has been delete successfully of this class' else: return True, 'No challenge was eliminated' except Exception as e: return False, 'Something went wrong'
def __provider_name(self): name = self.options.get(_provider_name, None) if _provider_config and not name: name = self.get_config(_provider, required=False) if not name: name = Config.string("ZIMAGI_{}".format(_provider.upper()), _default) return name
def exec(self): self.manager.start_service(self, 'zimagi-postgres', "postgres:12", { 5432: None }, environment = { 'POSTGRES_USER': Config.string('ZIMAGI_POSTGRES_USER', 'zimagi'), 'POSTGRES_PASSWORD': Config.string('ZIMAGI_POSTGRES_PASSWORD', 'zimagi'), 'POSTGRES_DB': Config.string('ZIMAGI_POSTGRES_DB', 'zimagi') }, volumes = { 'zimagi-postgres': { 'bind': '/var/lib/postgresql', 'mode': 'rw' } }, memory = self.memory, wait = 20 ) self.success('Successfully started PostgreSQL database service')
def get_recovery_token(user_): token = '' c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() query = "SELECT token FROM recovery_pass_token WHERE used = 0 AND expire >= NOW() AND fk_nick = %s;" data = (user_, ) cursor.execute(query, data) for (token) in cursor: return True, token cursor.close() cnx.close() return False, token
def exec(self): self.manager.start_service( self, 'zimagi-redis', "redis:5", {6379: None}, docker_command="redis-server --requirepass {}".format( Config.string('ZIMAGI_REDIS_PASSWORD', 'zimagi')), volumes={'zimagi-redis': { 'bind': '/data', 'mode': 'rw' }}, memory=self.memory, wait=20) self.set_state('config_ensure', True) self.success('Successfully started Redis service')
def challenge_init(id_challenge_, nick_student_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "INSERT INTO Challenge_last_activity(FK_student_nick ,FK_challenge_id_number ,last_response, number_of_interaction, init_date, finalized) VALUES (%s, %s, %s, %s, %s,%s);" data = (nick_student_, id_challenge_, '', 1, now, 0) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: print e return False
def new_permission(id_challenge_, nick_user): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "INSERT INTO evaluation_permissions(FK_all_challenges_id,FK_nick_evaluator) VALUES (%s, %s);" data = ( id_challenge_, nick_user, ) cursor.execute(query, data) cnx.commit() cnx.close() except Exception as e: print e
def insert_general_record(action_, data_, fk_nick_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "INSERT INTO records(action, data, dtime, fk_nick) VALUES (%s, %s, %s, %s);" data = ( action_, str(data_), now, fk_nick_, ) cursor.execute(query, data) cnx.commit() cnx.close() except Exception as e: print e
def add_interaction(id_challenge_, nick_student_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "UPDATE Challenge_last_activity SET number_of_interaction = number_of_interaction + 1 WHERE FK_student_nick = %s AND FK_challenge_id_number=%s" data = ( nick_student_, id_challenge_, ) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: print e return False
def log_student_queries(nick_student_, id_challenge_, query_, now_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() query = "INSERT INTO Students_query(FK_student_nick ,FK_challenge_id_number ,query, date_executed ) VALUES (%s, %s, %s, %s);" data = ( nick_student_, id_challenge_, query_, now_, ) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: print e return False
def insert_related_search_query(FK_id_number_student_query, position_, query_text): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() query = "INSERT INTO Students_related_search(FK_student_query_id_number ,position , textquery ) VALUES (%s, %s, %s);" data = ( FK_id_number_student_query, position_, query_text, ) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: print e return False
def insert_token(user_): try: token = get_random(30) c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() exp = datetime.now() - timedelta(minutes=60 * 4) query = "INSERT INTO recovery_pass_token(token, fk_nick, expire, used) VALUES (%s, %s, DATE_ADD(NOW(), INTERVAL 4 HOUR), 0);" data = ( str(token), user_, ) cursor.execute(query, data) cnx.commit() cnx.close() return True, token except Exception as e: print e return False, ''
def insert_new_mark_challenge_last_activity(id_last_activity, marks, nick_evaluator): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "INSERT INTO evaluation_marks(FK_challenge_last_activity_id,marks,FK_nick_evaluator) VALUES (%s, %s, %s);" data = ( id_last_activity, marks, nick_evaluator, ) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: return False print e
def add_student_to_class_professor(FK_class_id_number_, FK_student_nick_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "INSERT INTO classes(FK_class_id_number, FK_student_nick) VALUES (%s, %s);" data = ( FK_class_id_number_, FK_student_nick_, ) cursor.execute(query, data) cnx.commit() cnx.close() # FALTA - enlazar estudiantes al desafio return True, 'The student has been successfully entered in the class' except Exception as e: if ('Duplicate entry' in str(e)) and ('for key' in str(e)): return False, 'The student was previously registered in this class' else: return False, 'Something went wrong'
def update_text_library(FK_student_nick, FK_challenge_id_number, title_text, url_text, state): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() now = datetime.now() query = "UPDATE Student_personal_library SET state=%s WHERE FK_student_nick=%s AND FK_challenge_id_number=%s AND title_text=%s AND url_text=%s;" data = ( state, FK_student_nick, FK_challenge_id_number, title_text, url_text, ) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: print e return False
def insert_result_query(FK_id_number_student_query, position_, lang_, title_, snippet_, url_): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() query = "INSERT INTO Students_queries_results(FK_student_query_id_number ,position , lang, title, snippet, url ) VALUES (%s, %s, %s, %s, %s, %s);" data = ( FK_id_number_student_query, position_, lang_, title_, snippet_, url_, ) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: print e return False
def add_text_library(FK_student_nick, FK_challenge_id_number, title_text, url_text, date_added, state): try: c = Config() database_ = Database() config = database_.config cnx = mysql.connector.connect(**config) cursor = cnx.cursor() query = "INSERT INTO Student_personal_library(FK_student_nick , FK_challenge_id_number , title_text, url_text, date_added, state) VALUES (%s, %s, %s, %s, %s, %s);" data = ( FK_student_nick, FK_challenge_id_number, title_text, url_text, date_added, state, ) cursor.execute(query, data) cnx.commit() cnx.close() return True except Exception as e: print e return False
# -*- coding: utf-8 -*- from tools.os import OS from tools.yml import YML from settings.log import Log from settings.config import Config from settings.cli import CLIArguments # ============================================================================== # GLOBAL # ============================================================================== MAX_RETRIES = 50 config, args, yml = Config(), CLIArguments().args, YML().get_content() twitter_consumer_key = config.get_env("TWITTER_CONSUMER_KEY") twitter_consumer_secret = config.get_env("TWITTER_CONSUMER_SECRET") twitter_access_token = config.get_env("TWITTER_ACCESS_TOKEN") twitter_access_token_secret = config.get_env("TWITTER_ACCESS_TOKEN_SECRET") twitter_consumer_key = twitter_consumer_key if twitter_consumer_key else yml["twitter"]["consumer"]["key"] twitter_consumer_secret = twitter_consumer_secret if twitter_consumer_secret else yml["twitter"]["consumer"]["secret"] twitter_access_token = twitter_access_token if twitter_access_token else yml["twitter"]["access"]["token"] twitter_access_token_secret = twitter_access_token_secret if twitter_access_token_secret else yml["twitter"]["access"]["secret"] log_path = config.get_env("LOG_PATH") if config.get_env("LOG_PATH") else "/var/log/code" log_file = config.get_env("LOG_FILE") if config.get_env("LOG_FILE") else "file.log" log_level = config.get_env("LOG_LEVEL") if config.get_env("LOG_LEVEL") else "DEBUG" logger_name = config.get_env("LOGGER_NAME") if config.get_env("LOGGER_NAME") else "Twitter Realtime Processing"
from flask import jsonify from flask import request # import flask from orchestrator import Orchestrator from settings.config import Config from settings.factory import Factory from vectorizers.img_to_vec import Img2Vec app = Flask(__name__) # create an app instance img2vec = Img2Vec() port = 8082 host = '0.0.0.0' debug = True config = Config() components_factory = Factory(config) indexer = components_factory.get_indexer() content_vectors = components_factory.get_content_vector_store() result_mapper = components_factory.get_result_mapper() writer = components_factory.get_writer() reader = components_factory.get_reader() global_store = components_factory.get_global_store() # image_utils = ImageUtils(img2vec) @app.route("/api/v1/train", methods=['POST']) # at the end point / def training(): # call method training # content_vectors.load_csv('./assets/livemint-cv2.csv')
def test_config(): conf = Config() conf.parse("settings/config.ini")