id: 9c06d43a01764a398559f617e0e5e54d
parent_id: 
item_type: 1
item_id: e339646ec95d457da20cba7bf5edcd20
item_updated_time: 1764345622513
title_diff: "[{\"diffs\":[[1,\"写个python脚本，每日自动下载大a所有股票行情\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":25}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>写个python脚本，每日自动下载大a所有股票行情</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"content-class\\\" content=\\\"yinxiang.peso.superNote\\\"/>\\\r\\\n  <meta name=\\\"application-data:yinxiang.noteLayout\\\" content=\\\"{\\\"lineSpace\\\":\\\"recommend\\\",\\\"paragraphSpace\\\":\\\"recommend\\\"}\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"38322\\\"></a>\\\r\\\n<h1>写个python脚本，每日自动下载大a所有股票行情</h1>\\\r\\\n\\\r\\\n<div><span style=\\\"\\\"><div style=\\\"max-width: 700px;\\\"><p></p><div style=\\\"--en-blockquote: true; box-sizing: border-box; border-left: 3px solid #b4c0cc; background-position: initial initial; background-repeat: initial initial;\\\"><div>原文链接: <a href=\\\"http://mp.weixin.qq.com/s?__biz=Mzg4OTUxMjQ5MQ==&amp;mid=2247484787&amp;idx=1&amp;sn=609bd87ed0bd911913b11de748670cf0&amp;chksm=ce4b010e768a52045df16095b145bc044752719a729e6eab03c368bba312132dc9b2cd03ee0b&amp;mpshare=1&amp;scene=1&amp;srcid=0318EgbYyMDrPYOPaTvretpS&amp;sharer_shareinfo=d14f5ba7b0310ede6db83ffe4cbb0f22&amp;sharer_shareinfo_first=d14f5ba7b0310ede6db83ffe4cbb0f22#rd\\\"><span>http://mp.weixin.qq.com/s?__biz=Mzg4OTUxMjQ5MQ==&amp;mid=2247484...</span></a></div></div><p></p><div style=\\\"\\\"><div><div><div><span style=\\\"\\\">原创</span><span><span style=\\\"\\\">小夜的生信笔记</span></span><span><a style=\\\"\\\"> 小夜的生信笔记 </a></span><span><em></em></span></div><div style=\\\"\\\"><div style=\\\"--en-blockquote: true; box-sizing: border-box; border-left: 4px solid rgb(221, 221, 221); color: rgb(119, 119, 119); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\\\"><p style=\\\"box-sizing: border-box; -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0; -webkit-margin-end: 0; width: inherit;\\\"><span style=\\\"box-sizing: border-box; display: block;\\\"><span style=\\\"box-sizing: border-box;\\\"><span>使用</span></span><span style=\\\"box-sizing: border-box;\\\"><code style=\\\"box-sizing: border-box; text-align: left; border: 1px solid rgb(221, 221, 221); background-color: rgb(248, 248, 248); border-radius: 3px;\\\"><span>baostock</span></code></span><span style=\\\"box-sizing: border-box;\\\"><span>每日自动下载大a所有股票的当天的数据，以便用到时直接调取。</span></span></span></p></div><p style=\\\"box-sizing: border-box; -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0; -webkit-margin-end: 0; width: inherit; color: rgb(51,51,51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0; -webkit-text-stroke-width: 0; text-decoration-style: initial; text-decoration-color: initial;\\\"><span style=\\\"box-sizing: border-box; display: block;\\\"><span style=\\\"box-sizing: border-box;\\\"><span>因为</span></span><span style=\\\"box-sizing: border-box;\\\"><code style=\\\"box-sizing: border-box; text-align: left; border: 1px solid rgb(221, 221, 221); background-color: rgb(248, 248, 248); border-radius: 3px;\\\"><span>baostock</span></code></span><span style=\\\"box-sizing: border-box;\\\"><span>接口使用多线程或者多协程会被封，所以只能是遍历所有股票，一个个的下载,大概半个小时，共5616支股票。</span></span></span></p><div lang=\\\"python\\\" style=\\\"white-space: pre-wrap; box-sizing: border-box; overflow: visible; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(221, 221, 221); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\\\"><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>import</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>asyncio</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>import</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>baostock</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>as</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>bs</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>import</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>pandas</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>as</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>pd</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>import</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>os</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>import</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>time</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>import</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>datetime</span></span></span><br/><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 登录 baostock</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>def</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 255);\\\"><span>login_baostock</span></span><span>():</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>lg</span></span><span> = </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>bs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>login</span></span><span>()</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>if</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>lg</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>error_code</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(152, 26, 26);\\\"><span>!</span></span><span>= </span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'0'</span></span><span>:</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(51, 0, 170);\\\"><span>print</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>f&quot;登录失败，错误代码: {lg.error_code}，错误信息: {lg.error_msg}&quot;</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>return</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>False</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>return</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>True</span></span></span><br/><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 获取所有股票代码</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>def</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 255);\\\"><span>get_all_stock_codes</span></span><span>():</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span> = </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>bs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>query_all_stock</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>day</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>datetime</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>date</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>today</span></span><span>().</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>strftime</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'%Y-%m-%d'</span></span><span>))</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>if</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>error_code</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(152, 26, 26);\\\"><span>!</span></span><span>= </span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'0'</span></span><span>:</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(51, 0, 170);\\\"><span>print</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>f&quot;获取股票列表失败，错误代码: {rs.error_code}，错误信息: {rs.error_msg}&quot;</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>return</span></span><span> []</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>data_list</span></span><span> = []</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>while</span></span><span> (</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>error_code</span></span><span> == </span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'0'</span></span><span>) </span><span style=\\\"box-sizing: border-box; color: rgb(152, 26, 26);\\\"><span>&amp;</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>next</span></span><span>():</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>data_list</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>append</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>get_row_data</span></span><span>())</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span><span> = </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>pd</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>DataFrame</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>data_list</span></span><span>, </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>columns</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>fields</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_codes</span></span><span> = </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span><span>[</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span><span>[</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'tradeStatus'</span></span><span>] == </span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'1'</span></span><span>][</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'code'</span></span><span>].</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>tolist</span></span><span>()</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>return</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_codes</span></span></span><br/><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 下载单只股票数据</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>def</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 255);\\\"><span>download_stock_data</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_code</span></span><span>,</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>start_date</span></span><span>,</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>end_date</span></span><span>):</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span> = </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>bs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>query_history_k_data_plus</span></span><span>(</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_code</span></span><span>,</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>&quot;date,code,open,high,low,close,preclose,volume,amount,adjustflag,turn,tradestatus,pctChg,isST&quot;</span></span><span>,</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>start_date</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>start_date</span></span><span>,</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>end_date</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>end_date</span></span><span>,</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>frequency</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>&quot;d&quot;</span></span><span>,</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>adjustflag</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>&quot;3&quot;</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span>    )</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>if</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>error_code</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(152, 26, 26);\\\"><span>!</span></span><span>= </span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'0'</span></span><span>:</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(51, 0, 170);\\\"><span>print</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>f&quot;下载 {stock_code} 数据失败，错误代码: {rs.error_code}，错误信息: {rs.error_msg}&quot;</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>return</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>None</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>data_list</span></span><span> = []</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>while</span></span><span> (</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>error_code</span></span><span> == </span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'0'</span></span><span>) </span><span style=\\\"box-sizing: border-box; color: rgb(152, 26, 26);\\\"><span>&amp;</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>next</span></span><span>():</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>data_list</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>append</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>get_row_data</span></span><span>())</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span><span> = </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>pd</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>DataFrame</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>data_list</span></span><span>, </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>columns</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>rs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>fields</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>return</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span></span><br/><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 单线程下载所有股票数据</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>def</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 255);\\\"><span>download_all_stocks</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>start_date</span></span><span>,</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>end_date</span></span><span>):</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>if</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>not</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>login_baostock</span></span><span>():</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>return</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_codes</span></span><span> = </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>get_all_stock_codes</span></span><span>()</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>tasks</span></span><span> = []</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>for</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_code</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>in</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_codes</span></span><span>:</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 如果已经有之前的数据存在，则追加当天的信息</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>if</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>os</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>path</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>exists</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>f&quot;all_stock/{stock_code}.csv&quot;</span></span><span>):</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>download_stock_data</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_code</span></span><span>,</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>end_date</span></span><span>,</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>end_date</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>to_csv</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>f&quot;all_stock/{stock_code}.csv&quot;</span></span><span>, </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>mode</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'a'</span></span><span>, </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>header</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>False</span></span><span>,</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>index</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>False</span></span><span>,)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 如果数据不存在，则从指定开始，下载到当天的数据信息</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>else</span></span><span>:</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>download_stock_data</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>stock_code</span></span><span>,</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>start_date</span></span><span>,</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>end_date</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>df</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>to_csv</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>f&quot;all_stock/{stock_code}.csv&quot;</span></span><span>, </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>index</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>False</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 注销登录</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>bs</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>logout</span></span><span>()</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(119, 0, 136);\\\"><span>if</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>__name__</span></span><span> == </span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>&quot;__main__&quot;</span></span><span>:</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 获得当天的日期</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>today</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>datetime</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>date</span></span><span>.</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>today</span></span><span>().</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>strftime</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'%Y-%m-%d'</span></span><span>)</span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 设置开始时间</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>start_time</span></span><span>=</span><span style=\\\"box-sizing: border-box; color: rgb(170, 17, 17);\\\"><span>'2020-01-01'</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span></span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>download_all_stocks</span></span><span>(</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>start_time</span></span><span>,</span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 0);\\\"><span>today</span></span><span>)</span></span></div><p style=\\\"box-sizing: border-box; -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0; -webkit-margin-end: 0; width: inherit; color: rgb(51,51,51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0; -webkit-text-stroke-width: 0; text-decoration-style: initial; text-decoration-color: initial;\\\"><span style=\\\"box-sizing: border-box; display: block;\\\"><span style=\\\"box-sizing: border-box;\\\"><span>在</span></span><span style=\\\"box-sizing: border-box;\\\"><code style=\\\"box-sizing: border-box; text-align: left; border: 1px solid rgb(221, 221, 221); background-color: rgb(248, 248, 248); border-radius: 3px;\\\"><span>linux</span></code></span><span style=\\\"box-sizing: border-box;\\\"><span>服务器上，设置定时任务：</span></span></span></p><div lang=\\\"bash\\\" style=\\\"white-space: pre-wrap; box-sizing: border-box; overflow: visible; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(221, 221, 221); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;\\\"><br/><span style=\\\"box-sizing: border-box;\\\"><span>crontab </span><span style=\\\"box-sizing: border-box; color: rgb(0, 0, 204);\\\"><span>-e</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 修改定时任务为</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(170, 85, 0);\\\"><span># 每天3点半进行自动下载</span></span></span><br/><span style=\\\"box-sizing: border-box;\\\"><span style=\\\"box-sizing: border-box; color: rgb(17, 102, 68);\\\"><span>30</span></span><span></span><span style=\\\"box-sizing: border-box; color: rgb(17, 102, 68);\\\"><span>15</span></span><span> * * * python down.py</span></span></div><p style=\\\"box-sizing: border-box; -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0; -webkit-margin-end: 0; width: inherit; color: rgb(51,51,51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0; -webkit-text-stroke-width: 0; text-decoration-style: initial; text-decoration-color: initial;\\\"><span style=\\\"box-sizing: border-box; display: block;\\\"><span style=\\\"box-sizing: border-box; word-break: break-all; min-width: 10px; min-height: 10px; width: 800px; text-align: center;\\\"><span><img src=\\\":/0498bc177e774d158e191c5c58e71c6f\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" style=\\\"--en-marks: %7B%22align%22%3A%22center%22%7D; box-sizing: border-box; border-width: 0px 4px 0px 2px; border-top-style: initial; border-right-style: solid; border-bottom-style: initial; border-left-style: solid; border-top-color: initial; border-right-color: transparent; border-bottom-color: initial; border-left-color: transparent; border-image: initial; vertical-align: middle; max-width: 100%; cursor: default; width: auto;\\\" width=\\\"auto\\\"/></span></span></span></p><p style=\\\"box-sizing: border-box; -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0; -webkit-margin-end: 0; width: inherit; color: rgb(51,51,51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0; -webkit-text-stroke-width: 0; text-decoration-style: initial; text-decoration-color: initial;\\\"><span style=\\\"box-sizing: border-box; display: block;\\\"><span><br/></span></span></p></div></div></div></div></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":32956}]"
metadata_diff: {"new":{"id":"e339646ec95d457da20cba7bf5edcd20","parent_id":"f67288c3a0be4374b5d532b5dcc3aabc","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764348836928,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T21:04:09.051Z
created_time: 2025-11-28T21:04:09.051Z
type_: 13