def insert_to_mysql(lines): connection = s_utils.conn_mysql() try: with connection.cursor() as cursor: for index, row in lines.iterrows(): sql = cons.insert_news.format(cons.news_table_name) cursor.execute(sql, (cons.today_str_Ymd, row['publish_time'], row['article_title'], row['article_text'])) connection.commit() finally: connection.close()
def insert_mysql(self, df): connection = s_utils.conn_mysql() try: with connection.cursor() as cursor: for index, row in df.iterrows(): sql = cons.insert_reseach_report.format( cons.research_report_table_name) cursor.execute( sql, (row['title'], row['article_url'], row['type'], row['publish_time'], row['institution'], row['author'], row['content'])) connection.commit() finally: connection.close()
def get_data(self): connection = s_utils.conn_mysql() try: with connection.cursor() as cursor: sql = (cons.east_get_data.format( cons.east_money_ann_table_name, self.today, cons.SECURITYTYPE1)) x = cursor.execute(sql) result = cursor.fetchmany(x) data = [ item['noticetitle'] + cons.SPLIT_ITEM5 + item['url'] + cons.SPLIT_ITEM5 + item['columnname'] for item in result ] return data finally: connection.close()
def insert_mysql(self, df): connection = s_utils.conn_mysql() try: with connection.cursor() as cursor: # 倒序插入表中 for index, row in df[::-1].iterrows(): sql = cons.insert_east_money_ann_sql.format(cons.east_money_ann_table_name) cursor.execute(sql, (row[u'SECURITYCODE'], row[u'SECURITYFULLNAME'], row[u'NOTICETITLE'], row[u'NOTICEDATE'], row[u'SECURITYTYPE'], row[u'COLUMNNAME'], row[u'URL'])) connection.commit() finally: connection.close()
def insert_mysql(self, df): self.log.info("Inserting values...") connection = s_utils.conn_mysql() try: with connection.cursor() as cursor: # 倒序插入表中 for index, row in df[::-1].iterrows(): sql = cons.insert_reseach_report.format( cons.research_report_table_name) cursor.execute( sql, (row[u'title'], row[u'article_url'], row[u'type'], row[u'publish_time'], row[u'institution'], row[u'author'], row[u'content'])) self.log.info("{} was inserted.".format(row['title'])) connection.commit() finally: connection.close()