jscript file reading - Input past end of file [closed] - jscript

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have a simple file like:
124
123
122
121
120
I try to read it in softimage using jscript.
I have this:
var ForReading = 1;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fileObj = fso.GetFile("F:\\temp\\csv_reader_01.txt");
var ts = fileObj.OpenAsTextStream(ForReading, 0 );
while(!ts.AtEndOfSream) {
var textLine = ts.ReadLine();
LogMessage(textLine);
}
ts.Close();
LogMessage("done");
With the following output:
// INFO : 124
// INFO : 123
// INFO : 122
// INFO : 121
// INFO : 120
// ERROR : Input past end of file - [line 29]
It goes wrong at this line:
var textLine = ts.ReadLine();
How can this be solved, i would excpect the ! AtEndOfSream to do this.

Is ts.AtEndOfSream a typo? It should be ts.AtEndOfStream (notice the missing 't' in 'Stream').

Related

Convert http payload to string for debugging

I am using this C++ code on an ESP8266 to check on several http accessible data. Once in a while this device acts strangelay and I would like to be able to look at the data it gets. So I collect all payloads to be able to check it via rest api. The following code ALMOST works
String payloadAll = "start ###";
http.begin(client, getLink2);
httpCode = http.GET();
if ( httpCode > 0 ) { payload = http.getString(); payloadAll = payloadAll + payload.c_str() + "### ENDE-PAYLOAD1 ###"; }
the output looks like this:
start ###Internals: DEF 1 60 192.168.40.1:1502 TCP DeviceName 192.168.40.1:1502 EXPECT idle FD 6 FUUID 5xxxxx-fxxx-9xxx-fxxx-exxxxxxxxxxx IODev SolarEdge Interval 60 LASTOPEN 1647580317.55657 MODBUSID 1 MODE master MODEL SE8K-XXXXXXXXXX### ENDE-PAYLOAD1 ###
That is the first line of the payload only. I don't know much about the formast the requested data is in but once it is in the String, I can search ind find keyword and such from the lines I don't see in the output, so I know the data is there. If I leave out the ".c_str()" part, I will only get "start ###### ENDE-PAYLOAD1 ###"
How can I get all the lines - formatting is not important - it can all be one line, I just need to be able to see it as plain text.
Thanks!

Python Dictionary : '{num} = {title}'.format(**dict(num=7, title='Strings'))

I have doubt regarding this specific line
'{num} = {title}'.format(**dict(num=7, title='Strings'))
'7 = Strings'
I couldn't understand how **dict is working here. if anybody could help me on this.

Node-red output a message to CSV

For the past couple of days I have been trying and reading to get something very specific done in Node-Red: I want to send the (LoRa) message to a CSV.
This CSV should contain the following items:
topic
date
payload
I can insert the date using a function node:
var str1 = Date();
I have been playing around with CSV node, but I can't get it to output comma separated values. All this has probably to do with my lack of javascript programming skills, which is why I turn to you.
Can you help me out?
Edit:
I'm still looking for the answer, which has brought me the following:
Function node:
var res = Date() + "," + msg.topic + "," + msg.payload; return [ { payload: res } ];
Output:
[{"col1":"Mon Oct 17 2016 17:10:20 GMT+0200 (CEST)","col2":"1/test/1","col3":"string1"}]
All I want now is to lose the extra information such as column names and [{}]
The CSV node works only on the msg.payload field so you will have to copy the extra data into the payload object to get it to output what you want.
So to format the data correctly you need to place a function node with the following before the CSV node:
var originalPayload = msg.payload;
var newPayload = {};
newPayload.date = new Date().toString();
newPayload.topic = msg.topic;
newPayload.payload = originalPayload;
msg.payload = newPayload;
return msg;
And configure the CSV node to output columns "date,topic,payload"

(VB) Reading from CSV, finding row with value and writing into text file

I am trying to read .csv file contents, then find the records which contain letter N, and export the rest of the row which contains that N to external .txt file.
At this point, there are total of 12 customers and 7 of them contain my needed letter N. I want them all to be exported. Only the first one which is found gets exported.
CSV file{A column and B column}
John 345N
Andy 346K
Andrew 564B
Richard 645N
John 563N
Andy 345N
Andrew 346K
Richard 564B
John 645N
Andy 563N
Andrew 345N
Richard 346K
Code:
Dim currentRow As String()
Dim customerName(11) As String
Dim idAndProduct(11) As String
Dim FileWriter As StreamWriter
Using FileReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\Files\customers.csv")
FileReader.TextFieldType = FileIO.FieldType.Delimited
FileReader.SetDelimiters(",")
For index = 0 To 11
currentRow = FileReader.ReadFields
customerName(index) = currentRow(0)
idAndProduct(index) = currentRow(1)
Next index
For counter = 0 To 11
If Mid$(idAndProduct(counter), 4, 1) = "N" Then
FileWriter = New StreamWriter("C:\Files\export.txt")
FileWriter.WriteLine(customerName(counter) & "," & idAndProduct(counter))
FileWriter.Close()
End If
Next counter
End Using
Output(only one line gets exported instead of all 7):
Andrew,345N
How can I make all 7 get exported ?
I would be thankful for any answer !
EDIT To solve this problem, code needs to be changed from FileWriter = New StreamWriter("C:\Files\export.txt") to FileWriter = New StreamWriter("C:\Files\export.txt", True) to prevent the file from overwriting.

