Created
June 7, 2014 01:25
-
-
Save mherod/fc6e519ea4cf237ebce5 to your computer and use it in GitHub Desktop.
A quick and dirty way to take yahoo printed contacts and convert them to a Google Contacts compatible CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
public class YahooPrintCSV { | |
public static void main(String[] args) { | |
BufferedReader reader = null; | |
BufferedWriter writer = null; | |
try { | |
reader = new BufferedReader(new FileReader("print.htm")); | |
writer = new BufferedWriter(new FileWriter("print.csv")); | |
writer.write("\"First\",\"Last\",\"Email\""); | |
writer.newLine(); | |
boolean nextLineName = false; | |
String firstName = ""; | |
String lastName = ""; | |
String line = null; | |
while ((line = reader.readLine()) != null) { | |
if (nextLineName) { | |
if (line.contains("<b>")) { | |
int q = line.indexOf("<b>"); | |
int w = line.indexOf("</b>"); | |
String g = line.substring(q + 3, w); | |
String[] names = g.split(" "); | |
firstName = names[1]; | |
for (int j = 0; j < names.length; j++) { | |
if (names[j].length() > 0) | |
lastName = names[j]; | |
} | |
//lastName = names[3]; | |
} | |
nextLineName = false; | |
} | |
if (line.contains("<td colspan=\"2\">")) { | |
nextLineName = true; | |
} | |
if (line.contains("@")) { | |
String[] emails = line.split("<div>"); | |
for (String e : emails) { | |
String[] emails2 = e.split("</div>"); | |
for (String e2 : emails2) { | |
if (e2.contains("@") && firstName.length() > 0) { | |
writer.write("\"" + firstName + "\",\"" | |
+ lastName + "\",\"" + e2 + "\""); | |
writer.newLine(); | |
} | |
} | |
} | |
} | |
// writer.write(line); | |
// writer.newLine(); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
reader.close(); | |
writer.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment