Created
July 13, 2019 19:02
-
-
Save owenselles/82311fc1c9f720031be0077ba78c7165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun getShiftsMonth(month: Calendar, listener: CompanyConnection.ConnectionListener, | |
identifier: String) { | |
month.set(Calendar.DAY_OF_MONTH, 1) | |
val start = month.clone() as Calendar | |
month.add(Calendar.MONTH, 1) | |
month.add(Calendar.DAY_OF_MONTH, -1) | |
val period = Period(start, month) | |
if (login_cookies.size == 0) { | |
Log.println(Log.ERROR, "TAG", "NO LOGIN COOKIES!") | |
Crashlytics.log(Log.ERROR, "SAM", "No login cookies received") | |
listener.shifts(CompanyConnection.Result.CONNECT_ERROR, null, period) | |
return | |
} | |
val headers = HashMap<String, String>() | |
headers["Upgrade-Insecure-Requests"] = "1" | |
headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" | |
headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" | |
headers["DNT"] = "1" | |
headers["Referer"] = "https://sam.ahold.com/wrkbrn_jct/etm/etmMenu.jsp?locale=nl_NL" | |
headers["Accept-Encoding"] = "gzip, deflate, sdch, br" | |
headers["Accept-Language"] = "en-US,en;q=0.8,nl;q=0.6" | |
val params = HashMap<String, String>() | |
params["NEW_MONTH_YEAR"] = (month.get(Calendar.MONTH) + 1).toString() + "/" + month.get(Calendar.YEAR) | |
object : AsyncHttpConnector(AGENDA_URL, params, headers, Connection.Method.GET, login_cookies, | |
false) { | |
override fun OnSucces(document: Document, cookies: Map<String, String>) { | |
try { | |
val shifts = ArrayList<Shift>() | |
val elements = ArrayList<Element>() | |
elements.addAll(document.getElementsByClass("calendarCellRegularFuture")) | |
elements.addAll(document.getElementsByClass("calendarCellRegularPast")) | |
elements.addAll(document.getElementsByClass("calendarCellRegularCurrent")) | |
// todo add future | |
for (element in elements) { | |
if (!element.className().contains("etmNoBorder")) { | |
val table = element.getElementsByClass("etmCursor")[0] | |
Log.i("test", "reached onsucces") | |
val date = table.attr("title").replace("Details van ", "") | |
val cal = Calendar.getInstance() | |
try { | |
val sdf = SimpleDateFormat("MM/dd/yyyy", Locale.getDefault()) | |
cal.time = sdf.parse(date) | |
} catch (e: ParseException) { | |
e.printStackTrace() // todo quit? | |
} | |
var start: Time? = null | |
var end: Time? = null | |
for (element1 in table.getElementsByTag("span")) { | |
if (!element1.className().contains("etmNoBorder") && | |
!element1.className().contains("calendarDateNormal") && | |
!element1.className().contains("calendarDateCurrent") && | |
element1.html() != "-") { | |
if (start == null) { | |
start = Time(element1.html()) | |
} else { | |
end = Time(element1.html()) | |
} | |
} | |
} | |
if (start != null && end != null) { | |
val verified = table.html().contains("geautoriseerd") | |
val shift = OnlineShift(start, end, cal, verified) | |
shift.companyIdentifier = identifier | |
Log.i("shift", shift.toString()) | |
shifts.add(shift) | |
} | |
} | |
} | |
listener.shifts(CompanyConnection.Result.SUCCES, shifts, period) | |
} catch (e: Exception) { | |
Log.e("ERROR_LOADING", e.message) | |
Crashlytics.logException(e) | |
listener.shifts(CompanyConnection.Result.LOAD_ERROR, null, period) | |
throw e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment