def get_topological_order_by_relations(self, relationships): topsort_input = self.__prepare_topsort_input(relationships) topological_order = list(toposort_flatten(topsort_input)) dep_breaks = ConfigReader().get_dependency_breaks() tables_to_order = ConfigReader().get_all_tables() tables_to_delete = list() for r in relationships: p = r['parent_table_name'] c = r['child_table_name'] dep_break_found = False for dep_break in dep_breaks: if p == dep_break['parent'] and c == dep_break['child']: dep_break_found = True break if dep_break_found == True: continue if tables_to_order is not None and (p not in tables_to_order or c not in tables_to_order): continue if c in topological_order: tables_to_delete.append(r) return list(reversed(tables_to_delete))
def __prepare_topsort_input(self, relationships): dep_breaks = ConfigReader().get_dependency_breaks() tables_to_order = ConfigReader().get_all_tables() deps = dict() for r in relationships: p = r['parent_table_name'] c = r['child_table_name'] #break circ dependency dep_break_found = False for dep_break in dep_breaks: if p == dep_break['parent'] and c == dep_break['child']: dep_break_found = True break if dep_break_found == True: continue if tables_to_order is not None and len(tables_to_order) > 0 and ( p not in tables_to_order or c not in tables_to_order): continue if p in deps: deps[p].add(c) else: deps[p] = set() deps[p].add(c) return deps
def __get_passthrough_tables(self, order): passthrough_tables = ConfigReader().get_passthrough_tables() passthrough_threshold = ConfigReader().get_passthrough_threshold() for o in order: for t in o: c = database_helper.get_table_count(t, self.schema, self.__source_conn) if c <= passthrough_threshold: passthrough_tables.append(t) #an explicitly marked passthrough table canhave under 100 rows in which case it'll appear in final list twice return list(set(passthrough_tables))
def test_occupy_home_or_next_to_home(): # add two invalid files: "occupy_home_file.txt" and # "occupy_next_to_home_file.txt" in "invalid_files" path = "./invalid_files/occupy_home_file.txt" try: config_reader = ConfigReader(path) return print("test_occupy_home_or_next_to_home failed!") except ValueError: return True path = "./invalid_files/occupy_next_to_home_file.txt" try: config_reader = ConfigReader(path) return print("test_occupy_home_or_next_to_home failed!") except ValueError: return True
def __init__(self): self.sleep_time = 60 self.config_file_path = "config.json" self.config = ConfigReader(self.config_file_path) self.checker = MovieChecker(self.config) self.sender = EmailSender(self.config)
def send_email_to_botuser_local(recepient_email, message, id): try: config_reader = ConfigReader() configuration = config_reader.read_config() # instance of MIMEMultipart msg = MIMEMultipart() # storing the senders email address msg['From'] = configuration['SENDER_EMAIL'] # storing the receivers email address msg['To'] = ",".join(recepient_email) # storing the subject msg['Subject'] = configuration['EMAIL_SUBJECT'] # string to store the body of the mail body = message # attach the body with the msg instance msg.attach(MIMEText(body, 'text')) filename = "report" + str(id) + ".jpg" attachment = open("LocalReport/" + filename, 'rb') # instance of MIMEBase and named as p p = MIMEBase('application', 'octet-stream') # To change the payload into encoded form p.set_payload((attachment).read()) # encode into base64 encoders.encode_base64(p) p.add_header('Content-Disposition', "attachment; filename= %s" % filename) # attach the instance 'p' to instance 'msg' msg.attach(p) # creates SMTP session smtp = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security smtp.starttls() # Authentication smtp.login(msg['From'], configuration['PASSWORD']) # Converts the Multipart msg into a string text = msg.as_string() # sending the mail smtp.sendmail(msg['From'], recepient_email, text) print('email send') # terminating the session smtp.quit() except Exception as e: print('the exception is ' + str(e))
def news(req): sessionID = req.get("session") session = re.compile("sessions/(.*)") sessionID = session.findall(sessionID)[0] result = req.get("queryResult") user_says = result.get("queryText") try: config_reader = ConfigReader() configuration = config_reader.read_config() url = "http://newsapi.org/v2/top-headlines?country=in&category=health&apiKey=" + \ configuration['NEWS_API'] res = requests.get(url) jsonRes = res.json() articles = jsonRes["articles"] news = list() for i in range(len(articles)): title = articles[i]["title"] author = articles[i]["author"] news_final = str(i + 1) + ". " + \ str(title) + " - " + str(author) news.append(news_final) fulfillmentText = "\n".join(news) bot_says = fulfillmentText return {"fulfillmentText": fulfillmentText} except HTTPError as http_err: print(f"HTTP error occurred: {http_err}") except Exception as err: print(f"Other error occurred: {err}")
def webhook(): config_reader = ConfigReader() configuration = config_reader.read_config() req = request.get_json(silent=True, force=True) print("Request:") print(json.dumps(req, indent=4)) intent_check = req.get("queryResult").get("intent").get("displayName") if intent_check == "CountryCases_menu": res = getCountryName(req) elif intent_check == "StateCases_menu": res = getStateName(req) elif intent_check == "MyAreaCases_menu": res = getUserDetails(req) elif intent_check == "GlobalCases_menu": res = globalCases(req) elif intent_check == "indiaCases_menu": res = indiaCases(req) elif intent_check == "News": res = news(req) elif intent_check == "Helpline_Menu": res = helpLine(req) res = json.dumps(res, indent=4) r = make_response(res) r.headers['Content-Type'] = 'application/json' return r
def main(): cr = ConfigReader() config = cr.read_config_as_dict(conf.CONFIG_PATH) # create the log, so other module can use it #Logger(config['logger']['path'], config['logger']['level']) Logger(None, 7) # create the pool, so other module can use it DbPool(4, config['db']['host'], config['db']['port'], config['db']['user'], config['db']['password'], config['db']['db_name']) az_t = AnalyzeThread() smt = StreamMonitorThread(config['get_stream_api_url'], config['read_token'], config['monitor_cdn_in_api'], az_t, config['extra_streams']) all_threads["analyze_thread"] = az_t all_threads["stream_monitor"] = smt az_t.start() smt.start() az_t.join() smt.join()
def create(self): if self.use_existing_dump == True: pass else: tt = ConfigReader().get_all_tables() tables = ' '.join(['-t ' + t for t in tt]) cur_path = os.getcwd() pg_dump_path = get_pg_bin_path() if pg_dump_path != '': os.chdir(pg_dump_path) pg_dumpsql_path = os.path.join(self.output_path, 'schema_dump.sql') os.system( 'pg_dump --dbname=postgresql://{0}:{1}@{2}:{3}/{4} > {5} --schema-only --no-owner --no-privileges {6}' .format(self.source_connection_info['user_name'], self.source_connection_info['password'], self.source_connection_info['host'], self.source_connection_info['port'], self.source_connection_info['db_name'], pg_dumpsql_path, tables)) os.chdir(cur_path) self.__filter_commands(self.output_path) self.destination_psql_client.run( os.path.join(self.output_path, 'dump_create.sql'), self.create_output_path, self.create_error_path, True, True)
def test_file_not_found(): invalid_path = "./invalid_files/not_found.txt" try: config_reader = ConfigReader(invalid_path) return print("test_file_not_found failed!") except FileNotFoundError: return True
def __init__(self, config=None, debug=False): self.req_fields = ['title', 'descriprion', 'link'] self.opt_for_feed = { 'language': "", \ 'subtitle': "", \ 'updated': "", \ 'updated_parsed': "", } self.opt_for_items = { 'published': "", \ 'published_parsed': "", \ 'language': "", \ 'term': { 'field': 'tags', \ 'sub_field': 'term'},\ 'summary': "" } self.debug = debug # Read config parametrs config_reader = ConfigReader() config_reader.read(config) self.rss_urls = config_reader.url_names self.freq = config_reader.freq # Fields that are needed to be without html tags self.text_extr_fields = set() self.__set_text_extract_fields__() self.cut_html = CutHTML() self.cut_html.reset() # Connect to db self.db_connector = DBConnector(debug=self.debug) # News agent name and time mark self.news_agent_name = "" # + 0000 self.time_mark = None
def send_email_to_student(self, recepient_email, message, cust_name, responseId, lstCases): try: self.config_reader = ConfigReader() self.configuration = self.config_reader.read_config() # instance of MIMEMultipart self.msg = MIMEMultipart() # storing the senders email address self.msg['From'] = self.configuration['SENDER_EMAIL'] # storing the receivers email address self.msg['To'] = ",".join(recepient_email) # storing the subject self.msg['Subject'] = self.configuration['EMAIL_SUBJECT'] # string to store the body of the mail #body = "This will contain attachment" imgUrl = os.path.join(os.path.abspath('static/images'), responseId + ".png") self.get_cases_bar(responseId, lstCases, imgUrl) fp = open(imgUrl, 'rb') msgImage = MIMEImage(fp.read()) fp.close() # Define the image's ID as referenced above msgImage.add_header('Content-ID', '<image1>') self.msg.attach(msgImage) body = message body = body.replace('cust_name', cust_name) # attach the body with the msg instance self.msg.attach(MIMEText(body, 'html')) # instance of MIMEBase and named as p self.p = MIMEBase('application', 'octet-stream') # creates SMTP session self.smtp = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security self.smtp.starttls() # Authentication self.smtp.login(self.msg['From'], self.configuration['PASSWORD']) # Converts the Multipart msg into a string self.text = self.msg.as_string() # sending the mail self.smtp.sendmail(self.msg['From'], recepient_email, self.text) # terminating the session self.smtp.quit() except Exception as e: print('the exception is ' + str(e))
def test_non_integer(): path = "./invalid_files/non_integer_file.txt" try: config_reader = ConfigReader(path) return print("test_non_integer failed!") except ValueError: return True
def test_frame_out_of_range(): path = "./invalid_files/format_out_of_range_file.txt" try: config_reader = ConfigReader(path) return print("test_frame_out_of_range failed!") except SyntaxError: return True
def test_format_error(): path = "./invalid_files/format_error_file.txt" try: config_reader = ConfigReader(path) return print("test_format_error failed!") except SyntaxError: return True
def test_out_of_map(): # add "out_of_map_file.txt" in "invalid_files" path = "./invalid_files/out_of_map_file.txt" try: config_reader = ConfigReader(path) return print("test_out_of_map failed!") except SyntaxError: return True
def test_odd_length(): # add "odd_length_file.txt" in "invalid_files" path = "./invalid_files/odd_length_file.txt" try: config_reader = ConfigReader(path) return print("test_odd_length failed!") except SyntaxError: return True
def test_valid_file(): # no need to create file for this one, just test loading config.txt path = "./config.txt" try: config_reader = ConfigReader(path) return True except: return print("test_valid_file failed!")
def send_email_to_student(self, recepient_email, message): # print("recepient_email",recepient_email) # print("message",message) try: self.config_reader=ConfigReader() self.configuration=self.config_reader.read_config() # instance of MIMEMultipart self.msg = MIMEMultipart() # storing the senders email address self.msg['From'] = self.configuration['SENDER_EMAIL'] # storing the receivers email address self.msg['To'] = ",".join(recepient_email) # storing the subject self.msg['Subject'] = self.configuration['EMAIL_SUBJECT'] # string to store the body of the mail #body = "This will contain attachment" body=message # attach the body with the msg instance self.msg.attach(MIMEText(body, 'html')) # instance of MIMEBase and named as p self.p = MIMEBase('application', 'octet-stream') # creates SMTP session self.smtp = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security self.smtp.starttls() print("sender_email xx",self.msg['From']) print("pass xx",self.configuration['PASSWORD']) # Authentication self.smtp.login(self.msg['From'], self.configuration['PASSWORD']) # Converts the Multipart msg into a string self.text = self.msg.as_string() # sending the mail self.smtp.sendmail(self.msg['From'] , recepient_email, self.text) # terminating the session self.smtp.quit() except Exception as e: print('the exception is email xx '+str(e))
def __init__(self): """ initi method creates the required files and locations """ message_queue = Queue.Queue() conf_reader = ConfigReader() configuration_dictionary = conf_reader.conf_dict listen_server = ListenServer(message_queue, configuration_dictionary) sql_alchemy = SqlAlchemy(configuration_dictionary)
def test_duplicate_position(): # add two files: "dupli_pos_in_single_line.txt" and # "dupli_pos_in_multiple_lines.txt" in "invalid_files" path = "./invalid_files/dupli_pos_in_multiple_lines.txt" try: config_reader = ConfigReader(path) return print("test_duplicate_position failed!") except SyntaxError: return True
def sendEmailToSupportForRecording(self, name, email, batch, day): self.config_reader = ConfigReader() self.configuration = self.config_reader.read_config() # instance of MIMEMultipart self.msg = MIMEMultipart() # storing the senders email address self.msg['From'] = "iNeuron Megatron Chatbot <*****@*****.**>" # storing the receivers email address self.msg['To'] = "*****@*****.**" # storing the subject self.msg['Subject'] = "Recording Uploading query" body = """We have a query that recording is not uploaded in dashboard. Here is the details:- Batch:- {} Day:- {} Customer-name:- {} Customer-email:- {} Please have a look into this. Regards, Team iNeuron """.format(batch,day,name,email) # attach the body with the msg instance self.msg.attach(MIMEText(body, 'html')) # instance of MIMEBase and named as p self.p = MIMEBase('application', 'octet-stream') # creates SMTP session self.smtp = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security self.smtp.starttls() # Authentication self.smtp.login( self.configuration['SENDER_EMAIL'], self.configuration['PASSWORD']) # Converts the Multipart msg into a string self.text = self.msg.as_string() # sending the mail self.smtp.sendmail( self.configuration['SENDER_EMAIL'], self.msg['To'], self.text) print("Email sent to support team!") # terminating the session self.smtp.quit() return "Email sent to support team!"
def __init__(self): reader = ConfigReader() db_connection = reader.get_value("db_connection") self.conn_string = '{db_engine}{connector}://{user}:{password}@{server}/{database}'.format( db_engine=db_connection['db_engine'], connector=db_connection['connector'], user=db_connection['user'], password=db_connection['password'], server=db_connection['server'], database=db_connection['database'])
def sendEmailToSupport(self, name, email, user_query): self.config_reader = ConfigReader() self.configuration = self.config_reader.read_config() # instance of MIMEMultipart self.msg = MIMEMultipart() # storing the senders email address self.msg['From'] = "iNeuron Megatron Chatbot <*****@*****.**>" # storing the receivers email address self.msg['To'] = "*****@*****.**" # storing the subject self.msg['Subject'] = "Customer query" body = """We have a customer query, which we were not able to answer as of now. Here is the query:- {}\n Customer-name:- {}\n Customer-email:- {}\n Please have a look into this. \n\n\n\n Regards, Team iNeuron """.format(user_query,name,email) # attach the body with the msg instance self.msg.attach(MIMEText(body, 'html')) # instance of MIMEBase and named as p self.p = MIMEBase('application', 'octet-stream') # creates SMTP session self.smtp = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security self.smtp.starttls() # Authentication self.smtp.login( self.configuration['SENDER_EMAIL'], self.configuration['PASSWORD']) # Converts the Multipart msg into a string self.text = self.msg.as_string() # sending the mail self.smtp.sendmail( self.configuration['SENDER_EMAIL'], self.msg['To'], self.text) print("Email sent to support team!") # terminating the session self.smtp.quit() return "Email sent to support team!"
def __init__(self): config_reader = ConfigReader() self.__PROTO_FILE = config_reader.get_string_property('ProtoFile') self.__WEIGHTS_FILE = config_reader.get_string_property('WeightsFile') quantized_lab_space_path = config_reader.get_string_property('QuantizedLabSpace') self.__QUANTIZED_LAB_SPACE = np.load(quantized_lab_space_path).transpose().reshape(2, 313, 1, 1) self.__INPUT_WIDTH = config_reader.get_int_property('Width') self.__INPUT_HEIGHT = config_reader.get_int_property('Height') self.__neural_network = cv2.dnn.readNetFromCaffe(self.__PROTO_FILE, self.__WEIGHTS_FILE) self.__populate_network_layers_with_quantized_lab_space()
def send_email_to_support(self, cust_name, cust_email, cust_contact, course_name, body): try: self.config_reader = ConfigReader() self.configuration = self.config_reader.read_config() # instance of MIMEMultipart self.msg = MIMEMultipart() # storing the senders email address self.msg['From'] = self.configuration['SENDER_EMAIL'] # storing the subject self.msg['Subject'] = self.configuration[ 'SALES_TEAM_EMAIL_SUBJECT'] # string to store the body of the mail # body = "This will contain attachment" body = body.replace('cust_name', cust_name) body = body.replace('cust_contact', cust_contact) body = body.replace('cust_email', cust_email) body = body.replace('course_name', course_name) # attach the body with the msg instance self.msg.attach(MIMEText(body, 'html')) # instance of MIMEBase and named as p self.p = MIMEBase('application', 'octet-stream') # creates SMTP session self.smtp = smtplib.SMTP('smtp.gmail.com', 587) # start TLS for security self.smtp.starttls() # Authentication self.smtp.login(self.msg['From'], self.configuration['PASSWORD']) # Converts the Multipart msg into a string self.text = self.msg.as_string() # sending the mail self.support_team_email = self.configuration['SALES_TEAM_EMAIL'] self.smtp.sendmail(self.msg['From'], self.support_team_email, self.text) # terminating the session self.smtp.quit() except Exception as e: print('the exception is ' + str(e))
def tabulate(self): #tabulate row_counts = list() for table in ConfigReader().get_all_tables(): with self.source_db.get_db_connection() as conn: o = database_helper.get_table_count(table, self.schema, conn) with self.destination_db.get_db_connection() as conn: n = database_helper.get_table_count(table, self.schema, conn) row_counts.append((table, o, n)) print('\n'.join( [f'{x[0]}, {x[1]}, {x[2]}, {x[2]/x[1]}' for x in row_counts]))
def connect(): needed_reconnect = False if FBData.ready == False: print("Connecting to facebook...") email, password = ConfigReader().getFacebookCredentials() # FBData.client = fbchat.Client("*****@*****.**", "MadeInJack") FBData.client = fbchat.Client(email, password) FBData.ready = True needed_reconnect = False else: print "Facebook connection is on."
def setUp(self): self.config = ConfigReader(""" <root> <person> <name>fake</name> <age>15</age> </person> <person> <name>test</name> <age>43</age> </person> </root> """)