用seatable做了一个股票的模块,想实现通过内置的脚本用python自动爬取个股的今年和明年的每股收益数据,对应表格内的“年初EPS”和“年末EPS”。并实现自动更新。我把seatable共享出来https://cloud.seatable.cn/dtable/links/634e748fbd66436d8411
以下是我弄的错误代码,帮忙看看。
用seatable做了一个股票的模块,想实现通过内置的脚本用python自动爬取个股的今年和明年的每股收益数据,对应表格内的“年初EPS”和“年末EPS”。并实现自动更新。我把seatable共享出来https://cloud.seatable.cn/dtable/links/634e748fbd66436d8411
以下是我弄的错误代码,帮忙看看。
from seatable_api import Base, context
import requests
API_TOKEN = context.api_token
SERVER_URL = context.server_url
STOCK_BASE_URL = 'https://api.arvinx.com/api/stocks'
TABLE_NAME = "股票"
VIEW_NAME =None
con fetchEPS = async (code) => {
const res = await remoteFetchAsync(${BASE_URL}/${code}/eps
);
const data = await res.json()
if (data.success) {
return data.data
}
}
/**
更新股票 EPS
/
const updateStockEPS = async () => {
const table = base.getTable("股票");
// @ts-ignore
// const view = table.getView("大金融");
const view = table.getView("A股清单");
const query = await view.selectRecordsAsync();
const fetchPromise = query.records.map(async (record) => {
const code = record.getCellValueAsString("代码")
const name = record.getCellValueAsString("股票名称")
// 如果没 code 则结束
if (!code) return;
const data = await fetchEPS(code);
console.log(`开始更新${name}的EPS`);
await table.updateRecordAsync(record, {
"年初 EPS": data.yearStart,
"年末 EPS": data.yearEnd
})
console.log(`${name}更新完毕`);
})
await Promise.all(fetchPromise)
}
console.log('开始更新股票EPS...');
await updateStockEPS()
console.log('更新完成!');