def clone_database(): local_db = get_mysql_conn('db_zdt', local=True) cur = local_db.cursor() cur.execute('show tables') tables = cur.fetchall() local_engine = get_engine('db_zdt', local=True) dfs = [] for table in tables: try: result = re.findall('(\d+)zdt$', table[0]) if result: print(table[0]) current = result[0] # d= datetime.datetime.strptime(current,'%Y%m%d').strftime('%Y-%m-%d') # print(d) df = pd.read_sql(table[0], local_engine, index_col='index') # df['涨停日期']=d df = df.rename(columns={ '最后一次涨停时间A': '最后一次涨停时间', '第一次涨停时间A': '第一次涨停时间' }) try: print(df.head()) df.to_sql(table[0], local_engine, if_exists='replace') except Exception as e: print(e) except Exception as e: print(e) print(table[0])
def cb_stock_year(): ''' 上一年可转债正股的涨跌幅排名 :return: ''' engine = get_engine('db_stock') df_cb = pd.read_sql('tb_bond_jisilu', engine) filename='2019_all_price_change_ignore_new_stock.xls' df_all=pd.read_excel(filename,encoding='gbk') zg_codes = list(df_cb['正股代码'].values) df = df_all[df_all['code'].isin(zg_codes)] df.to_excel('2019_cb_zg.xls',encoding='gbk')
def merge_database(): local_db = get_mysql_conn('db_zdt', local=True) cur = local_db.cursor() cur.execute('show tables') tables = cur.fetchall() local_engine = get_engine('db_zdt', local=True) dfs = [] for table in tables: try: result = re.findall('(\d+)zdt$', table[0]) if len(result) > 0: print(table[0]) df = pd.read_sql(table[0], local_engine, index_col='index') dfs.append(df) except Exception as e: print(e) print(table[0]) dfx = pd.concat(dfs) print(dfx.head()) # ali_engine = get_engine(None,local=False) local_engine_stock = get_engine('db_stock', local=True) dfx.to_sql('tb_zdt', local_engine_stock, if_exists='replace')
def main(): obj = Filter_Stock() now = datetime.datetime.now() today = now.strftime("%Y%m%d") tb_name = today + 'zdt' end = str(now.year) + '-' + str(now.month - 1) df = obj.get_new_stock('2015', end) code_list = df['code'].values engine = get_engine('db_zdt') zt_df = pd.read_sql(tb_name, engine, index_col='index') zt_df['涨停强度'] = map(lambda x: round(x, 0), zt_df['涨停强度']) ret_df = zt_df[zt_df['代码'].isin(code_list)] if not ret_df.empty: tb_name_save = today + '_cx' excel_name = today + '_cx.xls' ret_df.to_excel(excel_name, encoding='gbk') ret_df.to_sql(tb_name_save, engine) s = ret_df[['代码', '名称', '涨停强度', '打开次数', '第一次涨停时间', '最后一次涨停时间']].to_string() sendmail(s, today + '次新涨停')
http://30daydo.com Contact: [email protected] ''' import tushare as ts import pandas as pd import os, datetime, time, Queue from 无用垃圾代码.toolkit import Toolkit from threading import Thread q = Queue.Queue() # 用来选股用的 pd.set_option('max_rows', None) from configure.settings import get_engine engine = get_engine('db_stock') # 缺陷: 暂时不能保存为excel class filter_stock(): def __init__(self, retry=5, local=False): if local: for i in range(retry): try: self.bases_save = ts.get_stock_basics() # print(self.bases_save) self.bases_save = self.bases_save.reset_index() self.bases_save.to_csv('bases.csv') self.bases_save.to_sql('bases', engine, if_exists='replace')
def __init__(self): self.engine = get_engine('db_stock', 'local') self.bonds = pd.read_sql('tb_bond_jisilu', con=self.engine)
# -*-coding=utf-8-*- __author__ = 'Rocky' ''' http://30daydo.com Contact: [email protected] 股市基本面 ''' from configure.settings import get_engine import tushare as ts engine = get_engine('db_finance_report') def year_report(year): df0 = ts.get_report_data(year, 4) df0.to_sql(str(year) + '_main', engine) df1 = ts.get_profit_data(year, 4) df1.to_sql(str(year) + '_profit', engine) df2 = ts.get_growth_data(year, 4) df2.to_sql(str(year) + '_growth', engine) df3 = ts.get_debtpaying_data(year, 4) df3.to_sql(str(year) + '_debtpaying', engine) df4 = ts.get_cashflow_data(year, 4) df4.to_sql(str(year) + '_cashflow', engine) def main(): for i in range(2010, 2018):