How to remove special characters when using .splitlines() - python-3.x

I have been working on a script that pulls email data from my gmail account.
Sometimes the output was printed on multiple lines, which caused the CSV formatting to malfunction.
In order to solve this issue, I have tried to use the .splitlines() command. This works really well, however the output looks like this now:
['ROSE Bikes News <newsletter#news.rosebikes.com>;10 % AUF DEUTER;22 Aug 2019 11:11:30']
Ideally I do not want the following characters ['CONTENT'].
I have tried to use the .strip() function without success.
content = (email_from + ';' + subject + ';' + local_message_date).splitlines()
print(content.strip("[']"))

Related

CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE csv parse for node?

I'm using a 3rd party application that throws this error:
Error: Invalid Closing Quote: found non trimable byte after quote at line 5
code: CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE
column: 16
empty_lines: 0
header: false
index: 16
invalid_field_length: 0
quoting: true
lines: 5
records: 4
when loading a csv file (I have to use this application). I think this application is using this node service: https://csv.js.org/parse/errors/
I also think the trouble is that column 16 has fields that look like this:
\Circular Logic 3\""
But I don't quite understand the issue.
Can anyone tell me if this column is not escaping the quotes properly? I have a ton of files and many instances like this in column 16 so it would be a pain to fix this manually.
It looks like proper escaping for double quotes in csv is another double quote. So the line should be:
\Circular Logic 3"""
We'll have to reformat the data.

IBM Domino xpage - parse iCalendar summary with new lines manually/ical4j

So far I was parsing the NotesCalendarEntry ics manually and overwriting certain properties, and it worked fine. Today i stumbled upon a problem, where a long summary name of the appointment gets split into multiple lines, and my parsing goes wrong, it replaces the part up to the first line break and the old part is still there.
Here's how I do this "parsing":
NotesCalendarEntry calEntry = cal.getEntryByUNID(apptuid);
String iCalE = calEntry.read();
StringBuilder sb = new StringBuilder(iCalE);
int StartIndex = iCalE.indexOf("BEGIN:VEVENT"); // care only about vevent
tmpIndex = sb.indexOf("SUMMARY:") + 8;
LineBreakIndex = sb.indexOf(Character.toString('\n'), tmpIndex);
if(sb.charAt(LineBreakIndex-1) == '\r') // take \r\n into account if exists
LineBreakIndex--;
sb.delete(tmpIndex, LineBreakIndex); // delete old content
sb.insert(tmpIndex, subject); // put my new content
It works when line breaks are where they are supposed to be, but somehow with long summary name, line breaks are put into the summary (not literal \r\n characters, but real line breaks).
I split the iCalE string by \r\n and got this (only a part obviously):
SEQUENCE:6
ATTENDEE;ROLE=CHAIR;PARTSTAT=ACCEPTED;CN="test/Test";RSVP=FALSE:
mailto:test#test.test
ATTENDEE;CUTYPE=ROOM;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED
;CN="Room 2/Test";RSVP=TRUE:mailto:room2#test.test
CLASS:PUBLIC
DESCRIPTION:Test description\n
SUMMARY:Very long name asdjkasjdklsjlasdjlasjljraoisjroiasjroiasjoriasoiruasoiruoai Mee
ting long name
LOCATION:Room 2/Test
ORGANIZER;CN="test/Test":mailto:test#test.test
Each line is one array element from iCalE.split("\\r\\n");. As you can see, the Summary field got split into 2 lines, and a space was added after the line break.
Now I have no idea how to parse this correctly, I thought about finding the index of next : instead of a new line break, and then finding the first line break before that : character, but that wouldn't work if the summary also contained a : after the injected line-break, and also wouldn't work on fields like that ORGANIZER;CN= as it doesn't use : but ;
I tried importing external ical4j jar into my xpage to overcome this problem, and while everything is recognized in Domino Designer it resulted in lots of NoClassDefFound exceptions after trying to reach my xpage service, despite the jars being in the build path and all.
java.lang.NoClassDefFoundError: net.fortuna.ical4j.data.CalendarBuilder
How can I safely parse this manually, or how can I properly import ical4j jar to my xpage? I just want to modify 3 fields, the DTSTART, DTEND and SUMMARY, with the dates I had no problems so far. Fields like Description are using literal \n string to mark new lines, it should be the same in other fields...
Update
So I have read more about iCalendar, and it seems that there is a standard for this called line folds, these are crlf line endings followed by a space. I made a while loop checking until the last line-break not followed by a space, and it works great so far. Will use this unless there's a better solution (ical4j is one, but I can't get it working with Domino)

Passing a DOS/Windows path in python

I run this code:
source_path="c:\temp\\"
dest_path="c:\\temp2\\"
for Name in UserNames:
run_win_cmd("robocopy "+ source_path + Name + "* "+ dest_path)
Name in UserNames gives a name like JBlackstone, and I get the following:
b'ERROR : Invalid Parameter #2 : "emp\\Flastone*"\r\n'
Complete with the b'. No matter how I seem to format the backslashes for the command line, it ends up wrong. Here it read \temp as tab emp. If I double backslashes \\temp\\ to the \, it puts in double backslashes. If I don't it reads them as formatting chararcters. I am using run_win_cmd to call the code.
Suggestions would be much appreciated.
I just rewrote it using Popen directly which appears to be the way most people do this in python now. I also pipe d stdout and stderr to a file. The process of doing that formatted the text correctly.

Strings Received via BLE appear on multiple lines

I am receiving strings from my peripheral fine but since the characteristics can only contain 20 bytes the data arrives in 3 loads. When adding this to a text field is no problem - it all appears in one line as desired but when I try to do things with this data it appears on multiple lines.
func serialDidReceiveString(_ message: String) {
mainTextView.text? += message
let allData = message
print(allData)
The result is :
194a1886a19901a19998
a233441a232332a11234
12a34123412
Essentially I am trying to get his all of this into one line but I seem to have tried all the standard methods including trimming characters for blankspaces and newlines etc.. The only method that seemed to work was if I used :
print(allData, terminator: "")
This would appear as one line but only in the debugging console - not much use.
Any suggestions??

Arduino String.replace() not working after file name change

I have encountered a strange failure when this code runs on my NodeMCU 0.9 board. It is basically getting http code from an API in the following format:
<abbr title="klokken">kl</abbr> 11–12
In this case I want to isolate the 11 and 12 by first removing the first 42 characters which works perfectly fine and then replacing the – with --. When I open a sketch and paste this program in it it runs perfectly fine and returns 11--12 but when I save this program under a random name it is rebuilt and for some reason doesn't replace the characters properly it then returns 11–12.
I have tried to replace different parts of the string when it was rebuilt which worked fine but for some reason I can't seem to either find the index of nor replace the three strange characters.
http.begin(URL_time);
int httpCode = http.GET();
String timerange;
if(httpCode > 0){
timerange = http.getString();
timerange.remove(0,42);
timerange.replace("–", "--");
Serial.println(timerange);
Thus my question is if anyone knows how to work around this issue apart from not saving my code. Feel free to ask me to elaborate on my question when needed.
The string you're receiving is encoded in Windows Latin 1 (ISO 8859-1), and you're (probably) using UTF-8. What you need is to re-encode the string properly.

Resources