Last active
September 1, 2023 13:03
-
-
Save sandervd/1bee6d6927fbd17e76b3a754de2e44a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uno | |
from pathlib import Path | |
from com.sun.star.beans import PropertyValue | |
from os.path import abspath | |
import getopt, sys | |
def create_instance(): | |
localContext = uno.getComponentContext() | |
resolver = localContext.ServiceManager.createInstanceWithContext( | |
"com.sun.star.bridge.UnoUrlResolver", localContext ) | |
try: | |
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) | |
except: | |
sys.stderr.write("""ERROR: Libreoffice must be running in the background: | |
soffice --accept='socket,host=localhost,port=2002;urp;StarOffice.Service' --headless | |
""") | |
sys.exit(1) | |
smgr = ctx.ServiceManager | |
return smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx) | |
def main(argv): | |
url = '' | |
opts, args = getopt.getopt(argv,"hi:",["input="]) | |
for opt, arg in opts: | |
if opt == '-h': | |
print ('comments.py -i <inputfile>') | |
sys.exit(1) | |
elif opt in ("-i", "--input"): | |
url = Path(abspath(arg)).as_uri() | |
desktop = create_instance() | |
loadArgs = [ | |
PropertyValue(Name="UpdateDocMode", Value=1), | |
#PropertyValue(Name="Hidden", Value=True) | |
] | |
doc = desktop.loadComponentFromURL(url, "_blank", 0, loadArgs) | |
model = desktop.getCurrentComponent() | |
oEnum = model.getTextFields().createEnumeration() | |
while oEnum.hasMoreElements(): | |
oField = oEnum.nextElement() | |
if oField.supportsService('com.sun.star.text.TextField.Annotation'): | |
print("---") | |
print("Author: " + oField.Author) | |
#['Day', 'Hours', 'IsUTC', 'Minutes', 'Month', 'NanoSeconds', 'Seconds', 'Year'] | |
date = oField.DateTimeValue.value | |
print("Date: " + str(date.Day) + "/" + str(date.Month) + "/" + str(date.Year) + " " + str(date.Hours) + ":" + str(date.Minutes)) | |
print("Content:") | |
print(oField.Content) | |
doc.dispose() | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment