orders = function(start.date, end.date = Sys.Date(), username = "gabriel.oprescu", password = "Nob3l_0504"){
path = getwd()
########### Login
if(missing(start.date) & missing(end.date) & missing(username) & missing(password)){
stop("Please specify all the parameters in function's definition")
}else{
username <- as.character(username)
password <- as.character(password)
agent = "Firefox/23.0"
curl = getCurlHandle()
curlSetOpt(cookiejar = "cookies.txt", useragent = agent,
followlocation = TRUE, autoreferer = TRUE,
curl = curl)
params <- list(userAgent = agent, username = username,
password = password)
}
########### Login
########### Parametrii descarcare
q.param = list(search.report.param = c("filterOrderDateTo=",
"filterType=",
"filterBuyerAccountTest=",
"filterOrderDateFrom="),
search.report.values = c("1",
"false"))
########### Parametrii descarcare
########### Generare secvente de date
start.date = as.Date(as.POSIXct(start.date, tz = "EST"))
end.date = as.Date(as.POSIXct(end.date, tz = "EST"))
if(start.date > end.date)
stop("Maybe you want to reverse start and end date")
date_from = seq.Date(start.date, end.date, by = "month")
date_to = date_from - 1
if(date_to[length(date_to)] <= end.date - 1)
date_to[length(date_to)+1] = end.date
date_to = date_to[-1]
date_trans = function(x) {
paste(month(x), day(x), year(x), sep = "%2F")
}
date_from_trans = unlist(map(date_from, date_trans))
date_to_trans = unlist(map(date_to, date_trans))
########### Generare secvente de date
for(i in 1:length(date_from_trans)){
search.report.param = q.param[["search.report.param"]]
search.report.values = c(date_to_trans[i],
q.param[["search.report.values"]],
date_from_trans[i])
########### Construire URL pentru descarcare
url = paste0("https://consumer.totalmanager.com/retail/order/viewOrders.htm?action=exportCSV&pageNumber=&rowsPerPage=&goToPageNumber=&column=&scope=REQUEST&exportDecoratorName=retail.order.orderExportDecorator.new&exportDecoratorScope=SPRING&tableModelName=retail.order.orderTableModel.new&",
paste0(search.report.param,search.report.values, "&", collapse=""), collapse = "")
filename = tempfile("temporar", tmpdir = path, fileext = ".csv")
f = CFILE(filename, mode = "wb")
postForm("https://consumer.totalmanager.com/login.htm", .params = params, curl = curl, style="POST")
curlPerform(url = url,
curl = curl,
writedata = f@ref)
close(f)
########### Construire URL pentru descarcare
########### Logout
postForm("https://consumer.totalmanager.com/logout.htm",
.params = params, curl = curl, style = "POST")
########### Logout
fisier = read.csv(filename)
file.remove(filename)
write.csv(fisier, paste("orders-", date_from[i],
"-", date_to[i], ".csv", sep = ""), row.names = FALSE)
write.table(fisier, "append.csv", append = TRUE,
row.names = FALSE, col.names = FALSE, sep = ",",
quote = FALSE)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.