Skip to content

Commit

Permalink
Merge branch 'initial-release'
Browse files Browse the repository at this point in the history
Resolved conflict in .gitignore and merged pre-release changes into
main.#
  • Loading branch information
ad0mb committed Sep 7, 2024
2 parents fa2251b + 9131853 commit 1bf81f7
Show file tree
Hide file tree
Showing 26 changed files with 1,292 additions and 0 deletions.
76 changes: 76 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<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>Projects</groupId>
<artifactId>Scrapers</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Scrapers</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>22</maven.compiler.source> <!-- Ensure this matches your Java version -->
<maven.compiler.target>22</maven.compiler.target>
</properties>

<dependencies>
<!-- JUnit dependency for testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<!-- Selenium dependency -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.23.1</version>
</dependency>

<!-- Gson dependency -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>

<build>
<plugins>

<!-- Maven Assembly Plugin to create a runnable JAR with dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<!-- Replace with the fully qualified name of your main class -->
<mainClass>Projects.StartGUI</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package CourtScraper.DataManagement.CSV;

import java.io.FileWriter;
import java.io.IOException;


public class CSVDownloadedAppend {

public static void appendToDownloaded(String row) throws IOException {
FileWriter csvFile = new FileWriter(CourtScraper.Helpers.CheckIfRetrieved.downloadedFilePath, true);

csvFile.append("\n");
csvFile.append(row);

csvFile.flush();
csvFile.close();
}
}
38 changes: 38 additions & 0 deletions src/Projects/CourtScraper/DataManagement/CSV/CSVManagement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package CourtScraper.DataManagement.CSV;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public class CSVManagement {

//path to be used for accessing temp file


public static void deleteLine(String tempFilePath, String tempFolderPath, String line) throws IOException {
File newTempFile = new File(tempFolderPath + "\\temp2temp.csv");
newTempFile.createNewFile();
File oldTempFile = new File(tempFilePath);

FileWriter writer = new FileWriter(tempFolderPath + "\\temp2temp.csv");

List<String> rows = Files.readAllLines(Path.of(tempFilePath));

for (String row : rows) {
if (row.equals(line)) {
continue;
}
writer.write(row + "\n");
}

writer.flush();
writer.close();

oldTempFile.delete();
newTempFile.renameTo(oldTempFile);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package CourtScraper.DataManagement.CSV;

import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import static CourtScraper.Flows.Courtlink.CourtlinkSearchConfig.CourtlinkSearchConfigMain.processedInputs;
import static CourtScraper.Setups.GUI.MainPanelElements.MainComboBoxes.selectedCounty;
import static CourtScraper.Setups.GUI.MainPanelElements.MainComboBoxes.selectedState;


public class CSVSearchAppendTemp {

public static String tempFilePath = "C:\\Users\\" + System.getenv("USERNAME") + "\\Desktop\\Courtlink Scraper\\States\\" + selectedState + "\\" + selectedCounty + "\\temp.csv";

//declarations of current date and time
private static SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
private Date date = new Date();

public void courtLinkAppendToTemp(List<String> toBeAppended) throws IOException {

String appendableString = "";

FileWriter csvFile = new FileWriter(tempFilePath, true);

//adds case number and date of case filed from the courtlink site
for (String element : toBeAppended) {
appendableString += element.substring(1) + ",";
}

//adds keywords used in search
appendableString += processedInputs[0] + ",";
//adds attorney terms used in search
appendableString += processedInputs[1] + ",";
//adds current date and time from which the document was grabbed from
appendableString += dateFormat.format(date) + ",";
//adds selected state
appendableString += selectedState + ",";
//added selected county
appendableString += selectedCounty + ",";
//adds documents selected
appendableString += "" + ",";


csvFile.append("\n");
csvFile.append(appendableString.substring(0, appendableString.length() - 1));

csvFile.flush();
csvFile.close();
}
}
23 changes: 23 additions & 0 deletions src/Projects/CourtScraper/FlowStart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package CourtScraper;

import CourtScraper.Flows.Courtlink.CourtlinkMain;
import CourtScraper.Setups.Browser.Firefox;

import java.io.IOException;



public class FlowStart {

public static void StartMainFlowButton() throws IOException, InterruptedException {

new Firefox().FirefoxLaunch();
new CourtlinkMain().CourtlinkFlow();

//closes all open tabs
CourtScraper.Helpers.TabManagement.closeAllTabs();

CourtScraper.Flows.States.StateParser.stateRetrievalFlow();

}
}
44 changes: 44 additions & 0 deletions src/Projects/CourtScraper/Flows/Courtlink/CourtlinkMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package CourtScraper.Flows.Courtlink;

import CourtScraper.Flows.Courtlink.CourtlinkScraper.CourtlinkScrapeMain;
import CourtScraper.Helpers.ConfigGrabbers;
import CourtScraper.StartGUI;
import org.openqa.selenium.By;

import java.io.FileNotFoundException;
import java.io.IOException;


import static CourtScraper.Flows.Courtlink.CourtlinkSearchConfig.CourtlinkSearchConfigMain.courtLinkTermInputs;

public class CourtlinkMain {

public void CourtlinkFlow() throws IOException, InterruptedException {
//Login process
courtLinkLogin();

Thread.sleep(1000);

//inputs terms/dates into input boxes
courtLinkTermInputs();

Thread.sleep(1000);

//scrapes courtlink for casenumbers
CourtlinkScrapeMain.courtLinkScrape();


}


public static void courtLinkLogin() throws FileNotFoundException, InterruptedException {
StartGUI.driver.get("https://signin.lexisnexis.com/lnaccess/app/signin?back=https%3A%2F%2Fadvance.lexis.com%3A443%2Fcourtlinkhome&aci=la");
String[] credentials = new ConfigGrabbers().loginGrabber("courtlink");

StartGUI.driver.findElement(By.xpath("//*[@id=\"userid\"]")).sendKeys(credentials[0]);
StartGUI.driver.findElement(By.xpath("//*[@id=\"signInSbmtBtn\"]")).click();
Thread.sleep(1500);
StartGUI.driver.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys(credentials[1]);
StartGUI.driver.findElement(By.xpath("//*[@id=\"signInSbmtBtn\"]")).click();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package CourtScraper.Flows.Courtlink.CourtlinkScraper;

import CourtScraper.DataManagement.CSV.CSVSearchAppendTemp;
import CourtScraper.Flows.Courtlink.CourtlinkMain;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

import static CourtScraper.StartGUI.driver;


public class CourtlinkScrapeMain extends CourtlinkMain {

private static WebDriverWait wait;
private static int numCases = Integer.valueOf(driver.findElement(By.xpath("/html/body/main/div/main/div[2]/div/div[1]/div/div[1]/ul/li[1]")).getAttribute("data-actualresultscount"));

public static void courtLinkScrape() throws IOException, InterruptedException {
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Thread.sleep(500);
System.out.println(numCases);
driver.findElement(By.xpath("//*[@id=\"title_sr0\"]")).click();
//waits until first page is loaded
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"Header\"]")));

//Grabs Case Info
for (int i = numCases-1; !(i == 0); i--) {
//grabs info on page
new CourtlinkScrapeMain().grabCaseInfo();
Thread.sleep(2000);

//grabs url for later next page loaded check
String url = driver.getCurrentUrl();

//clicks next button to move on to the next case
driver.findElement(By.xpath("/html/body/main/div/main/div/form/div[1]/div[1]/ul[3]/li/button[2]/span[1]")).click();

//ends if on last page to prevent stoppage and grabs last case before stopping
if (i==1) {
new CourtlinkScrapeMain().grabCaseInfo();
Thread.sleep(2000);
break;
}
//waits until next page loaded
wait.until(ExpectedConditions.not(ExpectedConditions.urlToBe(url)));
Thread.sleep(500);


}
}

public void grabCaseInfo() throws IOException {
List<String> toBeAppended = new ArrayList<>();

//inner text retrieves text not html from the inside and splits it

String caseInfo = driver.findElement(By.xpath("//*[@id=\"Header\"]")).getAttribute("innerText");
String[] info = caseInfo.split("\n");

//adds the case number and date filed in a loop
for (int i = 1; i<3; i++) {
String[] elements = info[i].split(":", 2);
toBeAppended.add(elements[1].trim());
}
//adds them to temporary csv file
new CSVSearchAppendTemp().courtLinkAppendToTemp(toBeAppended);

}
}
Loading

0 comments on commit 1bf81f7

Please sign in to comment.