This commit is contained in:
Elijah McMorris 2023-06-13 07:59:46 +00:00
parent 9107445cae
commit bc28230cbe
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
4 changed files with 33 additions and 30 deletions

View file

@ -15,3 +15,6 @@ RUN BTOP_VERSION=$(curl -s "https://api.github.com/repos/aristocratos/btop/relea
sudo tar -xvf btop-x86_64-linux-musl.tbz && \ sudo tar -xvf btop-x86_64-linux-musl.tbz && \
cd btop && ./install.sh && cd .. && \ cd btop && ./install.sh && cd .. && \
rm -rf btop-x86_64-linux-musl.tbz btop rm -rf btop-x86_64-linux-musl.tbz btop
RUN curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
# cargo install cargo-nextest --locked

View file

@ -14,6 +14,7 @@
"--name", "--name",
"devcontainer-${containerWorkspaceFolderBasename}" "devcontainer-${containerWorkspaceFolderBasename}"
], ],
"initializeCommand": "docker rm -f devcontainer-${containerWorkspaceFolderBasename} || true",
// Use 'mounts' to make the cargo cache persistent in a Docker Volume. // Use 'mounts' to make the cargo cache persistent in a Docker Volume.
"mounts": [ "mounts": [
{ {
@ -60,7 +61,6 @@
"Gruntfuggly.todo-tree", "Gruntfuggly.todo-tree",
"ms-azuretools.vscode-docker", "ms-azuretools.vscode-docker",
"redhat.vscode-yaml", "redhat.vscode-yaml",
"tomoki1207.pdf",
"GitHub.copilot" "GitHub.copilot"
] ]
} }

View file

@ -1,4 +1,2 @@
https://ark-funds.com/ark-trade-notifications/ https://ark-funds.com/ark-trade-notifications/
https://etfs.ark-funds.com/hubfs/idt/trades/ARK_Trade_06072023_0800PM_EST_6480efd1294b5.xls https://etfs.ark-funds.com/hubfs/idt/trades/ARK_Trade_06072023_0800PM_EST_6480efd1294b5.xls

View file

@ -248,7 +248,7 @@ pub fn get_api(ticker: Ticker, last_day: Option<i32>) -> Result<LazyFrame, Box<d
format!("https://api.nexveridian.com/ark_holdings?ticker={}", ticker) format!("https://api.nexveridian.com/ark_holdings?ticker={}", ticker)
} }
}; };
get_data_url(url, Reader::Json) Reader::Json.get_data_url(url)
} }
pub fn get_csv_ark(ticker: Ticker) -> Result<LazyFrame, Box<dyn Error>> { pub fn get_csv_ark(ticker: Ticker) -> Result<LazyFrame, Box<dyn Error>> {
@ -256,7 +256,7 @@ pub fn get_csv_ark(ticker: Ticker) -> Result<LazyFrame, Box<dyn Error>> {
Ticker::ARKVC => "https://ark-ventures.com/wp-content/uploads/funds-etf-csv/ARK_VENTURE_FUND_HOLDINGS.csv".to_owned(), Ticker::ARKVC => "https://ark-ventures.com/wp-content/uploads/funds-etf-csv/ARK_VENTURE_FUND_HOLDINGS.csv".to_owned(),
_ => format!("https://ark-funds.com/wp-content/uploads/funds-etf-csv/ARK_{}_ETF_{}_HOLDINGS.csv", ticker.value(), ticker), _ => format!("https://ark-funds.com/wp-content/uploads/funds-etf-csv/ARK_{}_ETF_{}_HOLDINGS.csv", ticker.value(), ticker),
}; };
get_data_url(url, Reader::Csv) Reader::Csv.get_data_url(url)
} }
pub enum Reader { pub enum Reader {
@ -264,34 +264,36 @@ pub enum Reader {
Json, Json,
} }
pub fn get_data_url(url: String, reader: Reader) -> Result<LazyFrame, Box<dyn Error>> { impl Reader {
let response = Client::builder() pub fn get_data_url(&self, url: String) -> Result<LazyFrame, Box<dyn Error>> {
let response = Client::builder()
.user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3") .user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3")
.build()?.get(url).send()?; .build()?.get(url).send()?;
if !response.status().is_success() { if !response.status().is_success() {
return Err(format!( return Err(format!(
"HTTP request failed with status code: {:?}", "HTTP request failed with status code: {:?}",
response.status() response.status()
) )
.into()); .into());
}
let data = response.text()?.into_bytes();
let df = match reader {
Reader::Csv => CsvReader::new(Cursor::new(data))
.has_header(true)
.finish()?
.lazy(),
Reader::Json => {
let json_string = String::from_utf8(data)?;
let json: Value = serde_json::from_str(&json_string)?;
JsonReader::new(Cursor::new(json.to_string()))
.finish()?
.lazy()
} }
};
Ok(df) let data = response.text()?.into_bytes();
let df: LazyFrame = match self {
Self::Csv => CsvReader::new(Cursor::new(data))
.has_header(true)
.finish()?
.lazy(),
Self::Json => {
let json_string = String::from_utf8(data)?;
let json: Value = serde_json::from_str(&json_string)?;
JsonReader::new(Cursor::new(json.to_string()))
.finish()?
.lazy()
}
};
Ok(df)
}
} }