#' FamilyMart
#'
#' @seealso
#' url: \url{http://www.family.com.tw/marketing/inquiry.aspx} \cr
#' data: \url{http://api.map.com.tw/net/familyShop.aspx}
#'
#' @return data.table
#' @export
getFamilyMart <- function() {
url = "http://api.map.com.tw/net/familyShop.aspx"
res = GET(url,
add_headers(
Referer="http://www.family.com.tw/marketing/inquiry.aspx"
),
query = list(
searchType = "ShopName",
type = "",
kw = "%",
fun = "getByName",
key = "6F30E8BF706D653965BDE302661D1241F8BE9EBC"))
res_text = content(res, "text")
jsonDataString <- res_text %>%
sub("^[^\\[]*","",.) %>%
sub("[^\\]]*$","",.)
dt_FamilyMart <- jsonlite::fromJSON(jsonDataString) %>%
as.data.table()#%>% dplyr::tbl_dt()
# ## check misc items
# unique(unlist(strsplit(as.character(dt_FamilyMart$all),',')))
# # cooffie
# COFFEE = ifelse(str_detect(ifelse(
# is.na(dt_FamilyMart$all), '', as.character(dt_FamilyMart$all)
# ), 'COFFEE'), 'Y', 'N')
# #夯蕃薯
# SWEETPOTATO = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'SWEETPOTATO'), 'Y', 'N')
# #相片咅可得
# Photo = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'Photo'), 'Y', 'N')
# WiFi = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'WiFi'), 'Y', 'N')
# Toilet = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'Toilet'), 'Y', 'N')
# #休憩區
# Rest = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'Rest'), 'Y', 'N')
# #生鮮蔬菜
# veg = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'veg'), 'Y', 'N')
# #烈日鬆餅
# muffin = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'muffin'), 'Y', 'N')
# #雙口味霜淇淋
# twoice = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'twoice'), 'Y', 'N')
# # 單口味霜淇淋
# oneice = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'oneice'), 'Y', 'N')
# #停車場
# Parking = ifelse(str_detect(ifelse(
# is.na(temp3$all), '', as.character(temp3$all)
# ), 'Parking'), 'Y', 'N')
## rename variables
setnames(dt_FamilyMart,
c("addr", "NAME", "TEL", "px", "py"),
c("addr", "store_nm", "tel_no", "lon_x", "lat_y"))
dt_FamilyMart[, store_nm := sub("^全家", "", store_nm)]
# add brand name
dt_FamilyMart[, `:=`(brand_nm = "全家", keyword = "Family Mart")]
## add url, time, full name
dt_FamilyMart[, store_url := "http://www.family.com.tw/"][
, data_time := format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z")][
, full_nm := paste0(brand_nm, store_nm)]
key_var <- c("full_nm", "brand_nm", "keyword", "store_nm", "addr",
"lon_x", "lat_y", "store_url")
## move brand_nm, key_word to first two colmuns
setcolorder(dt_FamilyMart, c(key_var, setdiff(names(dt_FamilyMart), key_var)))
dt_FamilyMart
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.