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
Related
This is literally day 1 of python for me. I've coded in VBA, Java, and Swift in the past, but I am having a particularly hard time following guides online for coding a pdf scraper. Since I have no idea what I am doing, I keep running into a wall every time I want to test out some of the code I've found online.
Basic Info
Windows 7 64bit
python 3.6.0
Spyder3
I have many of the pdf related code packages (PyPDF2, pdfminer, pdfquery, pdfwrw, etc)
Goals
To create something in python that allows me to convert PDFs from a folder into an excel file (ideallY) OR a text file (from which I will use VBA to convert).
Issues
Every time I try some sample code from guides i've found online, I always run into syntax errors on the lines where I am calling the pdf that I want to test the code on. Some guide links and error examples below. Should I be putting my test.pdf into the same file as the .py file?
How to scrape tables in thousands of PDF files?
I got an invalid syntax error due to "for" on the last line
PDFMiner guide (Link)
runfile('C:/Users/U587208/Desktop/pdffolder/pdfminer.py', wdir='C:/Users/U587208/Desktop/pdffolder')
File "C:/Users/U587208/Desktop/pdffolder/pdfminer.py", line 79
print pdf_to_csv('test.pdf', separator, threshold)
^
SyntaxError: invalid syntax
It seems that the tutorials you are following make use of python 2. There are usually few noticable differences, the the biggest is that in python 3, print became a funtion so
print()
I would recomment either changing you version of python or finding a tutorial for python 3. Hope this helps
Here
Pdfminer python 3.5 an example, how to extract informations from a PDF.
But it does not solve the problem with tables you want to export to Excel. Commercial products are probably better in doing that...
I am trying to do this exact same thing! I have been able to convert my pdf to text however the formatting is extremely random and messy and I need the tables to stay in tact to be able to write them into excel data sheets. I am now attempting to convert to XML to see if it will be easier to extract from. If I get anywhere on this I will let you know :)
btw, use python 2 if you're going to use pdfminer. Here's some help with pdfminer https://media.readthedocs.org/pdf/pdfminer-docs/latest/pdfminer-docs.pdf
What is the easiest way to convert a string of Latex (e.g. "Consider the polynomial $x^2$") into a pdf within a Python web app? Ideally, this wouldn't require the creation of intermediate files that I would have to store in a database.
I tried downloading Texcaller (http://vog.github.io/texcaller/) but I could not get it to work. In particular, the key file python/texcaller.py has the line "import _texcaller" which gives the error "No module named _texcaller."
I'm thinking that there must be some way to do it because the Texer resource at AoPS (http://www.artofproblemsolving.com/Resources/texer.php) renders Tex as PDF almost instantaneously.
Thank you very much in advance!
I've recently written a library for the purpose of generating LaTeX code using python. It supports tables, plots, matrices and more. https://github.com/JelteF/PyLaTeX
I am interested in gleaning information from an ESRI .shp file.
Specifically the .shp file of a polyline feature class.
When I open the .dbf of a feature class, I get what I would expect: a table that can open in excel and contains the information from the feature class' table.
However, when I try to open a .shp file in any program (excel, textpad, etc...) all I get is a bunch of gibberish and unusual ASCII characters.
I would like to use Python (2.x) to interpret this file and get information out of it (in this case the vertices of the polyline).
I do not want to use any modules or non built-in tools, as I am genuinely interested in how this process would work and I don't want any dependencies.
Thank you for any hints or points in the right direction you can give!
Your question, basically, is "I have a file full of data stored in an arbitrary binary format. How can I use python to read such a file?"
The answer is, this link contains a description of the format of the file. Write a dissector based on the technical specification.
If you don't want to go to all the trouble of writing a parser, you should take look at pyshp, a pure Python shapefile library. I've been using it for a couple of months now, and have found it quite easy to use.
There's also a python binding to shapelib, if you search the web. But I found the pure Python solution easier to hack around with.
might be a long shot, but you should check out ctypes, and maybe use the .dll file that came with a program (if it even exists lol) that can read that type of file. in my experience, things get weird when u start digging around .dlls
Hi I am new to dot file concept,
I am looking create ERD diagram with Primary keys and relationships. The approach is to whip up a Python script to read the database tables and to create a "dot" file which can then be used to generate the graphic using graphviz. I found the way to generate graph using dot file on graphviv.org, however I didn't found the way to use Python script to read the database tables and to create a "dot" file. Any help would really appreciate, thanks.
for graphviz modules you can check this
for database manipulation, it depends on the size and complexity of your data, but you can start with the sqlite3 python module
I wrote a crude script to do exactly this. It works only for mySQL for an engine that understands foreign keys (myISAM doesn't work). It does text parsing to get the keys and stuff so it's not as robust as one would expect. I wrote it quickly to analyse a medium sized database that I had to work on for a consulting project. Most of the parameters will have to be tweaked to work properly for you but you might be able to start off with it.
The code is available here and here is a scaled down version of an example database graphed by the tool.
I have an Excel spreadsheet with calculations I would like to use in a Django web application. I do not need to present the spreadsheet as it appears in Excel. I only want to use the formulae embedded in it. What is the best way to do this?
You can control Excel with Python via COM. See this thread: Driving Excel from Python in Windows
It might be a challenge to get this to work reliably as part of a Django app.
In addition to the COM solution, xlrd is cross-platform. That might be more suitable, since I believe Linux is still the most common deployment environment for django. It's also a lighter-weight solution than pyUno.
I think the only thing you can do is use some python/excel mechanism (the only one I could find was this: http://www.python-excel.org/; the tutorial makes me think it might be doable) to read and write from an excel spreadsheet.
You would write to certain cells that would be used by the spreadsheet formulas and then read the results from the formulas from other cells.
Django per-se has nothing to help you with this.
I'll retag your question to include python so that, maybe, someone with Python-excel experience can comment...
You need to use Excel to calculate the results? I mean, maybe you could run the Excel sheet from OpenOffice and use a pyUNO macro, which is somehow "native" python.
A different approach will be to create a macro to generate some more friendly code to python, if you want Excel to perform the calculation is easy you end up with a very slow process.