Trying to only pull the URL between two quotes in a text string. I want to end with "www.youtube.com/embed/abcdefg" Currently, EndURL pulls a 0 which means it didn't find a double quote.
Link_Youtube = <iframe width="560" height="315" src="//www.youtube.com/embed/abcdefg" frameborder="0" allowfullscreen></iframe>
StartURL = Instr(Link_Youtube,"src=")
EndURL = Instr(startURL+7, Link_Youtube, Instr(Link_Youtube,""""))
Link_Youtube = Mid(Link_Youtube, startURL+6, EndURL)
Updated (working) Code:
If Instr(Link_Youtube,"iframe") > 0 Then 'embed
startURL = Instr(Link_Youtube,"src=")+7
EndURL = Instr(startURL, Link_Youtube, """") - startURL
Link_Youtube = Mid(Link_Youtube, startURL, EndURL)
End If
Related
My webhook is receiving POST request (aplication/JSON) from a 360Dialog (whatsapp) API with escaped Unicode characters like this: \u05db\u05e0\u05e1\u05d2\u05db\u05d9. It should be Hebrew letters.
I'm trying to decode that using JavaScript runat server but seems like it is not changing. I found a potential solution in this question's solution but it still saves the un-escaped Unicode into the database.
<script language="javascript" runat="server">
URL = {
decode : function(s){return decodeURIComponent(s.replace(/\+/g, " "))}
}
</script>
<%
rs("smstext")=URL.decode(body2)
%>
The POST request is coming from 360dialog (a Whatsapp API) and hitting my webhook.
the request sends an application/json POST with information of incoming Whatsapp messages.
It seems the POST itself already has the Hebrew in it as \u05e0\u05e1\u05d9\u05d5\u05df i guess i need to figure out how to set the charset for that?
also, this unanswered question seems like my same problem.
I am trying to convert a request.BinaryRead into utf-8.
the output in the database is this: \u05e0\u05e1\u05d9\u05d5\u05df instead of נסיון
I am probably misunderstanding something as the output is not what I expected.
my code is:
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include virtual="/include/aspjson.asp" -->
<%
If Request.TotalBytes > 0 Then
Dim lngBytesCount
lngBytesCount = Request.TotalBytes
body = BytesToStr(Request.BinaryRead(lngBytesCount))
Set db = CreateObject("ADODB.Connection")
db.Open "DSN=xxx"
set rs = Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM log_sms", db, 3, 3
rs.addnew
rs("smstext")=body
rs.update
rs.close
End if
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "utf-8"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
%>
If I replace rs("smstext")=body with rs("smstext")="נסיון", the value in the database is saved correctly.
The approach is sound the problem is because the text is escaped in the JSON body you will need to unescape those characters before saving the content to a database.
Would recommend using this particular JSON Parser as it will automatically handle unescaping the characters for you.
Useful Links
Classic ASP Convert Latin Characters to Unicode Escape Strings *(Contains useful information about escaping, which can help with the unescaping aspect).
The solution (thanks to #user692942 comments):
I replaced the aspJSON library I was using with rcdmk/aspJSON. It takes care of decoding escaped characters already and simplified the process.
Since the POST request to my webhook page is in application/JSON a JSON library is required anyways.
to my little understanding, i must use BinaryRead to fetch the data from such a request. And thus have to convert from byte to str.
the working code is as follows:
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001" LCID="1037"%>
<!--#include virtual="/wa/aspjson.asp" -->
<%
If Request.TotalBytes > 0 Then
Dim lngBytesCount
lngBytesCount = Request.TotalBytes
jsonbyte = Request.BinaryRead(lngBytesCount)
jsonStr = BytesToStr(jsonbyte)
Set JSON = New JSONobject
Set jsn = JSON.Parse(jsonStr)
Set contact = jsn.value("contacts")(0)
set profile = contact.value("profile")
profname = profile.value("name")
wa_id = contact.value("wa_id")
Set message = jsn.value("messages")(0)
from = message.value("from")
id = message.value("id")
timestamp = message.value("timestamp")
mtype = message.value("type")
set text = message.value("text")
body = text.value("body")
End If
Set db = CreateObject("ADODB.Connection")
db.Open "DSN=xxx"
set rs = Server.CreateObject("ADODB.Recordset")
rs.open "SELECT * FROM log_sms", db, 3, 3
rs.addnew
rs("sent")=DateAdd("s", timestamp, DateSerial(1970,1,1))
rs("from")=from
rs("to")="whatsapp"
rs("smstext")=body
rs("result")="received"
rs("msgid")=id
rs("snr")="r"
rs("type")=mtype
rs.update
rs.close
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "utf-8"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
I have a document that is using tabs to fill a document. The document is signed before and after completion of a task. Is it possible to modify tabs on an envelope - then re-generate an DocuSign_eSign::RecipientViewRequest (still having the initial signature / fields)?
Thus far I've been able to generate two DocuSign_eSign::RecipientViewRequest, but cannot figure out how to change the tabs in between signing:
PRE_SIGNER = 'pre_signer'
POST_SIGNER = 'post_signer'
PRIVATE_KEY = CREDENTIALS['private_key']
PUBLIC_KEY = CREDENTIALS['public_key']
USER_ID = CREDENTIALS['user_id']
CLIENT_ID = CREDENTIALS['client_id']
ACCOUNT_ID = CREDENTIALS['account_id']
BASE_URL = CREDENTIALS['base_url']
configuration = DocuSign_eSign::Configuration.new
configuration.host = "#{BASE_URL}/restapi"
configuration.debugging = true
api_client = DocuSign_eSign::ApiClient.new(configuration)
api_client.base_path = BASE_URL
envelope_api = DocuSign_eSign::EnvelopesApi.new(api_client)
pre_signer_text = DocuSign_eSign::Text.new
pre_signer_text.value = 'Alpha'
pre_signer_text.tab_label = 'pre_value'
pre_signer = DocuSign_eSign::Signer.new
pre_signer.role_name = PRE_SIGNER
pre_signer.client_user_id = PRE_SIGNER
pre_signer.recipient_id = 1
pre_signer.name = 'Kevin Sylvestre'
pre_signer.email = 'kevin#fake.com'
pre_signer.tabs = DocuSign_eSign::Tabs.new
pre_signer.tabs.text_tabs = [pre_signer_text]
post_signer = DocuSign_eSign::Signer.new
post_signer.role_name = POST_SIGNER
post_signer.client_user_id = POST_SIGNER
post_signer.recipient_id = 2
post_signer.name = 'Kevin Sylvestre'
post_signer.email = 'kevin#fake.com'
post_signer.tabs = DocuSign_eSign::Tabs.new
post_signer.tabs.text_tabs = []
server_template = DocuSign_eSign::ServerTemplate.new
server_template.sequence = 0
server_template.template_id = TEMPLATE_ID
inline_template = DocuSign_eSign::InlineTemplate.new
inline_template.sequence = 0
inline_template.recipients = DocuSign_eSign::Recipients.new
inline_template.recipients.signers = [
pre_signer,
post_signer,
]
composite_template = DocuSign_eSign::CompositeTemplate.new
composite_template.server_templates = [server_template]
composite_template.inline_templates = [inline_template]
envelope_event = DocuSign_eSign::EnvelopeEvent.new
envelope_event.envelope_event_status_code = 'completed'
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
envelope_definition.status = 'sent'
envelope_definition.composite_templates = [composite_template]
api_client.request_jwt_user_token(CLIENT_ID, USER_ID, PRIVATE_KEY)
envelope = envelope_api.create_envelope(ACCOUNT_ID, envelope_definition)
pre_signer_recipient_view_request = DocuSign_eSign::RecipientViewRequest.new
pre_signer_recipient_view_request.authentication_method = 'none'
pre_signer_recipient_view_request.client_user_id = PRE_SIGNER
pre_signer_recipient_view_request.user_name = 'Kevin Sylvestre'
pre_signer_recipient_view_request.email = 'kevin#fake.com'
pre_signer_recipient_view_request.return_url = 'https://ksylvest.com'
pre_recipient_view = envelope_api.create_recipient_view(ACCOUNT_ID, envelope.envelope_id, pre_signer_recipient_view_request)
url = pre_recipient_view.url
`open #{url}`
puts "Continue?"
gets
# at this point I'd like to enter values for tabs...
post_signer_text = DocuSign_eSign::Text.new
post_signer_text.value = 'Omega'
post_signer_text.tab_label = 'post_value'
post_signer_recipient_view_request = DocuSign_eSign::RecipientViewRequest.new
post_signer_recipient_view_request.authentication_method = 'none'
post_signer_recipient_view_request.client_user_id = POST_SIGNER
post_signer_recipient_view_request.user_name = 'Kevin Sylvestre'
post_signer_recipient_view_request.email = 'kevin#fake.com'
post_signer_recipient_view_request.return_url = 'https://ksylvest.com'
post_recipient_view = envelope_api.create_recipient_view(ACCOUNT_ID, envelope.envelope_id, post_signer_recipient_view_request)
url = post_recipient_view.url
`open #{url}`
You could add the same person to sign twice, as two separate recipients that are the same person. You can generate different recipient views. You can set the routing order to be different. Only reason I didn't post this as an answer is that you may mean that you need to pause the envelope?
you can add tabs using your code where you have post_signer.tabs, but if you want to modify existing tabs that came from the template then you have to create the envelope in draft mode ("created") and then make a different API call to modify the tabs and then a final API call to send it. Another option is to pause the envelope and "correct" it.
Pause envelope workflow code examples
https://github.com/docusign/docusign-esign-ruby-client/blob/c477b07c2f578214fdf7d0c5a33355f01e9a0b4e/lib/docusign_esign/api/envelopes_api.rb#L6132 update_recipients() method should do the trick...
I have a script that is submitting a POST request of a form via AJAX.
When I look at the network tab, it is coming back in the format below, which I cannot read with a standard Request.Form in Classic ASP. I am seeing this server variable added to the page request as well due to the AJAX request: HTTP_X_REQUESTED_WITH = XMLHttpRequest
The form is set up as a simple POST: <form method="post" action="/contact-submit">
I cannot change the script performing the AJAX request to update the content type, etc.
This is the “Request payload” in the response on the network tab below. I have googled for days and cannot figure this out. How do you access this data? I even tried reading it with a file upload script I have via ASPUpload, but Upload.Form("contact_name") does not work either, it's blank as well.
I tried a simple PHP script (I do not know how PHP works, but this script came with script performing the POST as a demo), and calling print_r($_POST) the script passes all the correct info in an array back in the response on network tab. What the heck!!
Does anyone know how to get this data back in Classic ASP?
Thanks so much for the help in advance.
Dennis
-----------------------------254001430938683980861095915686
Content-Disposition: form-data; name="contact_name"
Test Name
-----------------------------254001430938683980861095915686
Content-Disposition: form-data; name="contact_email"
test#test.com
-----------------------------254001430938683980861095915686
Content-Disposition: form-data; name="contact_message"
my message
-----------------------------254001430938683980861095915686--
I worked on a solution to reading the data, this works below. Not sure it is the best / least expensive way to do this, but it works!
Thanks to everyone for the help / tips. If anyone has a better way to parse the response above, I'm all ears :)
<%
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "iso-8859-1"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
If Request.TotalBytes > 0 Then
Dim lngBytesCount, post
lngBytesCount = Request.TotalBytes
post = BytesToStr(Request.BinaryRead(lngBytesCount))
End If
Response.ContentType = "text/plain"
sContentType = Replace(Request.ServerVariables("CONTENT_TYPE"),"multipart/form-data; boundary=---------------------------","")
arrPost = Split(post,"-----------------------------" & sContentType)
For i = 0 to UBound(arrPost)
sVal = Replace(arrPost(i),"Content-Disposition: form-data; name=","")
arrVal = Split(sVal,Chr(10),1)
For a = 0 to UBound(arrVal)
If Instr(1, arrVal(a), "contact_name") <> 0 Then
Response.Write GetValue(arrVal(a), "contact_name")
End If
If Instr(1, arrVal(a), "contact_message") <> 0 Then
Response.Write GetValue(arrVal(a), "contact_message")
End If
Next
Next
Function GetValue(f_FullString, f_FieldName)
fieldval = Replace(f_FullString, """" & f_FieldName & """","")
'response.Write "_" & fieldval & "_<Br>"
arrVal1 = Split(fieldval,Chr(10),1)
For b = 0 to UBound(arrVal1)
newval = arrVal1(b)
newval = Left(newval,Len(newval) - 2)
newval = Right(newval,Len(newval) - 6)
'For z = 1 to Len(newval)
' CurrChar = Mid(newval, z, 1)
' Response.Write Asc(CurrChar) & "<bR>"
'Next
Next
GetValue = newval
End Function
%>
UPDATE:
This is another solution if you have ASPUpload installed. I tried this last night, but forgot to add Upload.Save (which would have saved me 4hours of work --- UGGGGGHHHH).
'http://www.aspupload.com/manual_memory.html
Set Upload = Server.CreateObject("Persits.Upload")
Upload.Save
Name = Upload.Form("contact_name")
Response.Write Name
In an accounting WPF app we have a number of public DataTables that reload data once a tab is opened. This works great locally as the reports just refer to those tables..
For some more complex reports we have just set up a Web Service to run them and return a PDF... To make it easier I thought of loading these DataTables into a DataSet and then extracting them at the server end. This works perfectly the first time it's run, but then (as best as I can work out so far) it's sending the incorrect (last loaded) data for subsequent reports. Locally it still works as it should but the DataTables we are sending in the DataSet appear to not be updating. Have tried to remove the tables and re-add them again, but that just throws a 'object reference not set' the first time a DataRow is selected from a DataTable at the server.
Must be something very basic I have been missing :-(
Any ideas?
Thanks
Private Async Sub RunProfitAndLossOnServer(sender As Object, e As RoutedEventArgs)
Try
Dim StartDateTB As DateTBx = ReportBalanceSheet_Grid.FindName("BalanceSheet_StartDateTB")
Dim EndDateTB As DateTBx = ReportBalanceSheet_Grid.FindName("BalanceSheet_EndDateTB")
ReportStartDate = StartDateTB.Value
ReportEndDate = EndDateTB.Value
ReportDate = Today
ReportName = "Profit and Loss Report"
PaperLandscape = False
ReportFontSize = 8
PopupModals_ReportGenerator()
If ReportGeneratorRun = True Then
Dim vPDF() As Byte = Nothing
'Determine if the Export Dataset has already been created
If ExportDS Is Nothing Then
ExportDS = New DataSet
VariablesDT = New DataTable
With VariablesDT.Columns
.Add("Current_HOA_Name", GetType(String))
.Add("Current_HOA_ID", GetType(Integer))
.Add("ReportName", GetType(String))
.Add("ReportFontSize", GetType(Integer))
.Add("ReportStartDate", GetType(Date))
.Add("ReportEndDate", GetType(Date))
.Add("User_InternationalDate", GetType(Integer))
.Add("PaperSize", GetType(String))
.Add("PaperLandscape", GetType(Boolean))
.Add("Reports_IsSplitGL", GetType(Boolean))
.Add("Form_ID", GetType(Integer))
End With
With VariablesDT.Rows
.Add(Current_HOA_Name, Current_HOA_ID, ReportName, ReportFontSize, ReportStartDate, ReportEndDate, User_InternationalDate, PaperSize, PaperLandscape, False, Form_ID)
End With
VariablesDT.TableName = "VariablesDT"
ExportDS.Tables.Add(VariablesDT)
ResIncomeDT.TableName = "ResIncomeDT"
ExportDS.Tables.Add(ResIncomeDT)
ResIncNomDT.TableName = "ResIncNomDT"
ExportDS.Tables.Add(ResIncNomDT)
ResExpensesDT.TableName = "ResExpensesDT"
ExportDS.Tables.Add(ResExpensesDT)
ResExpNomDT.TableName = "ResExpNomDT"
ExportDS.Tables.Add(ResExpNomDT)
RevenueDT.TableName = "RevenueDT"
ExportDS.Tables.Add(RevenueDT)
ExpensesDT.TableName = "ExpensesDT"
ExportDS.Tables.Add(ExpensesDT)
RevenueNomDT.TableName = "RevenueNomDT"
ExportDS.Tables.Add(RevenueNomDT)
ExpensesNomDT.TableName = "ExpensesNomDT"
ExportDS.Tables.Add(ExpensesNomDT)
Else
ExportDS.Tables.Remove("ResIncomeDT")
ExportDS.Tables.Remove("ResIncNomDT")
ExportDS.Tables.Remove("ResExpensesDT")
ExportDS.Tables.Remove("ResExpNomDT")
ExportDS.Tables.Remove("RevenueDT")
ExportDS.Tables.Remove("ExpensesDT")
ExportDS.Tables.Remove("RevenueNomDT")
ExportDS.Tables.Remove("ExpensesNomDT")
ExportDS.Tables.Add(ResIncomeDT)
ExportDS.Tables.Add(ResIncNomDT)
ExportDS.Tables.Add(ResExpensesDT)
ExportDS.Tables.Add(ResExpNomDT)
ExportDS.Tables.Add(RevenueDT)
ExportDS.Tables.Add(ExpensesDT)
ExportDS.Tables.Add(RevenueNomDT)
ExportDS.Tables.Add(ExpensesNomDT)
ExportDS.Tables.Remove("VariablesDT")
For Each row As DataRow In VariablesDT.Rows
row("Current_HOA_Name") = Current_HOA_Name
row("current_HOA_ID") = Current_HOA_ID
row("ReportFontSize") = ReportFontSize
row("User_InternationalDate") = User_InternationalDate
row("PaperSize") = PaperSize
row("PaperLandscape") = PaperLandscape
row("Reports_IsSplitGL") = False
row("ReportStartDate") = ReportStartDate
row("ReportEndDate") = ReportEndDate
row("ReportName") = ReportName
row("Form_ID") = Form_ID
Next
ExportDS.Tables.Add(VariablesDT)
End If
Dim vImage As New LoadingImage
LoadingStarted("Uploading to xSoftware... Please wait...", vImage)
Await Task.Run(Sub()
Using vService As New Service5Client
vPDF = vService.ReturnProfitAndLossSheet(ExportDS)
End Using
End Sub)
LoadingCompleted("File uploaded to xSoftware...", "File was uploaded and PDF returned...", vImage)
Dim vFile As String = ByteToFilePath(vPDF)
If System.IO.File.Exists(vFile) Then
Dim P As New Process
With P
.StartInfo.FileName = vFile
.StartInfo.Verb = "Open"
.Start()
End With
Else
AppBoxError("The file path for the PDF is not valid!")
End If
End If
Catch ex As Exception
EmailError(ex)
End Try
End Sub
Throws an error at the server end if we remove and add the datatables back to the DataSet
Dim RevenueData() As DataRow = RevenueDT.Select("FormID = " & Form_ID, "Position")
Dim ExpenseData() As DataRow = ExpensesDT.Select("FormID = " & Form_ID, "Position")
Dim RevenueNomData() As DataRow = RevenueNomDT.Select("FormID = " & Form_ID, "Position")
Dim ExpenseNomData() As DataRow = ExpensesNomDT.Select("FormID = " & Form_ID, "Position")
It looks like the answer is
Remove the DataTables from the DataSet and add them again (which got us part of the way there)
Name the DataTables again!
ExportDS.Tables.Remove("ResIncomeDT")
ExportDS.Tables.Remove("ResIncNomDT")
ExportDS.Tables.Remove("ResExpensesDT")
ExportDS.Tables.Remove("ResExpNomDT")
ExportDS.Tables.Remove("RevenueDT")
ExportDS.Tables.Remove("ExpensesDT")
ExportDS.Tables.Remove("RevenueNomDT")
ExportDS.Tables.Remove("ExpensesNomDT")
ExportDS.Tables.Remove("VariablesDT")
VariablesDT.TableName = "VariablesDT"
ExportDS.Tables.Add(VariablesDT)
ResIncomeDT.TableName = "ResIncomeDT"
ExportDS.Tables.Add(ResIncomeDT)
ResIncNomDT.TableName = "ResIncNomDT"
ExportDS.Tables.Add(ResIncNomDT)
ResExpensesDT.TableName = "ResExpensesDT"
ExportDS.Tables.Add(ResExpensesDT)
ResExpNomDT.TableName = "ResExpNomDT"
ExportDS.Tables.Add(ResExpNomDT)
RevenueDT.TableName = "RevenueDT"
ExportDS.Tables.Add(RevenueDT)
ExpensesDT.TableName = "ExpensesDT"
ExportDS.Tables.Add(ExpensesDT)
RevenueNomDT.TableName = "RevenueNomDT"
ExportDS.Tables.Add(RevenueNomDT)
ExpensesNomDT.TableName = "ExpensesNomDT"
ExportDS.Tables.Add(ExpensesNomDT)
Now it appears to be working correctly :-)
My target is to crawl image url and image alt tag using scrapy . I tried many combinations but still didn't achieve it.
Here is what i tried
def parse_item(self, response):
sel = Selector(response)
item = imageItem()
item['crawl_time'] = time.asctime( time.localtime(time.time()))
item['crawl_date'] = time.asctime( time.localtime(time.strftime("%Y%m%d")))
item['url'] = response.url
for img in hxs.select('//img'):
item['title'] = node.xpath("#alt").extract()
item['iurl'] = node.xpath("#src").extract()
if response.meta['depth'] == 1:
exit
return item
Some issues there:
You already have sel selector. But you use hxs in the loop
in the loop, you are using node instead of img
does it make more sense that each loop should yield one image item
This is my tested and working code:
def parse_item(self, response):
sel = Selector(response)
images = sel.xpath('//img')
for img in images:
item = imageItem()
item['url'] = response.url
title = img.xpath('./#alt').extract() or ''
item_title = title[0] if title else ''
item['title'] = item_title
iurl = img.xpath('./#src').extract() or ''
item_iurl = iurl[0] if iurl else ''
item['iurl'] = item_iurl
yield item
Here is the below code using which I achieved the result , but depth is still 1
class MySpider(CrawlSpider):
name = 'imageaggr'
start_urls = ['http://www.dmoz.org/','http://timesofindia.indiatimes.com/','http://www.nytimes.com','http://www.washingtonpost.com/','http://www.jpost.com','http://www.rediff.com/']
rules = (
# Extract links matching 'category.php' (but not matching 'subsection.php')
# and follow links from them (since no callback means follow=True by default).
Rule(SgmlLinkExtractor(allow=('', ), deny=('defghi\.txt')), callback='parse_item'),
# Extract links matching 'item.php' and parse them with the spider's method parse_item
# Rule(SgmlLinkExtractor(allow=('\.cms','\.html' )), deny=('parse_item\.html'))),
#Rule(SgmlLinkExtractor(allow=('news', )), callback='parse_item'),
)
def parse_item(self, response):
sel = Selector(response)
images = sel.xpath('//img')
image_count = len(images)
count = 0
while(count < image_count):
item = imageItem()
item['url'] = response.url
title = sel.xpath('//img/#alt').extract()[count] or ''
if title == '':
break
item['title'] = title
iurl = sel.xpath('//img/#src').extract()[count] or ''
item['iurl'] = iurl
item['crawl_time'] = time.asctime( time.localtime(time.time()))
crawl_date = time.strftime("%Y%m%d")
item['crawl_date'] = crawl_date
count = count + 1
return item