Skip to content

Instantly share code, notes, and snippets.

@Maxcloud
Last active May 17, 2017 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maxcloud/0f831873a7600fce36ed4b6ac0c296e0 to your computer and use it in GitHub Desktop.
Save Maxcloud/0f831873a7600fce36ed4b6ac0c296e0 to your computer and use it in GitHub Desktop.
This is temporary, some values are static for now.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Main {
/**
* The contents of 'file.txt' can be found here (https://pastebin.com/1hGW3mmM)
* @param args
*/
public static void main(String[] args) {
BufferedReader br = null;
FileReader fr = null;
try {
fr = new FileReader("C:\\file.txt");
br = new BufferedReader(fr);
String sLine;
String sql = "INSERT INTO marvel_prizes (`Item_name`, `ItemID`, `quantity`, `GroupID`, `item_idx`, `image`)";
while ((sLine = br.readLine()) != null) {
System.out.printf(sql + " VALUES('%s', '1000000', '11', 'A', '%s', '%s'); \r\n",
getTitle(sLine), getDataId(sLine), getImage(sLine));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
/**
* Return the name and extension of the image.
* @param sLine
* @return
*/
public static String getImage(String sLine) {
int start = sLine.indexOf("items/") + 6;
int end = sLine.indexOf("')");
return sLine.substring(start, end);
}
/**
* Return the title of the item.
* @param sLine
* @return
*/
public static String getTitle(String sLine) {
int start = sLine.indexOf("title=") + 7;
int end = sLine.indexOf("data") - 2;
String nLine = sLine.substring(start, end);
nLine = nLine.replace("%5b", "[");
nLine = nLine.replace("%5d", "]");
return nLine;
}
/**
* Return the data-index of the item.
* @param sLine
* @return
*/
public static String getDataId(String sLine) {
int start = sLine.indexOf("data-idx=") + 10;
int end = sLine.indexOf("</div>") - 2;
return sLine.substring(start, end);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment