Skip to content

Commit

Permalink
use sdapi 0.2.1 which fixes the latest scrapping logic
Browse files Browse the repository at this point in the history
  • Loading branch information
librehat committed Oct 18, 2020
1 parent ff2b832 commit aa61ae8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1)

project(kesdict
VERSION 0.1.0
VERSION 0.1.1
LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand Down
47 changes: 25 additions & 22 deletions src/KesDict/sdapi.dictionary.qml.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,29 +855,32 @@ function isTagType(tag, type, name) {
}
return true;
}
function extractComponentData(html) {
var body = lib_2(html)[1];
var dataSearchFn = function (element) {
return element.children.find(function (child) {
var _a;
return isTagType(child, 'element', 'script')
&& ((_a = child.children) === null || _a === void 0 ? void 0 : _a.length)
&& child.children[0].type === 'text'
&& child.children[0].content.includes('SD_COMPONENT_DATA');
});
};
var resultTag;
for (var _i = 0, _a = body.children; _i < _a.length; _i++) {
var child = _a[_i];
resultTag = dataSearchFn(child);
if (resultTag) {
break;
function extractComponentData(htmlString) {
var html = lib_2(htmlString).find(function (element) { return isTagType(element, 'element', 'html'); });
var body = html.children.find(function (element) { return isTagType(element, 'element', 'body'); });
if (!body) {
throw new Error('Cannot find the body tag. SpanishDict API might have changed');
}
var dataComponentFindFn = function (element) {
var _a, _b;
for (var _i = 0, _c = (_a = element.children) !== null && _a !== void 0 ? _a : []; _i < _c.length; _i++) {
var child = _c[_i];
if (isTagType(child, 'element', 'script') && ((_b = child.children) === null || _b === void 0 ? void 0 : _b.length)) {
var grandResult = dataComponentFindFn(child);
if (grandResult) { // find it
return grandResult;
}
}
if (child.type === 'text' && child.content.includes('SD_COMPONENT_DATA')) {
return child;
}
}
}
};
var resultTag = dataComponentFindFn(body);
if (!resultTag) {
throw new Error('Cannot find the tag with results. SpanishDict API might have changed');
}
var resultsLine = resultTag.children[0].content.split('\n').find(function (line) { return line.includes('SD_COMPONENT_DATA'); });
var resultsLine = resultTag.content.split('\n').find(function (line) { return line.includes('SD_COMPONENT_DATA'); });
return JSON.parse(resultsLine.substring(resultsLine.indexOf('=') + 1, resultsLine.length - 1));
}

Expand Down Expand Up @@ -914,10 +917,10 @@ function convertSense(sense, lang) {
});
}
function extract(html) {
var _a, _b, _c;
var _a;
var resultsProps = extractComponentData(html).sdDictionaryResultsProps;
var neodict = (_b = (_a = resultsProps) === null || _a === void 0 ? void 0 : _a.entry) === null || _b === void 0 ? void 0 : _b.neodict;
if (!((_c = neodict) === null || _c === void 0 ? void 0 : _c.length)) {
var neodict = (_a = resultsProps === null || resultsProps === void 0 ? void 0 : resultsProps.entry) === null || _a === void 0 ? void 0 : _a.neodict;
if (!(neodict === null || neodict === void 0 ? void 0 : neodict.length)) {
throw new Error('Cannot find neodict. SpanishDict API might have changed');
}
return neodict
Expand Down
2 changes: 1 addition & 1 deletion src/plasmoid/metadata.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ X-KDE-PluginInfo-Category=Language
X-KDE-PluginInfo-Email=symeon@librehat.com
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-Name=com.librehat.kesdict
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Version=1.1
X-KDE-PluginInfo-Website=https://github.com/librehat/kesdict
X-KDE-ServiceTypes=Plasma/Applet
X-Plasma-API=declarativeappletscript
Expand Down

0 comments on commit aa61ae8

Please sign in to comment.