How can I get all the tracks from a spotify playlist in r?
this is what i tried but it doesnt work
response = POST(
'https://accounts.spotify.com/api/token',
accept_json(),
authenticate(clientID, secret),
body = list(grant_type = 'client_credentials'),
encode = 'form',
verbose()
)
token = content(response)$access_token
authorization.header = paste0("Bearer ", token)
#Get track info#
call1 <- GET(url = "https://api.spotify.com/v1/playlists/{53Y8wT46QIMz5H4WQ8O22c}", config = add_headers(authorization = authorization.header))
call1
Related
I'm trying to create a subscription to the callRecords notifications with Graph API in R. I'm looking at this Microsoft page as a reference: https://learn.microsoft.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-beta&tabs=http
Here is my code:
Subscribtion_Call <- AzureGraph::call_graph_endpoint(Tok, options = list(), api_version = Version, operation = "subscriptions", content_type = "application/json")
Subscription_Properties <- list(
changeType = "created,updated",
notificationUrl = "https://webhook.azurewebsites.net/notificationClient",
resource = "communications/callRecords",
expirationDateTime = "2022-04-09T11:00:00.0000000Z",
clientState = "SecretClientState"
)
Send_Subscription <- call_graph_url(Tok, Endpoint, body = Subscription_Properties, encode = "json",
content_type = "application/json",
http_verb = "POST",
http_status_handler = "message",
simplify = FALSE,
auto_refresh = TRUE
)
This gets me an HTTP 405 error as below:
> Subscribtion_Call <- AzureGraph::call_graph_endpoint(Tok, options = list(), api_version = Version, operation = "subscriptions", content_type = "application/json")
>
> Subscription_Properties <- list(
+ changeType = "created,updated",
+ notificationUrl = "https://webhook.azurewebsites.net/notificationClient",
+ resource = "communications/callRecords",
+ expirationDateTime = "2022-04-09T11:00:00.0000000Z",
+ clientState = "SecretClientState"
+ )
>
> Send_Subscription <- call_graph_url(Tok, Endpoint, body = Subscription_Properties, encode = "json",
+ content_type = "application/json",
+ http_verb = "POST",
+ http_status_handler = "message",
+ simplify = FALSE,
+ auto_refresh = TRUE
+ )
Method Not Allowed (HTTP 405). Failed to complete operation. Message:
.
If I change the http_verb to "GET" this is returned:
> Send_Subscription <- call_graph_url(Tok, Endpoint, body = Subscription_Properties, encode = "json",
+ content_type = "application/json",
+ http_verb = "GET",
+ http_status_handler = "message",
+ simplify = FALSE,
+ auto_refresh = TRUE
+ )
OK (HTTP 200). Failed to complete operation. Message:
.
>
What am I missing?
Thanks in advance for your help!
Context:
I currently send 10 separate HTML files markdown files to my audience, however, in the email it sends as different attachments as such in the image below:
How can I package all these attachments in a single zip file instead individual attachments?
My Current Script to email out these attachments:
#Create vector of all sheetname that are in my excel paths
markdown_names <- paste0("MVNDR","_",mvndr_nbr,".html")
path_markdown <- "C:path/Supplier_Ops_Parameterized_Reports/"
attachments_markdown <- c(paste0(path_markdown, markdown_names))
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = paste("emails",
sep=";", collapse=NULL)
outMail[["subject"]] = "RMarkdown Report"
outMail[["body"]] =
"Hi -
email body
"
purrr::map(attachments_markdown, ~ outMail[["attachments"]]$Add(.))
outMail$Send()
You can use the following function :
library(RDCOMClient)
send_email <- function(vec_to = "",
vec_cc = "",
vec_bcc = "",
char_subject = "",
char_body = "",
char_htmlbody = "",
vec_attachments = "") {
Outlook <- RDCOMClient::COMCreate("Outlook.Application")
Email <- Outlook$CreateItem(0)
Email[["to"]] <- vec_to
Email[["cc"]] <- vec_cc
Email[["bcc"]] <- vec_bcc
Email[["subject"]] <- char_subject
if (char_body != "" && char_htmlbody != "") {
stop("Error")
}
if (char_htmlbody == "") {
Email[["body"]] <- char_body
} else {
Email[["htmlbody"]] <- char_htmlbody
}
if (vec_attachments[1] != "") {
for (i in seq_along(vec_attachments)) {
Email[["attachments"]]$Add(vec_attachments[i])
}
}
}
You just have to give the paths to the files to send to the variable "vec_attachments".
Hi Can anyone know how to troubleshoot this.
url = "https://www.zillow.com/walnut-ca/?searchQueryState=%7B%22pagination%22%3A%7B%7D%2C%22usersSearchTerm%22%3A%22Walnut%2C%20CA%22%2C%22mapBounds%22%3A%7B%22west%22%3A-117.93482729053105%2C%22east%22%3A-117.75286623096073%2C%22south%22%3A33.93783156520187%2C%22north%22%3A34.06392018234896%7D%2C%22isMapVisible%22%3Atrue%2C%22mapZoom%22%3A12%2C%22filterState%22%3A%7B%22price%22%3A%7B%22min%22%3A400000%2C%22max%22%3A700000%7D%2C%22mp%22%3A%7B%22min%22%3A1448%2C%22max%22%3A2535%7D%2C%22sort%22%3A%7B%22value%22%3A%22globalrelevanceex%22%7D%7D%2C%22isListVisible%22%3Atrue%7D"
d = {'key':'value'}
print(d)
d['new key'] = 'new value'
print(d)
query_houses = {}
house_no = 0
while True:
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data,'html.parser')
houses = soup.find_all('article',{'class':'list-card list-card-short list-card_not-saved'})
for house in houses:
location = house.find('address',{'class': 'list-card-addr'})
value = house.find('div',{'class': 'list-card-price'})
detail = house.find('ul', {'class':'list-card-details'})
seller = house.find('div',{'class':'list-card-truncate'})
link = house.find('a', {'class': 'list-card-link'}).get('href')
house_response = requests.get(link)
house_data = house_response.text
house_soup = BeautifulSoup(house_data, 'html.parser')
square = house_soup.find('span',{'class':'ds-bed-bath-living-area'})
year_build = house_soup.find('span',{'class':'ds-body ds-home-fact-value'})
estimated_sales_range = house_soup.find('div',{'class':'Spacer-sc-17suqs2-0 pfWXf'})
house_no+=1
query_houses[house_no] = [location, value, detail, seller, link, square, year_build, estimated_sales_range]
url_tag = soup.find('a',{'title':'Next-page'})
if url_tag.get('href'):
url= 'https://zillow.com' + url_tag.get('href')
print(url)
else:
break
When I use the below command
curlPerform(url = "Intranet URL Here",getURL("Intranet URL Here",userpwd = "USERID:PASSWORD",cainfo=system.file("CurlSSL","cacert.pem",package="RCurl")),
httpheader = headerfields,postfields = body,writefunction = reader$update)
I am getting the error message as mentioned below.
Error in curlOptions(..., .opts = .opts) : unnamed curl option(s): HTTP/1.1 404 Not Found
Page not foundPage not found
Could you please suggest me on this error. Thanks in advance.
I have used curl as below
reader = basicTextGatherer()
curl = getCurlHandle()
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"), followlocation = TRUE, httpheader = c(Accept = "text/xml",Accept = "multipart/*",'Content-Type' = "text/xml; charset=utf-8",SOAPAction="INTRANET URL"), userpwd = "USERID:PASSWORD", netrc = TRUE,timeout = 100, postfields = SOAP DETAILS, writefunction = reader$update, verbose=TRUE, curl = curl))
response <- getURL("INTRANET URL", curl=curl)
I use below mentioned code to send mails, can I change the format of table which will pasted on mail body, I want to send nicely formatted/compacted table in mail body.
first6 is my data.frame
Date=sys.Date()-1
date2 <- paste("My subject of mail", Date, sep = " - ")
setwd("/xyz")
newdir <- paste("output", Sys.time(), sep = "_")
dir.create(newdir)#, showWarnings = FALSE)
setwd(newdir)
######
mydoc = bsdoc( title = 'my document')
options( "ReporteRs-fontsize" = 8 )
mydoc = addParagraph(mydoc, value = "Hi All, \n\nPlease check attached summary.")
mydoc = addParagraph(mydoc, value = "Summary:")
MyFTable = FlexTable( data = first6, add.rownames = FALSE, header.cell.props = cellProperties( background.color = "#FAEBD7" )
, header.par.props = parProperties(text.align = "center" ))
MyFTable = setColumnsColors( MyFTable, j=1, colors = '#F0F8FF' )
MyFTable[ , ] = parProperties( text.align = 'center')
MyFTable = setColumnsColors( MyFTable, j=ncol(first6), colors = '#F0F8FF' )
mydoc = addFlexTable( mydoc, MyFTable )
writeDoc( mydoc, file = "op2.html" )
send.mail(from = "abc#xyz.com",
to = c("abc#xyz.com"),
subject = date2,
body = "op2.html",
html = TRUE,
smtp = list(host.name = "smtp.gmail.com", port = 465, user.name = "abc#xyz.com", passwd = "xyz#123", ssl = TRUE),
authenticate = TRUE,
send = TRUE)
Sorry if this doesn't answer your question, but I think you need to use the right tool for the right job.
In column A : Names of the people
In column B : E-mail addresses
In column C:Z : Filenames like this C:\Data\Book2.xls (don't have to be Excel files)
The Macro will loop through each row in "Sheet1" and if there is a E-mail address in column B
and file name(s) in column C:Z it will create a mail with this information and send it.
Sub Send_Files()
'Working in Excel 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("Sheet1")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")
If cell.Value Like "?*#?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = cell.Value
.Subject = "Testfile"
.Body = "Hi " & cell.Offset(0, -1).Value
For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
Next FileCell
.Send 'Or use .Display
End With
Set OutMail = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
You can find other options at the link below.
https://www.rondebruin.nl/win/s1/outlook/mail.htm