JAudioTagger Deleting First Few Seconds of Track

I've written a simple Groovy script (below) to set the values of four of the ID3v1 and ID3v2 tag fields in mp3 files using the JAudioTagger library. The script successfully makes the changes but it also deletes the first 5 to 10 seconds of some of the files, other files are unaffected. It's not a big problem, but if anyone knows a simple fix, I would be grateful. All the files are from the same source, all have v1 and v2 tags, I can find no obvious difference in the source files to explain it.
import org.jaudiotagger.*
java.util.logging.Logger.getLogger("org.jaudiotagger").setLevel(java.util.logging.Level.OFF)
Integer trackNum = 0
Integer totalFiles = 0
Integer invalidFiles = 0
validMP3File = true
def dir = new File(/D:\Users\Jeremy\Music\Speech Radio\Unlistened\Z Temp Files to MP3 Tagged/)
dir.eachFile({curFile ->
totalFiles ++
try {
mp3File = org.jaudiotagger.audio.AudioFileIO.read(curFile)
} catch (org.jaudiotagger.audio.exceptions.CannotReadException e) {
validMP3File = false
invalidFiles ++
}
// Get the file name excluding the extension
baseFilename = org.jaudiotagger.audio.AudioFile.getBaseFilename(curFile)
// Check that it is an MP3 file
if (validMP3File) {
if (mp3File.getAudioHeader().getEncodingType() != 'mp3') {
validMP3File = false
invalidFiles ++
}
}
if (validMP3File) {
trackNum ++
if (mp3File.hasID3v1Tag()) {
curTagv1 = mp3File.getID3v1Tag()
} else {
curTagv1 = new org.jaudiotagger.tag.id3.ID3v1Tag()
}
if (mp3File.hasID3v2Tag()) {
curTagv2 = mp3File.getID3v2TagAsv24()
} else {
curTagv2 = new org.jaudiotagger.tag.id3.ID3v23Tag()
}
curTagv1.setField(org.jaudiotagger.tag.FieldKey.TITLE, baseFilename)
curTagv2.setField(org.jaudiotagger.tag.FieldKey.TITLE, baseFilename)
curTagv1.setField(org.jaudiotagger.tag.FieldKey.ARTIST, "BBC Radio")
curTagv2.setField(org.jaudiotagger.tag.FieldKey.ARTIST, "BBC Radio")
curTagv1.setField(org.jaudiotagger.tag.FieldKey.ALBUM, "BBC Radio - 20130205")
curTagv2.setField(org.jaudiotagger.tag.FieldKey.ALBUM, "BBC Radio - 20130205")
curTagv1.setField(org.jaudiotagger.tag.FieldKey.TRACK, trackNum.toString())
curTagv2.setField(org.jaudiotagger.tag.FieldKey.TRACK, trackNum.toString())
mp3File.setID3v1Tag(curTagv1)
mp3File.setID3v2Tag(curTagv2)
mp3File.save()
}
})
println """$trackNum tracks created from $totalFiles files with $invalidFiles invalid files"""
I'm still investigating and it appears that there is no problem with JAudioTagger. Before setting the tags, I use Total Recorder to reduce the quality of the download from 128kbps, 44,100Hz to 56kbps, 22,050Hz. This reduces the file size to less than half and the quality is fine for speech radio.
If I run my script on the original files, none of the audio track is deleted. The deletion of the first part of the audio track only occurs with the files that have been processed by Total Recorder.
Looking at the JAudioTagger logging for these files, there does appear to be a problem with the header:
Checking further because the ID3 Tag ends at 0x23f9 but the mp3 audio doesnt start until 0x7a77
Confirmed audio starts at 0x7a77 whether searching from start or from end of ID3 tag
This check is not performed for files that have not been processed by Total Recorder.
The log of the header read operation also shows (for a 27 minute track):
trackLength:06:52
It looks as though I shall have to find a new MP3 file editor!
Instead of
mp3File.save()
could you try:
mp3File.commit()
No idea if it will help, but that seems to be the documented method?

Resources