Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix online dump downloads for the various modes and Closes #869 #872

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wikidata.wdtk.dumpfiles.wmf;

import java.io.BufferedReader;

/*
* #%L
* Wikidata Toolkit Dump File Handling
Expand All @@ -22,6 +24,9 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -115,9 +120,30 @@

@Override
protected boolean fetchIsDone() {
// WMF provides no easy way to check this for these files;
// so just assume it is done
return true;
boolean result = false;
String fileName = WmfDumpFile.getDumpFileName(DumpContentType.JSON,
this.projectName, this.dateStamp);
try (InputStream in = this.webResourceFetcher
.getInputStreamForUrl(getBaseUrl())) {
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(in, StandardCharsets.UTF_8));
String inputLine;
while ((inputLine = bufferedReader.readLine()) != null) {
System.out.println(inputLine);
if (inputLine.startsWith("<a href=")) {
System.out.println(inputLine);
inputLine = inputLine.replaceAll(".*href=\"(.*?)\".*", "$1");
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
System.out.println(inputLine);
if (inputLine.equals(fileName)) {
return true;
}
}
}
bufferedReader.close();
} catch (IOException e) { // file not found or not readable
result = false;
}
return result;
}

/**
Expand All @@ -127,7 +153,7 @@
*/
String getBaseUrl() {
return WmfDumpFile.getDumpFileWebDirectory(DumpContentType.JSON,
this.projectName);
this.projectName) + this.dateStamp + "/";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public abstract class WmfDumpFile implements MwDumpFile {
WmfDumpFile.WEB_DIRECTORY.put(DumpContentType.CURRENT, "");
WmfDumpFile.WEB_DIRECTORY.put(DumpContentType.FULL, "");
WmfDumpFile.WEB_DIRECTORY.put(DumpContentType.SITES, "");
WmfDumpFile.WEB_DIRECTORY.put(DumpContentType.JSON, "other/");
WmfDumpFile.WEB_DIRECTORY.put(DumpContentType.JSON, "");
}

/**
Expand All @@ -68,7 +68,7 @@ public abstract class WmfDumpFile implements MwDumpFile {
WmfDumpFile.POSTFIXES.put(DumpContentType.FULL,
"-pages-meta-history.xml.bz2");
WmfDumpFile.POSTFIXES.put(DumpContentType.SITES, "-sites.sql.gz");
WmfDumpFile.POSTFIXES.put(DumpContentType.JSON, ".json.gz");
WmfDumpFile.POSTFIXES.put(DumpContentType.JSON, "-all.json.gz");
}

/**
Expand Down Expand Up @@ -172,7 +172,7 @@ public static String getDumpFileWebDirectory(
if ("wikidatawiki".equals(projectName)) {
return WmfDumpFile.DUMP_SITE_BASE_URL
+ WmfDumpFile.WEB_DIRECTORY.get(dumpContentType)
+ "wikidata" + "/";
+ projectName + "/entities/";
} else {
throw new RuntimeException(
"Wikimedia Foundation uses non-systematic directory names for this type of dump file."
Expand Down Expand Up @@ -253,7 +253,7 @@ public static String getDateStampFromDumpFileDirectoryName(
public static String getDumpFileName(DumpContentType dumpContentType,
String projectName, String dateStamp) {
if (dumpContentType == DumpContentType.JSON) {
return dateStamp + WmfDumpFile.getDumpFilePostfix(dumpContentType);
return "wikidata-" + dateStamp + WmfDumpFile.getDumpFilePostfix(dumpContentType);
} else {
return projectName + "-" + dateStamp
+ WmfDumpFile.getDumpFilePostfix(dumpContentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected boolean fetchIsDone() {
new InputStreamReader(in, StandardCharsets.UTF_8));
String inputLine = bufferedReader.readLine();
bufferedReader.close();
result = "done".equals(inputLine);
result = inputLine.startsWith("done");
} catch (IOException e) { // file not found or not readable
result = false;
}
Expand Down