mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 23:52:44 +01:00
Add experimental/partial downloading marks data
This commit is contained in:
parent
2a0134d8f4
commit
7d00f92b83
@ -2,6 +2,8 @@ package io.github.wulkanowy.activity.dashboard.marks;
|
|||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.GridLayoutManager;
|
import android.support.v7.widget.GridLayoutManager;
|
||||||
@ -10,8 +12,18 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.jsoup.Connection;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
|
|
||||||
@ -39,6 +51,8 @@ public class MarksFragment extends Fragment {
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
new MarksModel(container.getContext()).execute();
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.fragment_marks, container, false);
|
View view = inflater.inflate(R.layout.fragment_marks, container, false);
|
||||||
|
|
||||||
RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.card_recycler_view);
|
RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.card_recycler_view);
|
||||||
@ -53,4 +67,68 @@ public class MarksFragment extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MarksModel extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private Map<String, String> loginCookies;
|
||||||
|
|
||||||
|
MarksModel(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
String cookiesPath = mContext.getFilesDir().getPath() + "/cookies.txt";
|
||||||
|
|
||||||
|
try {
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(cookiesPath));
|
||||||
|
loginCookies = (Map<String, String>) ois.readObject();
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e){
|
||||||
|
e.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// get link to uonetplus-opiekun.vulcan.net.pl module
|
||||||
|
String startPageUrl = "https://uonetplus.vulcan.net.pl/powiatjaroslawski/Start.mvc/Index";
|
||||||
|
try {
|
||||||
|
Document startPage = Jsoup.connect(startPageUrl)
|
||||||
|
.followRedirects(true)
|
||||||
|
.cookies(loginCookies)
|
||||||
|
.get();
|
||||||
|
Elements studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a");
|
||||||
|
String uonetPlusOpiekunUrl = studentTileLink.attr("href");
|
||||||
|
|
||||||
|
// get context module cookie
|
||||||
|
Connection.Response res = Jsoup.connect(uonetPlusOpiekunUrl)
|
||||||
|
.followRedirects(true)
|
||||||
|
.cookies(loginCookies)
|
||||||
|
.execute();
|
||||||
|
loginCookies = res.cookies();
|
||||||
|
|
||||||
|
// get marks view
|
||||||
|
String marksPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/powiatjaroslawski/005791/Oceny/Wszystkie?details=2";
|
||||||
|
Document marksPage = Jsoup.connect(marksPageUrl)
|
||||||
|
.cookies(loginCookies)
|
||||||
|
.get();
|
||||||
|
Elements marksRows = marksPage.select(".ocenySzczegoly-table > tbody > tr");
|
||||||
|
for (Element element : marksRows) {
|
||||||
|
System.out.println("----------");
|
||||||
|
System.out.println("Subject: " + element.select("td:nth-child(1)").text());
|
||||||
|
System.out.println("Grade: " + element.select("td:nth-child(2)").text());
|
||||||
|
System.out.println("Description: " + element.select("td:nth-child(3)").text());
|
||||||
|
System.out.println("Weight: " + element.select("td:nth-child(4)").text());
|
||||||
|
System.out.println("Date: " + element.select("td:nth-child(5)").text());
|
||||||
|
System.out.println("Teacher: " + element.select("td:nth-child(6)").text());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,9 @@ import org.jsoup.Jsoup;
|
|||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import io.github.wulkanowy.R;
|
import io.github.wulkanowy.R;
|
||||||
@ -83,6 +85,12 @@ public class Login extends AsyncTask<Void, Void, Void> {
|
|||||||
String helloText = dashboardHtml.getElementsByClass("welcome").text();
|
String helloText = dashboardHtml.getElementsByClass("welcome").text();
|
||||||
|
|
||||||
if (helloText.equals("Dzień dobry!")) {
|
if (helloText.equals("Dzień dobry!")) {
|
||||||
|
String cookiesPath = activity.getFilesDir().getPath() + "/cookies.txt";
|
||||||
|
FileOutputStream out = new FileOutputStream(cookiesPath);
|
||||||
|
ObjectOutputStream outputStream = new ObjectOutputStream(out);
|
||||||
|
outputStream.writeObject(loginCookies);
|
||||||
|
outputStream.flush();
|
||||||
|
|
||||||
userMesage = activity.getString(R.string.login_accepted);
|
userMesage = activity.getString(R.string.login_accepted);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -129,13 +137,17 @@ public class Login extends AsyncTask<Void, Void, Void> {
|
|||||||
|
|
||||||
urlForStepThree = urlForStepThree.replace("{locationID}", county);
|
urlForStepThree = urlForStepThree.replace("{locationID}", county);
|
||||||
|
|
||||||
return Jsoup.connect(urlForStepThree)
|
Connection.Response res = Jsoup.connect(urlForStepThree)
|
||||||
.data("wa", wa)
|
.data("wa", wa)
|
||||||
.data("wresult", wresults)
|
.data("wresult", wresults)
|
||||||
.cookies(loginCookies)
|
.cookies(loginCookies)
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.method(Connection.Method.POST)
|
.method(Connection.Method.POST)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
loginCookies = res.cookies();
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPostExecute(Void result) {
|
protected void onPostExecute(Void result) {
|
||||||
|
@ -31,7 +31,7 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
|||||||
/* Intent intent = new Intent(activity,MainActivity.class);
|
/* Intent intent = new Intent(activity,MainActivity.class);
|
||||||
activity.startActivity(intent); */
|
activity.startActivity(intent); */
|
||||||
|
|
||||||
Intent intent = new Intent(activity,DashboardActivity.class);
|
Intent intent = new Intent(activity,MainActivity.class);
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user