Commit 7d60f6d0 authored by Dorchies David's avatar Dorchies David
Browse files

debug: try old fashion form post by getting cookies from the session (not working)

parent 5f16d33f
No related merge requests found
Showing with 22 additions and 21 deletions
+22 -21
#' Title #' Add a day time in "Feuille de pointage"
#' #'
#' @param cookies Connection cookies in string format or key/value vector #' session a [rvest::session] provided by [login] function
#' (See [set_cookie])
#' @param user_id ID of the user
#' @param date Date to fill #' @param date Date to fill
#' @param duree Duration of the working day #' @param duree Duration of the working day
#' @param type_regulation Regularisation type (default 22 for "Heures normales") #' @param type_regulation Regularisation type (default 22 for "Heures normales")
...@@ -19,11 +17,8 @@ ...@@ -19,11 +17,8 @@
#' @examples #' @examples
#' \dontrun{ #' \dontrun{
#' library(hatata) #' library(hatata)
#' login("pnom", "my_password") #' session <- login("pnom", "my_password")
#' add_temps( #' add_temps(session, "15/04/2021")
#' user_id = "4242",
#' date = "15/04/2021"
#' )
#' } #' }
add_temps <- function( add_temps <- function(
session, session,
...@@ -31,21 +26,27 @@ add_temps <- function( ...@@ -31,21 +26,27 @@ add_temps <- function(
duree = "+07h44", duree = "+07h44",
type_regulation = "22", type_regulation = "22",
commentaire = "", commentaire = "",
user_id = get_user_id(session),
cfg = config::get(file = system.file("config.yml", package = "hatata")) cfg = config::get(file = system.file("config.yml", package = "hatata"))
) { ) {
if(!inherits(session, "hatata_pointage")) { if(!inherits(session, "hatata_pointage")) {
session <- jump_to_pointage(session) session <- jump_to_pointage(session)
} }
rs <- rvest::read_html(system.file("form_add.html", package = "hatata"))
rf <- rvest::html_form(rs)[[1]] cookies <- session$response$cookies$value
# Define proper url for form action names(cookies) <- session$response$cookies$name
rf$action <- paste(cfg$url_post_add, cfg$param_add, sep = "?")
# Set form fields POST(
rf <- rf %>% rvest::html_form_set(date = date, paste(cfg$url_post_add, cfg$param_add, sep = "?"),
type_regulation = type_regulation, #user_agent(cfg$user_agent),
commentaire = commentaire, set_cookies(.cookies = cookies),
user_id = user_id, body = list(
duree = duree) date = date,
rvest::session_submit(session, rf) type_regulation = type_regulation,
commentaire = commentaire,
user_id = attr(session, "user_id"),
id_form = "form_add_regul",
duree = duree
)
)
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment