Appending a tag at targeted place - python-3.x

strong text
I have following output
I want to add tags before and after "reporting formalities"
I also want to add tags before means and after the full stop . or semi ;
finally export the appended file
I have This file name is: /content/data/32010L0065.xml
tag name: heading
text name: Definitions
tail name:
/tMy next sibling is: {http://docs.oasis-open.org/legaldocml/ns/xml/3.0}list
"reporting formalities" means the information set out in the Annex which;
"electronic transmission of data" means the process of transmitting information that has been encoded digitally, using a revisable.
file_content = open ('.akn_file', 'a+')
file_content.write
file_content.close()

Related

How can I change a variable in a .txt template, if I have more than 5000 different values for this variable in an excel table?

I have an excel table with a column called 'interface', and what I want to do is a code that pull each interface value : Port-channel47, Port-channel46,etc... and put it in my .txt template replacing the {interface} part that i have in my txt template.
the value I want to change in the .txt template is "{interface}"
I tried this code:
but I get lost when i want to pull the data.
Anyone can help me? thank you so much in advance
Use string template:
from string import Template
with open('template.txt') as fp:
template = Template(fp.read())
for interface, group in df.groupby('Interface'):
file_name = interface.replace('/', '_') + '_output.txt'
with open(file_name, 'w') as fp:
content = template.substitute(interface=interface)
fp.write(content)
When you iterate over a DataFrameGroupBy object, it returns a 2-tuple containing the key of the group, and all rows matching that key.
A second thing to worry about is that / is not a valid path under most OSes I know so you must replace it with some other character (I chose a _).

Perl script to edit an item via CLI in MKS Integrity?

I want to add one word in the beginning of "RQ_Description Text" field, keeping the existing content as it is.
The below script gets the job done, However the Rich text content and images are lost in the process.
How would I preserve it?
NOTE: I'm working on a Requirement Document in MKS/IMS Integrity Tool
#This script is used to edit "RQ_Description Text".
#The file "input.txt" contains the Integrity item IDs
open FH,"<D:/input.txt";
while(<FH>)
{
# READ ITEM IDS
my $new_chapter_id=$_;
$new_chapter_id=~s/[^0-9]//g;
#READ THE CONTENTS OF RQ_DESCRIPTION TEXT FIELD
my $command_export_read="im issues --fields=\"RQ_Description Text\" $new_chapter_id" ;
my $command_output_export_read = qx($command_export_read);
#ADD THE INTENDED TEXT TO THE EXISTING CONTENT
$command_output_export_read = 'Abhishek'.$command_output_export_read;
my $command_export_edit="im editissue --richContentField=\"RQ_Description Text=$command_output_export_read\""." $new_chapter_id" ;
#UPDATE IN INTEGRITY
my $command_output_export_edit = qx($command_export_edit);
}
close FH;

Add front matter to markdown in Node

I am trying to generate .md files by Nodejs, and the file should contain the front matter.
This is what I am doing:
let {title,date,markdown_content}=document;
let fileContent = `
---
title: '${title}'
date: ${date}
---
${markdown_content}
`;
Now the title may contain special characters like " ' and etc(find more in this post).
Any nodejs library can be used out of box to do this job? Or I will have to replace the characters manually.

ReportLab - Metadata, CreationDate and ModificationDate

How can I change metadata fields, CreationDate and ModificationDate, when I create a pdf with Reportlab?
Take a look at where modification and creation dates are set:
D['ModDate'] = D["CreationDate"] = \
Date(ts=document._timeStamp,dateFormatter=self._dateFormatter)
# ...
return PDFDictionary(D).format(document)
Basically, metadata is a dictionary saved at the end of binary string, start of string is file contents (document).
Inside Reportlab the workflow you ask about can be:
create canvas
draw something on it
get document from canvas
create PDFDictionary with artificial mod and create dates
format document with PDFDictionary
save to file
Change metadata of pdf file with pypdf also attempts similar goal.
The ReportLab (currently 3.5) Canvas provides public methods, like Canvas.setAuthor(), to set the /Author, /Title, and other metadata fields (called "Internal File Annotations" in the docs, section 4.5).
However, there is no method for overriding the /CreationDate or /ModDate.
If you only need to change the formatting of the dates, you can simply use the Canvas.setDateFormatter() method.
The methods described above modify a PDFInfo object, as can be seen in the source, but this is part of a private PDFDocument (as in Canvas._doc.info).
If you really do need to override the dates, you could either hack into the private parts of the canvas, or just search the content of the resulting file object for /CreationDate (...) and /ModDate (...), and replace the value between brackets.
Here's a quick-and-dirty example that does just that:
import io
import re
from reportlab.pdfgen import canvas
# write a pdf in a file-like object
file_like_obj = io.BytesIO()
p = canvas.Canvas(file_like_obj)
# set some metadata
p.setAuthor('djvg')
# ... add some content here ...
p.save()
# replace the /CreationDate (similar for /ModDate )
pdf_bytes = file_like_obj.getvalue()
pdf_bytes = re.sub(b'/CreationDate (\w*)', b'/CreationDate (D:19700101010203+01)', pdf_bytes)
# write to actual file
with open('test.pdf', 'wb') as pdf:
pdf.write(pdf_bytes)
The example above just illustrates the principle. Obviously one could use fancy regular expressions with lookaround etc.
From the pdf spec:
Date values used in a PDF shall conform to a standard date format, which closely follows that of the international standard ASN.1 (Abstract Syntax Notation One), defined in ISO/IEC 8824. A date shall be a text string of the form
( D : YYYYMMDDHHmmSSOHH' mm )

What is different about these two pairs of strings that makes this sed script with one and not the other?

This question is related to this other question I asked earlier today:
Find and replace text with all-inclusive wild card
I have a text file like this
I want= to keep this
This is some <text> I want to keep <and "something" in tags that I" want to keep> aff FOO1 WebServices and some more "text" that" should "</be> </deleted>
<this is stuff in tags I want=to begone> and other text I want gone too. </this is stuff in tags I want to begone>
A novice programmer walked into a "BAR2" descript keepthis
and this even more text, let's keep it
<I actually want this>
and this= too.`
when I use sed -f script.sed file.txt to run this script:
# Check for "aff"
/\baff\b/ {
# Define a label "a"
:a
# If the line does not contain "desc"
/\bdesc\b/!{
# Get the next line of input and append
# it to the pattern buffer
N
# Branch back to label "a"
ba
}
# Replace everything between aff and desc
s/\(\baff\)\b.*\b\(desc\b\)/\1TEST DATA\2/
}
I get this as my output:
I want= to keep this
This is some <text> I want to keep <and "something" in tags that I" want to keep> aff FOO1 WebServices and some more "text" that" should "</be> </deleted>
<this is stuff in tags I want=to begone> and other text I want gone too. </this is stuff in tags I want to begone>
A novice programmer walked into a "BAR2" descript keepthis
and this even more text, let's keep it
<I actually want this>
and this= too.
However, by simply changing the search strings from aff and desc to FOO1 and BAR2:
# Check for "FOO1"
/\bFOO1\b/ {
# Define a label "a"
:a
# If the line does not contain "BAR2"
/\bBAR2\b/!{
# Get the next line of input and append
# it to the pattern buffer
N
# Branch back to label "a"
ba
}
# Replace everything between FOO1 and BAR2
s/\(\bFOO1\)\b.*\b\(BAR2\b\)/\1TEST DATA\2/
}
gives the expected output:
I want= to keep this
This is some <text> I want to keep <and "something" in tags that I" want to keep> aff FOO1TEST DATABAR2" descript keepthis
and this even more text, let's keep it
<I actually want this>
and this= too.`
I am completely stumped about what is going on here. Why should searching between FOO1 and BAR2 work differently from the exact same script with aff and desc?
The end marker should be \bdesc instead of \bdesc\b.
Note the \b in the pattern, it matches a word boundary. Your above text contains the word description, but not desc.
Your previous question made me assume that you want that. If you don't care about word boundaries, remove the \b escape sequences completely.

Resources