Skip to content

Latest commit

 

History

History
83 lines (59 loc) · 2.54 KB

special-qrcode-factories.rst

File metadata and controls

83 lines (59 loc) · 2.54 KB

Special QR Code factory functions

The :pysegno.helpers module provides factory functions to create common QR codes for encoding WIFI configurations, vCards and MeCards <contact-information>, EPC QR Codes <epc-qrcodes> or geographic locations.

The created QR codes use at minimum the error correction level "L". If a better error correction level is possible without changing the QR Code version, the better error correction level will be used.

Create a QR code for a WIFI configuration

>>> from segno import helpers
>>> # Create a WIFI config with min. error level "L" or better
>>> qr = helpers.make_wifi(ssid='My network', password='secret', security='WPA')
>>> qr.designator
'3-M'

3-M QR code encoding a WIFI configuration

If you want more control over the creation of the QR code (i.e. using a specific version or error correction level, use the :pysegno.helpers.make_wifi_data factory function, which returns a string which encodes the WIFI configuration.

>>> import segno
>>> from segno import helpers
>>> config = helpers.make_wifi_data(ssid='My network', password='secret', security='WPA')
>>> config
'WIFI:T:WPA;S:My network;P:secret;;'
>>> # Create a QR Code with error correction level "H"
>>> qr = segno.make(config, error='h')
>>> qr.designator
'4-H'

4-H QR code encoding a WIFI configuration

Create a QR code encoding geographic information

>>> from segno import helpers
>>> latitude, longitude = 38.8976763,-77.0365297
>>> qr = helpers.make_geo(latitude, longitude)
>>> qr.designator
'2-M'

2-M QR code encoding a geographic informatiion

A factory function for encoding the geographic information as string is also available.

>>> import segno
>>> from segno import helpers
>>> latitude, longitude = 38.8976763, -77.0365297
>>> geo_uri = helpers.make_geo_data(latitude, longitude)
>>> geo_uri
'geo:38.8976763,-77.0365297'
>>> # Use error correction level "H"
>>> qr = segno.make(geo_uri, error='H')
>>> qr.designator
'4-H'

4-H QR code encoding a geographic informatiion