try: df.to_sql(self.today + post_fix, engine, if_exists='fail') except Exception, e: logger.log(e) if choice == 2: df = df.set_index(u'序号') df[u'最大涨幅'] = map(lambda x: round(x * 100, 3), df[u'最大涨幅']) df[u'最大跌幅'] = map(lambda x: round(x * 100, 3), df[u'最大跌幅']) df[u'今日开盘涨幅'] = map(lambda x: round(x * 100, 3), df[u'今日开盘涨幅']) df[u'昨日涨停强度'] = map(lambda x: round(x, 0), df[u'昨日涨停强度']) df[u'今日涨停强度'] = map(lambda x: round(x, 0), df[u'今日涨停强度']) try: df.to_sql(self.today + post_fix, engine, if_exists='fail') except Exception, e: logger.log(e) # 昨日涨停今日的状态,今日涨停 def storedata(self): zdt_content = self.getdata(self.zdt_url, headers=self.header_zdt) logger.log('zdt Content' + zdt_content) zdt_js = self.convert_json(zdt_content) self.save_to_dataframe(zdt_js, self.zdt_indexx, 1, 'zdt') time.sleep(2) zrzt_content = self.getdata(self.zrzt_url, headers=self.header_zrzt) logger.log('zrzt Content' + zdt_content) zrzt_js = self.convert_json(zrzt_content) self.save_to_dataframe(zrzt_js, self.zrzt_indexx, 2, 'zrzt')
try: df.to_sql(self.today + post_fix, engine, if_exists='fail') except Exception, e: logger.log(e) if choice == 2: df = df.set_index(u'序号') df[u'最大涨幅'] = map(lambda x: round(x * 100, 3), df[u'最大涨幅']) df[u'最大跌幅'] = map(lambda x: round(x * 100, 3), df[u'最大跌幅']) df[u'今日开盘涨幅'] = map(lambda x: round(x * 100, 3), df[u'今日开盘涨幅']) df[u'昨日涨停强度'] = map(lambda x: round(x, 0), df[u'昨日涨停强度']) df[u'今日涨停强度'] = map(lambda x: round(x, 0), df[u'今日涨停强度']) try: df.to_sql(self.today + post_fix, engine, if_exists='fail') except Exception, e: logger.log(e) # 昨日涨停今日的状态,今日涨停 def storedata(self): zdt_content = self.getdata(self.zdt_url, headers=self.header_zdt) logger.log('zdt Content' + zdt_content) zdt_js = self.convert_json(zdt_content) self.save_to_dataframe(zdt_js, self.zdt_indexx, 1, 'zdt') time.sleep(5) zrzt_content = self.getdata(self.zrzt_url, headers=self.header_zrzt) logger.log('zrzt Content' + zdt_content) zrzt_js = self.convert_json(zrzt_content) self.save_to_dataframe(zrzt_js, self.zrzt_indexx, 2, 'zrzt')
time.sleep(LOOP__TIME) except Exception as e: logger.log(e) self.api = ts.get_apis() time.sleep(EXECEPTION_TIME) elif current == -1: time.sleep(LOOP__TIME) elif current == 1: try: ts.close_apis(self.api) except Exception as e: logger.log('fail to stop monitor {}'.format( datetime.datetime.now())) exit(0) if __name__ == '__main__': today = datetime.datetime.now().strftime('%Y-%m-%d') if ts.is_holiday(today): logger.log('{} holiday'.format(today)) exit(0) obj = ReachTarget() obj.monitor()
# print datetime.datetime.now() try: sendmail(ret_dt.to_string(),u'波动的可转债') logger.log("Send mail successfully at {}".format(datetime.datetime.now())) except Exception,e: logger.log('sending mail failed') logger.log(e) time.sleep(LOOP__TIME) except Exception, e: logger.log(e) self.api=ts.get_apis() time.sleep(EXECEPTION_TIME) elif current==-1: time.sleep(LOOP__TIME) elif current==1: try: ts.close_apis(self.api) except Exception,e: logger.log('fail to stop monitor {}'.format(datetime.datetime.now())) exit(0) if __name__ == '__main__': today = datetime.datetime.now().strftime('%Y-%m-%d') if ts.is_holiday(today): logger.log('{} holiday'.format(today)) exit(0) obj = ReachTarget() obj.monitor()
f_open.close() if len(all_contents) > 0: sendmail(''.join(all_contents), temp_time) db_name = 'db_stock' conn = get_mysql_conn(db_name, local=True) # create_tb(conn) cur = conn.cursor() for i in cmd_list: try: cur.execute(i) conn.commit() except Exception, e: logger.log(e) conn.rollback() conn.commit() # conn.close() db_name = 'qdm225205669_db' conn2 = get_mysql_conn(db_name, local=False) # create_tb(conn2) cur2 = conn2.cursor() for i in cmd_list: try: cur2.execute(i) conn2.commit() except Exception, e: