Popular Python recipes tagged "meta:requires=json"http://code.activestate.com/recipes/langs/python/tags/meta:requires=json/2016-05-27T01:07:42-07:00ActiveState Code RecipesPDF Text Extraction using fitz / MuPDF (PyMuPDF) (Python)
2016-03-17T12:00:06-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580626-pdf-text-extraction-using-fitz-mupdf-pymupdf/
<p style="color: grey">
Python
recipe 580626
by <a href="/recipes/users/4193772/">Jorj X. McKie</a>
(<a href="/recipes/tags/cbz/">cbz</a>, <a href="/recipes/tags/epub/">epub</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/openxps/">openxps</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/text_extraction/">text_extraction</a>, <a href="/recipes/tags/xps/">xps</a>).
</p>
<p>Extract all the text of a PDF (or other supported container types) at very high speed.
In general, text pieces of a PDF page are not arranged in natural reading order, but in the order they were entered during PDF creation.
This script re-arranges text blocks according to their pixel coordinates to achieve a more readable output, i.e. top-down, left-right.</p>
How to parse a table in a PDF document (Python)
2016-04-10T22:43:57-07:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580635-how-to-parse-a-table-in-a-pdf-document/
<p style="color: grey">
Python
recipe 580635
by <a href="/recipes/users/4193772/">Jorj X. McKie</a>
(<a href="/recipes/tags/cbz/">cbz</a>, <a href="/recipes/tags/epub/">epub</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/openxps/">openxps</a>, <a href="/recipes/tags/parsing/">parsing</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>, <a href="/recipes/tags/table/">table</a>, <a href="/recipes/tags/xps/">xps</a>).
Revision 4.
</p>
<p>A Python function that converts a table contained in a page of a PDF (or OpenXPS, EPUB, CBZ, XPS) document to a matrix-like Python object (list of lists of strings).</p>
Convert JSON to PDF with Python and xtopdf (Python)
2014-12-10T18:02:14-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578979-convert-json-to-pdf-with-python-and-xtopdf/
<p style="color: grey">
Python
recipe 578979
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/pdfwriter/">pdfwriter</a>, <a href="/recipes/tags/sys/">sys</a>).
</p>
<p>This recipe show the basic steps needed to convert JSON input to PDF output, using Python and xtopdf, a PDF creation toolkit. xtopdf is itself written in Pytho, and uses the ReportLab toolkit internally.</p>
<p>We set up some needed values, such as the output PDF file name, the font name and size, the header and footer, and the input lines for the body of the PDF output; all these values are passed in JSON format (in a single dictionary) to a function that uses those values to generate a PDF file with the desired content.</p>
<p>The code is intentionally kept simple so as to require the least amount of code needed to demonstrate the techniques involved. But it can be generalized or extended to more complex situations.</p>
JSON Formatted Logging (Python)
2016-05-27T01:07:42-07:00Michael Blan Palmerhttp://code.activestate.com/recipes/users/4194130/http://code.activestate.com/recipes/580667-json-formatted-logging/
<p style="color: grey">
Python
recipe 580667
by <a href="/recipes/users/4194130/">Michael Blan Palmer</a>
(<a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>I have created a package that outputs JSON formatted lines to a log file. It can make use of the standard logging parameters and/or take custom input. The use of JSON in the log file allows for easy filtering and processing.</p>
Configurable JSON Extensions for Python (Python)
2016-05-22T19:00:54-07:00Michael Blan Palmerhttp://code.activestate.com/recipes/users/4194130/http://code.activestate.com/recipes/580664-configurable-json-extensions-for-python/
<p style="color: grey">
Python
recipe 580664
by <a href="/recipes/users/4194130/">Michael Blan Palmer</a>
(<a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>The concept behind the package is to build a single class per type you want to add to json in Python. The new class will have a method for encoding to json and a method for decoding from json. The classes are then loaded into an encoder object and a decoder object that are hooked into the standard json loads
and dumps functions.</p>
How to use Python to convert a web page to PDF with a POST request to SelectPdf Online API and save it on the disk (Python)
2015-11-16T14:52:17-08:00SelectPdfhttp://code.activestate.com/recipes/users/4193129/http://code.activestate.com/recipes/579126-how-to-use-python-to-convert-a-web-page-to-pdf-wit/
<p style="color: grey">
Python
recipe 579126
by <a href="/recipes/users/4193129/">SelectPdf</a>
(<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/htmltopdf/">htmltopdf</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/selectpdf/">selectpdf</a>).
</p>
<p>This code converts an url to pdf in Python using SelectPdf HTML To PDF REST API through a POST request. The parameters are JSON encoded. The content is saved into a file on the disk.</p>
Validate data easily with JSON Schema (Python)
2015-12-06T21:23:48-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579135-validate-data-easily-with-json-schema/
<p style="color: grey">
Python
recipe 579135
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/jsonschema/">jsonschema</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>).
</p>
<p>This recipe shows how to use the jsonschema Python library, which implements the JSON Schema specification, to easily validate your Python data. It sends good output to stdout and bad output to stderr, for demo purposes.</p>
<p>jsonschema Python library: <a href="https://pypi.python.org/pypi/jsonschema" rel="nofollow">https://pypi.python.org/pypi/jsonschema</a></p>
<p>JSON Schema: <a href="http://json-schema.org/" rel="nofollow">http://json-schema.org/</a></p>
vlc.py stream capture scheduler script (Python)
2015-08-19T05:00:25-07:00jwhite88http://code.activestate.com/recipes/users/4192711/http://code.activestate.com/recipes/579096-vlcpy-stream-capture-scheduler-script/
<p style="color: grey">
Python
recipe 579096
by <a href="/recipes/users/4192711/">jwhite88</a>
(<a href="/recipes/tags/recording/">recording</a>, <a href="/recipes/tags/stream/">stream</a>, <a href="/recipes/tags/vlc/">vlc</a>).
</p>
<p>Capture network streams using vlc.py on a schedule.</p>
Hivemind (Python)
2015-07-15T12:37:13-07:00Oscar Byrnehttp://code.activestate.com/recipes/users/4192487/http://code.activestate.com/recipes/579082-hivemind/
<p style="color: grey">
Python
recipe 579082
by <a href="/recipes/users/4192487/">Oscar Byrne</a>
(<a href="/recipes/tags/borg/">borg</a>, <a href="/recipes/tags/defaultdict/">defaultdict</a>, <a href="/recipes/tags/hash/">hash</a>, <a href="/recipes/tags/hashing/">hashing</a>, <a href="/recipes/tags/hivemind/">hivemind</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/singleton/">singleton</a>, <a href="/recipes/tags/state/">state</a>).
</p>
<p>Inspired by the ever-popular Borg pattern, objects inheriting from Hivemind share state if initialised with the same arguments</p>
dynamically changing encoder (for json) with metaclass (class factory) (Python)
2013-10-24T11:31:44-07:00-http://code.activestate.com/recipes/users/4188267/http://code.activestate.com/recipes/578696-dynamically-changing-encoder-for-json-with-metacla/
<p style="color: grey">
Python
recipe 578696
by <a href="/recipes/users/4188267/">-</a>
(<a href="/recipes/tags/class_factory/">class_factory</a>, <a href="/recipes/tags/encode/">encode</a>, <a href="/recipes/tags/json/">json</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/metaclasses/">metaclasses</a>).
</p>
<p>The <em>json.dumps</em> need to be feed with some class (cls =someClass) but what if we want to change the class dynamically?
This example can be done by declaring the <em>listOfClasses</em> in class level of course, but the idea is to be changeable. This can be done by the class factory function <em>encoderFacory</em></p>
Use 'Google Maps Elevation Service' to get elevation data for any location on Earth. (Python)
2012-08-12T20:47:29-07:00Aristotelis Stamatiadishttp://code.activestate.com/recipes/users/4183191/http://code.activestate.com/recipes/578239-use-google-maps-elevation-service-to-get-elevation/
<p style="color: grey">
Python
recipe 578239
by <a href="/recipes/users/4183191/">Aristotelis Stamatiadis</a>
(<a href="/recipes/tags/elevation/">elevation</a>, <a href="/recipes/tags/gis/">gis</a>, <a href="/recipes/tags/google_maps/">google_maps</a>).
</p>
<p>The Google Maps Elevation Service provides a simple interface for getting elevation data for any location on Earth, including locations under the sea (where the elevation is negative). </p>
<p>The following function is based on the examples presented in the Elevation API web page: <code><a href="https://developers.google.com/maps/documentation/elevation/%3C/code%3E." rel="nofollow">https://developers.google.com/maps/documentation/elevation/</code>.</a></p>
<p>Before using the Elevation Service you must read the rather strict usage limits set by Google in the above web page, especially the term that stipulates that "the Elevation API may only be used in conjunction with displaying results on a Google map; using elevation data without displaying a map for which elevation data was requested is prohibited."</p>
A small python script to detect .net framwork versions installed on your local windows machine (Python)
2012-05-23T15:33:13-07:00Yong Zhaohttp://code.activestate.com/recipes/users/4182173/http://code.activestate.com/recipes/578143-a-small-python-script-to-detect-net-framwork-versi/
<p style="color: grey">
Python
recipe 578143
by <a href="/recipes/users/4182173/">Yong Zhao</a>
(<a href="/recipes/tags/dotnet/">dotnet</a>, <a href="/recipes/tags/framework/">framework</a>, <a href="/recipes/tags/python_scripts/">python_scripts</a>, <a href="/recipes/tags/windows_registry/">windows_registry</a>, <a href="/recipes/tags/_winreg/">_winreg</a>).
</p>
<p>This small script uses the _winreg module to find out the .net framwork versions installed on your local machine. tested using IronPython 2.7.1.</p>
Persistent dict with multiple standard file formats (Python)
2011-09-06T20:01:46-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/576642-persistent-dict-with-multiple-standard-file-format/
<p style="color: grey">
Python
recipe 576642
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/dbm/">dbm</a>, <a href="/recipes/tags/dictionary/">dictionary</a>, <a href="/recipes/tags/persistent/">persistent</a>, <a href="/recipes/tags/shelve/">shelve</a>).
Revision 10.
</p>
<p>dbdict: a dbm based on a dict subclass.</p>
<p>On open, loads full file into memory.
On close, writes full dict to disk (atomically).
Supported output file formats: csv, json, and pickle.
Input file format automatically discovered.</p>
<p>Usable by the shelve module for fast access.</p>
JSON pretty printer (Python)
2011-06-28T11:23:13-07:00Noufal Ibrahimhttp://code.activestate.com/recipes/users/4173873/http://code.activestate.com/recipes/577772-json-pretty-printer/
<p style="color: grey">
Python
recipe 577772
by <a href="/recipes/users/4173873/">Noufal Ibrahim</a>
(<a href="/recipes/tags/json/">json</a>).
</p>
<p>Simple script to be used as a shell pipeline to pretty print JSON output. Quite useful when using couchdb with curl.</p>
<p>This is a shell function which uses Python to do all ork.</p>
Extract data from feedjit (Python)
2011-05-03T19:50:27-07:00jrovegnohttp://code.activestate.com/recipes/users/4170207/http://code.activestate.com/recipes/577683-extract-data-from-feedjit/
<p style="color: grey">
Python
recipe 577683
by <a href="/recipes/users/4170207/">jrovegno</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/feedjit/">feedjit</a>).
Revision 2.
</p>
<p>Script to extract data from my live traffic feed from feedjit</p>
transform command line arguments to args and kwargs for a method call (Python)
2010-03-21T22:41:42-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/577122-transform-command-line-arguments-to-args-and-kwarg/
<p style="color: grey">
Python
recipe 577122
by <a href="/recipes/users/4173505/">Trent Mick</a>
(<a href="/recipes/tags/argv/">argv</a>, <a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/json/">json</a>).
Revision 2.
</p>
<p>For many of my Python modules I find it convenient to provide a small <code>if __name__ == "__main__": ...</code> block to be able to call individual methods from the command line. This requires some kind of translation of command-line string arguments to <code>args</code> and <code>kwargs</code> for the method call. This recipe uses a few conventions to do that:</p>
<ul>
<li>the first argument is the method name</li>
<li>positional args are positional (duh)</li>
<li>"key=value" is a keyword argument</li>
<li>an attempt is made to interpret arguments as JSON to allow specifying types other than string</li>
</ul>