Is there anyway to read .one(OneNote files) using Python script? - python

I am trying to read .one file(OneNote files) and want to write its content into a text file, but didn't find a single way to do it using Python. Please help me with this.

Try to get the content of your notes calling:
./me/onenote/pages/1-1c13bcbae2fdd747a95b3e5386caddf1!1-xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx/content?includeIDs=true&includeInkML=true&preAuthenticated=true
It will give you text/html, which you can parse with https://pypi.org/project/lxml/

I didn't find a good way to decode .one file.
But I find another way to workaround it.
Install OneNote 2016 and sync the contents.
Install the Evernote legacy version
Import data from OneNote to Evernote. (There's a button on GUI).
Export notes to html from Evernote.
Then you can do whatever you want. Yeah!

This isn't Python, but for other internet voyagers trying to escape Microsoft's iron grip this PowerShell script is pure magic.
https://passbe.com/2019/bulk-export-onenote-2013-2016-pages-as-html/

Related

Internet Shortcut in python

I have a problem. Let's say I have a website (e.g. www.google.com). Is there any way to create a file with a .url extension linking to this website in python? (I am currently looking for a flat, and I am trying to save shortcuts on my hard drive only to apartment offers posted online matching my expectations ) I've tried to use the os and requests module to create such files, but with no success. I would really appreciate the help. (I am using python 3.9.6 on Windows 10)
This is pretty straightforward. I had no idea what .URL files were before seeing this post, so I decided to drag its URL to my desktop. It created a file with the following contents which I viewed in Notepad:
[InternetShortcut]
URL=https://stackoverflow.com/questions/68304057/internet-shortcut-in-python
So, you just need to write out the same thing via Python, except replace the URL with the one you want:
test_url = r'https://www.google.com/'
with open('Google.url','w') as f:
f.write(f"""[InternetShortcut]
URL={test_url}
""")
With regards to your current attempts:
I've tried to use os and requests module to create such file
It's not clear what you're using requests or os for, since you didn't provide a Minimal Reproduceable Example of what you'd tried so far; so, if there's a more complex element to this that you didn't specify, such as automatically generating the file while you're in your browser, or something like that, then you need to update your question to include all of your requirements.

Using python to build a latex document

I have a script I have written in python which pulls data from a bunch of files on my computer which change daily. I want to insert the results into a latex template so that I can review the summary.
What is the best way to open a file and insert text into it at a specific point?
Preferably using a python, but I'm open to other tools if there is something better.
Thanks
Russ
You could also do it all from within python using the pylatex library.
https://github.com/JelteF/PyLaTeX
This way you only have to run the python file every day.
I figured out how to do it.
It seems to me the best way is to have python output low level latex code, then use latex's command \input to pull that code into a larger document.
https://en.wikibooks.org/wiki/LaTeX/Modular_Documents

Sublime Text dynamic tmLanguage file

I have an issue on my github project that is meant to maintain a EJS syntax definition file for Sublime Text editor. (https://github.com/samholmes/EJS.tmLanguage/issues/1)
The issue is that users want to be able to customize what the opening and closing tags should be in EJS. I've set it to <? and ?> respectively, because I prefer this personally. However, the "correct" or should I say the recommended default open and closing tags are <% and %> as you'll find on the EJS website.
So, what I'm wondering is if there is a way to customize this per installation of this package? I wouldn't know how this would work though. tmLanguage files are just XML files. So, my question is. On this line:
https://github.com/samholmes/EJS.tmLanguage/blob/master/EJS.tmLanguage#L579
Is there a way to make the regular expression generated by some setting file?
Any ideas on how I could solve this would be highly appreciated. I'm not familiar with Sublime's features or python API, so anyone with more information on this, please let me know what it is you think I should do.

xml writer/editor -- use python's version?

I need to learn/write XML and I already have python downloaded as I am also learning python. I did notice that there was another question on stackoverflow about xml writers and python but I didn't get the idea that there was real consensus on what's easiest to use? That is, I would ideally like an XML editor that highlights my errors and helps with formatting as it can be very tedious. Should I stick with python's element tree xml app or download one of the following that I was told about? Thanks.
http://netbeans.org/downloads/index.html
download Java SE and just use its editor
XML Notepad 2007
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=72d6aa49-787d-4118-ba5f-4f30fe913628&DisplayLang=en#AffinityDownloads
You're asking about two separate things.
XML Notepad and the NetBeans utility are apps for visually creating and editing XML.
Python's ElementTree is a library for programmatically creating and parsing XML.
Which one you need depends on what you want to do - create XML in an editor, or do it inside your program.
I use IntelliJ (community edition should be fine) and emacs for XML editing.
I used the Altova XMLSpy family back in the days I used windows.

python convert microsoft office docs to plain text on linux

Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.
I'd go for the command line-solution (and then use the Python subprocess module to run the tools from Python).
Convertors for msword (catdoc), excel (xls2csv) and ppt (catppt) can be found (in source form) here: http://vitus.wagner.pp.ru/software/catdoc/.
Can't really comment on the usefullness of catppt but catdoc and xls2csv work great!
But be sure to first search your distributions repositories... On ubuntu for example catdoc is just one fast apt-get away.
You can access OpenOffice via Python API.
Try using this as a base: http://wiki.services.openoffice.org/wiki/Odt2txt.py
The usual tool for converting Microsoft Office documents to HTML or other formats was mswordview, which has since been renamed to vwWare.
If you're looking for a command-line tool, they actually recommend using AbiWord to perform the conversion:
AbiWord --to=txt
If you're looking for a library, start on the wvWare overview page. They also maintain a list of libraries and tools which read MS Office documents.
At the command line, antiword or wv work very nicely for .doc files. (Not a Python solution, but they're easy to install and fast.)
Same problem here. Below is my simple script to convert all doc files in dir 'docs/' to dir 'txts/' using catdoc. Hope it will help someone:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import glob, re, os
f = glob.glob('docs/*.doc') + glob.glob('docs/*.DOC')
outDir = 'txts'
if not os.path.exists(outDir):
os.makedirs(outDir)
for i in f:
os.system("catdoc -w '%s' > '%s'" %
(i, outDir + '/' + re.sub(r'.*/([^.]+)\.doc', r'\1.txt', i,
flags=re.IGNORECASE)))
For dealing with Excel Spreadsheets xlwt is good. But it won't help with .doc and .ppt files.
(You may have also heard of PyExcelerator. xlwt is a fork of this and better maintained so I think you'd be better of with xlwt.)
I've had some success at using XSLT to process the XML-based office files into something usable in the past. It's not necessarily a python-based solution, but it does get the job done.

Categories