Skip to content

Commit

Permalink
Merge pull request #5 from GFalcon-UA/v-0.1.2
Browse files Browse the repository at this point in the history
chore: javadoc and update versions
  • Loading branch information
oleksii-khalikov authored Apr 14, 2024
2 parents 5177ba1 + a52ff22 commit 25dc24d
Show file tree
Hide file tree
Showing 36 changed files with 1,271 additions and 73 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Oleksii Khalikov (GFalcon-UA)
Copyright (c) 2023-2024 Oleksii Khalikov (GFalcon-UA)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
49 changes: 38 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ MIT License
~ -----------
~
~ Copyright (c) 2016-2024 Oleksii V. KHALIKOV (http://gfalcon.com.ua)
~ Permission is hereby granted, free of charge, to any person
~ obtaining a copy of this software and associated documentation
~ files (the "Software"), to deal in the Software without
~ restriction, including without limitation the rights to use,
~ copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the
~ Software is furnished to do so, subject to the following
~ conditions:
~
~ The above copyright notice and this permission notice shall be
~ included in all copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
~ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
~ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
~ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
~ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
~ OTHER DEALINGS IN THE SOFTWARE.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ua.com.gfalcon</groupId>
<artifactId>finviz-api</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>

<name>Finviz API (unofficial)</name>
<description>API for scraping stocks data from finviz.com</description>
Expand All @@ -21,21 +48,15 @@
<ossindex.fail>true</ossindex.fail>

<commons-collections4.version>4.4</commons-collections4.version>
<htmlunit.version>3.0.0</htmlunit.version>
<jsoup.version>1.15.4</jsoup.version>
<junit-jupiter.version>5.9.2</junit-jupiter.version>
<jsoup.version>1.17.2</jsoup.version>
<junit-jupiter.version>5.10.2</junit-jupiter.version>
<maven-version-ruleset.version>1.1.0</maven-version-ruleset.version>
<opencsv.version>5.7.1</opencsv.version>
<opencsv.version>5.9</opencsv.version>
<ossindex-maven-plugin.version>3.2.0</ossindex-maven-plugin.version>
<slf4j-api.version>2.0.7</slf4j-api.version>
<slf4j-api.version>2.0.12</slf4j-api.version>
</properties>

<dependencies>
<dependency>
<groupId>org.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>${htmlunit.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -213,6 +234,12 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven-central</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<distributionManagement>
<snapshotRepository>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
/*
* MIT License
* -----------
*
* Copyright (c) 2016-2024 Oleksii V. KHALIKOV (http://gfalcon.com.ua)
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package ua.com.gfalcon.finviz.exception;

/**
* FinvizApiException is a subclass of RuntimeException that is thrown when an error occurs while using the Finviz API.
* It is used to wrap any exceptions that occur during API usage and provide more specific information about the error.
* <p/>
* This class provides several constructors to handle different scenarios
* and allows the exception message and underlying cause to be specified.
*/
public class FinvizApiException extends RuntimeException {

public FinvizApiException() {
Expand Down
43 changes: 40 additions & 3 deletions src/main/java/ua/com/gfalcon/finviz/overview/Stock.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/*
* MIT License
* -----------
*
* Copyright (c) 2016-2024 Oleksii V. KHALIKOV (http://gfalcon.com.ua)
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package ua.com.gfalcon.finviz.overview;

import java.io.IOException;
Expand All @@ -11,6 +38,9 @@

import ua.com.gfalcon.finviz.exception.FinvizApiException;

/**
* The Stock class represents stock ticker information retrieved from Finviz.
*/
public class Stock {

//<editor-fold desc="Variables">
Expand Down Expand Up @@ -104,9 +134,11 @@ public class Stock {
* @param ticker ticker of the company
* @throws FinvizApiException when ticker cannot be found on Finviz
*/
@SuppressWarnings("checkstyle:MethodLength")
public Stock(String ticker) {
Document doc = getStockInfo(ticker);
if (doc.getElementById("ticker") != null) {
if (!doc.getElementsByAttribute("data-ticker")
.isEmpty()) {
Elements elements = doc.select("a.tab-link");
this.ticker = Optional.ofNullable(doc.getElementById("ticker"))
.orElse(new Element("div"))
Expand Down Expand Up @@ -268,7 +300,7 @@ public Stock(String ticker) {
.get(0)
.text());
} else {
throw new FinvizApiException("This ticker cannot be found");
throw new FinvizApiException("This ticker " + ticker + " cannot be found");
}
}

Expand Down Expand Up @@ -625,8 +657,13 @@ public List<String> getStringArr() {
this.sma20, this.sma50, this.sma200, this.volume, this.change);
}


/**
* @return all stock variables
* Returns a string representation of the Stock object.
* The string includes all the attributes of the Stock object,
* formatted as key-value pairs separated by newlines.
*
* @return a string representation of the Stock object
*/
@Override
public String toString() {
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/ua/com/gfalcon/finviz/overview/Stocks.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/*
* MIT License
* -----------
*
* Copyright (c) 2016-2024 Oleksii V. KHALIKOV (http://gfalcon.com.ua)
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package ua.com.gfalcon.finviz.overview;

import java.io.IOException;
Expand All @@ -9,12 +36,16 @@

import ua.com.gfalcon.finviz.exception.FinvizApiException;

/**
* The Stocks class represents a collection of stocks.
* It provides methods to add, retrieve, and check the presence of stocks.
*/
public class Stocks {

private final List<Stock> stocksList;

/**
* Uses a text file with tickers on a new line
* Uses a text file with tickers on a new line.
*
* @param path text file with stocks
* @throws FinvizApiException if unable to find ticker
Expand All @@ -35,7 +66,7 @@ public Stocks(Path path) {
}

/**
* Adds multiple stocks to list
* Adds multiple stocks to list.
* <br>
* {@code
* Stocks stocks = new Stocks("MSFT", "AAPL", "TSLA");
Expand Down Expand Up @@ -67,7 +98,7 @@ public List<Stock> getStocks() {
}

/**
* Adds stock to Stocks list
* Adds stock to Stocks list.
*
* @param stock stock to add
* @return true if stock is added
Expand All @@ -81,7 +112,7 @@ public boolean addStock(Stock stock) {
}

/**
* Adds stock to Stocks list
* Adds stock to Stocks list.
*
* @param stocks stock to add
*/
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/ua/com/gfalcon/finviz/overview/StocksUtilities.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/*
* MIT License
* -----------
*
* Copyright (c) 2016-2024 Oleksii V. KHALIKOV (http://gfalcon.com.ua)
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package ua.com.gfalcon.finviz.overview;

import java.io.File;
Expand All @@ -15,6 +42,9 @@

import ua.com.gfalcon.finviz.exception.FinvizApiException;

/**
* The StocksUtilities class provides utility methods for working with Stocks objects.
*/
public class StocksUtilities {

private static final Logger LOG = LoggerFactory.getLogger(StocksUtilities.class);
Expand Down Expand Up @@ -81,8 +111,8 @@ public static void outputToCSV(Stocks stocks, File file) {
* Export.outputToCSV(stocks, System.getProperty("user.home") + "/Desktop/output.csv");
* }
*
* @param stock Stock to output
* @param file Absolute file path of CSV file
* @param stock Stock to output
* @param file Absolute file path of CSV file
*/
public static void outputToCSV(Stock stock, File file) {
if (file.getParentFile()
Expand Down
Loading

0 comments on commit 25dc24d

Please sign in to comment.