Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
fix fetching of subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
wiomoc committed Oct 14, 2020
1 parent 8d15c54 commit 3c6fe45
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build-professors-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function fetchDOM(url) {


async function buildProfessorsList() {
const entries = await Promise.all((await Promise.all([1, 2]
const entries = await Promise.all((await Promise.all([1, 2, 3]
.map(async page =>
fetchDOM('https://www.hft-stuttgart.de/personenverzeichnis?' +
'tx_solr[filter][0]=role%3AProfessor%2Fin' +
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "hft-app",
"version": "3.0.9",
"version": "3.0.10",
"description": "The HFT App",
"browser_specific_settings": {
"gecko": {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "hft-app",
"version": "3.0.9",
"version": "3.0.10",
"private": true,
"description": "",
"author": "Christoph Walcher & Lukas Jans",
"scripts": {
"build:webext": "webpack --config webpack.config.webext.js --mode=production",
"sign:webext": "cd dist; web-ext sign --api-key=$AMO_JWT_ISSUER --api-secret=$AMO_JWT_SECRET; cd ..",
"serve:dev": "webpack-dev-server --config webpack.config.cordova.js",
"serve:dev": "webpack-dev-server --config webpack.config.webext.js",
"lint": "eslint --ext .js,.vue src tests",
"test": "jest",
"icons": "cd image; ./scale.sh; cd .."
Expand Down
2 changes: 1 addition & 1 deletion src-cordova/config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="de.hft.app" version="3.0.9" xmlns="http://www.w3.org/ns/widgets">
<widget id="de.hft.app" version="3.0.10" xmlns="http://www.w3.org/ns/widgets">
<name>HFT App</name>
<description>
The HFT App
Expand Down
11 changes: 5 additions & 6 deletions src-cordova/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src-cordova/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "de.hft.app",
"displayName": "HFT App",
"version": "3.0.9",
"version": "3.0.10",
"description": "The HFT App",
"main": "index.js",
"scripts": {
Expand All @@ -22,32 +22,32 @@
"dependencies": {
"cordova-android": "^9.0.0",
"cordova-ios": "^6.1.1",
"cordova-plugin-advanced-http": "^2.4.1",
"cordova-plugin-advanced-http": "^3.0.1",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-webpack": "^1.0.4",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-plugin-x-socialsharing": "^5.6.5",
"es6-promise-plugin": "^4.2.2"
},
"devDependencies": {
"cordova": "^10.0.0",
"cordova-plugin-whitelist": "^1.3.4"
"cordova": "^10.0.0"
},
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {},
"cordova-plugin-x-socialsharing": {
"ANDROID_SUPPORT_V4_VERSION": "24.1.1+",
"PHOTO_LIBRARY_ADD_USAGE_DESCRIPTION": "This app requires photo library access to function properly.",
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "This app requires photo library access to function properly."
},
"cordova-plugin-statusbar": {},
"cordova-plugin-webpack": {},
"cordova-plugin-advanced-http": {}
"cordova-plugin-advanced-http": {},
"cordova-plugin-whitelist": {}
},
"platforms": [
"android",
"ios"
]
}
}
}
30 changes: 19 additions & 11 deletions src/platform/cordova/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ export function fetchJSON(url) {
})
}

export function clearCookies() {
cordova.plugin.http.clearCookies();
}

export function fetchDOM(url) {
return new Promise((resolve, reject) => {
cordova.plugin.http.get(url, {}, {},
response => {
resolve(new DOMParser().parseFromString(response.data, 'text/html'))
},
response => {
if (response.status === 503) {
reject({type: 'maintenance'})
} else {
reject(response)
try {
cordova.plugin.http.get(url, {}, {},
response => {
resolve(new DOMParser().parseFromString(response.data, 'text/html'))
},
response => {
if (response.status === 503) {
reject({type: 'maintenance'})
} else {
reject(response)
}
}
}
)
)
} catch (e) {
reject(e);
}
}
)
}
Expand Down
4 changes: 4 additions & 0 deletions src/platform/webext/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export function fetchDOM(url) {
}).then(text => new DOMParser().parseFromString(text, 'text/html'))
}

export function clearCookies() {
//not implemented
}

export async function fetchLogin(url, data) {
const queryString = Object.entries(data)
.map(pair => `${pair[0]}=${encodeURIComponent(pair[1])}`)
Expand Down
11 changes: 6 additions & 5 deletions src/stores/lsf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {parseDate, sleep} from './util';
import {fetchDOM, fetchLogin} from 'platform/fetch';
import {fetchDOM, fetchLogin, clearCookies} from 'platform/fetch';


const BASE_URL = 'https://lsf.hft-stuttgart.de/qisserver/rds';
Expand Down Expand Up @@ -185,9 +185,10 @@ export const Client = {
},

async loadSubjects() {
clearCookies();
const dom = await fetchDOM(BASE_URL + '?state=verpublish&publishContainer=stgPlanList');

return Array(...dom.querySelectorAll('.content tbody tr'))
return Array(...dom.querySelectorAll('.divcontent tbody tr'))
.map(element => {
const href = element.children[1].children[0].getAttribute('href');
return {
Expand Down Expand Up @@ -587,9 +588,9 @@ export default {

// XXX We have to relogin to LSF
await client.login(context.state.credentials);
const lecturesThisWeek = client.loadLectures(new Date());
const lecturesNextWeek = client.loadLectures(new Date(Date.now() + 6.04e+8));
const lectures = (await lecturesThisWeek).concat(await lecturesNextWeek);
const lecturesThisWeek = await client.loadLectures(new Date());
const lecturesNextWeek = await client.loadLectures(new Date(Date.now() + 6.04e+8));
const lectures = lecturesThisWeek.concat(lecturesNextWeek);
context.commit('lectures', lectures);
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/stores/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ export function parseDate(date) {
return new Date(parseInt(parts[2]), parseInt(parts[1]) - 1, parseInt(parts[0]))
}

export function getErrorInfo(e){
export function getErrorInfo(e) {
if (e.type) {
return e;
return e;
} else if (e.constructor.name === 'TypeError') {
return {type: 'offline'}
} else {
Expand Down

0 comments on commit 3c6fe45

Please sign in to comment.