save all eligible stock codes
This commit is contained in:
parent
014d9ce92c
commit
b5832e40f0
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.db
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
||||
113
data/adata.ipynb
Normal file
113
data/adata.ipynb
Normal file
@ -0,0 +1,113 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import adata\n",
|
||||
"\n",
|
||||
"res_df = adata.stock.info.all_code()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sqlite3\n",
|
||||
"\n",
|
||||
"conn = sqlite3.connect('big-a.db')\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"5661"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"res_df.to_sql('all_code', con=conn, if_exists='replace', index=False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"no_exit = res_df['short_name'].map(lambda x: not x.endswith('退'))\n",
|
||||
"have_date = res_df['list_date'].map(lambda x: not (not x))\n",
|
||||
"no_st = res_df['short_name'].map(lambda x: 'ST' not in x)\n",
|
||||
"no_pt = res_df['short_name'].map(lambda x: 'PT' not in x)\n",
|
||||
"\n",
|
||||
"filtered = res_df[no_exit & no_st & no_pt & res_df['list_date'].notnull()]\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"5255"
|
||||
]
|
||||
},
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"filtered.to_sql('all_code', con=conn, if_exists='replace', index=False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas\n",
|
||||
"\n",
|
||||
"local = pandas.read_sql_table('all_code', con='sqlite:///big-a.db', parse_dates=['list_date'])"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "big-a",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.13.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
15
data/save_all_eligible_code.py
Normal file
15
data/save_all_eligible_code.py
Normal file
@ -0,0 +1,15 @@
|
||||
import adata
|
||||
import sqlite3
|
||||
|
||||
conn = sqlite3.connect('big-a.db')
|
||||
res_df = adata.stock.info.all_code()
|
||||
|
||||
no_exit = res_df['short_name'].map(lambda x: not x.endswith('退'))
|
||||
have_date = res_df['list_date'].map(lambda x: not (not x))
|
||||
no_st = res_df['short_name'].map(lambda x: 'ST' not in x)
|
||||
no_pt = res_df['short_name'].map(lambda x: 'PT' not in x)
|
||||
|
||||
filtered = res_df[no_exit & no_st & no_pt & res_df['list_date'].notnull()]
|
||||
filtered.to_sql('all_code', con=conn, if_exists='replace', index=False)
|
||||
|
||||
print('Done')
|
||||
@ -3,3 +3,5 @@ ruff
|
||||
granian
|
||||
fastapi[standard]
|
||||
orjson>=3.10,<4
|
||||
adata
|
||||
sqlalchemy
|
||||
|
||||
Loading…
Reference in New Issue
Block a user