Some considerations about batch processing of QR Codes

This article is a continuation of the topics described in the previously published article “Some ideas about classified documents labeling and QR codes”.

The advantages of a batch (non-interactive) processing of QR codes do not have to be specially stressed by me, because they are visible even to the naked eye. They can be for instance used to supply the database of classified documents with the data.

In some circumstances we may want to generate QR codes and save them in the database in the semigraphic form, instead of bitmaps like for instance PNG file. Then a script similar to this listed below can come in handy.

The script code in Ruby language:

require 'rqrcode'
def encode (data)
   qr = RQRCode::QRCode.new(data)
   puts qr.to_s
end

if ARGV.length < 1
   puts "Proper syntax: ruby #{$0} filename"
   exit
else
   begin
      IO.foreach(ARGV[0]){ |line|
                            encode (line)
                            puts '-'*33
                         }
   rescue => error
      puts error.message
      puts error.backtrace
   end
end

The source data from file, to be encoded:

001:file-01:3d6d1146dc56af6:CONF
002:file-02:d219eed4f3b5315:INTR
003:file-03:f1885aea2457a4f:SCNF
004:file-04:3ddd4ecf76cc6d1:NOCL
005:file-05:0e8ffa22d023a93:CONF

Standard output of the script:

xxxxxxx xx  xx xx x x xx  xxxxxxx
x     x xx xxxx   xx   xx x     x
x xxx x    xxx   x xx xxx x xxx x
x xxx x x xx   x xxxx x   x xxx x
x xxx x xxx x xxxx  x   x x xxx x
x     x xxxx xxxxxxx  x   x     x
xxxxxxx x x x x x x x x x xxxxxxx
            xxxx x   xx x       
   x  x  x     x  xxxx x   xxx xx
   xxx    xxxxx x xxx     xx x  x
 x xx xx    x xxxx  xx   x x xxxx
xxxx x xxxxxx   xxx xx  xx x    x
xxx xxxxx  x xx   x x x   x xx x
xxx x   xx      x  xx x  xx x  xx
xxx x x x xx xxx  xxx  xxx x x  
   xx      x x  x xxxx xxx x x  
     xxx  x x x  x xxxx x x xx xx
x xxxx xxx  xx   xxx x xxx      
 x  x x   x  xx  x x    xx    x x
x   x  xx   x   xxxx xx xxx xx  x
  xxx x x x x x   x  xxxxx x   x
   x      x  xx   xx xxxxx x x  x
xx x xx     x x  xx x   xx x  xxx
 x x x    xx xxx x xxxxxxx x    x
x x x x  x xxxxxx  xxx xxxxxxx  x
        x x  x xxx    x x   x   x
xxxxxxx  xx  x xx x xx  x x xxx 
x     x  xx  x x    x  xx   xx  
x xxx x   xxx   x x x x xxxxxx  x
x xxx x xx x xxxx x  x xx x x xx
x xxx x  x x  x xxx     x   x   x
x     x  xx  xxx x xx  xx  xx   
xxxxxxx       x x  xxx  xxx xxxx
---------------------------------

….. STDOUT was shortened from the practical reason.

This script, as you can see, prints character type of data on the console, which depicts the QR codes in the semigraphic form. The source data used to supply the script with, comes from a text file whose name is specified as a mandatory argument of the script execution. Semigraphical form of QR codes is generated for each line of text read from the file.

The mentioned earlier classified documents database can be prepared using any database system. For the purposes of this article I wanted to show you a very simple example based on a serverless database system available for free – SQLite.

require 'sqlite3'

QR = <<'CODE'
xxxxxxx xx  xx xx x x xx  xxxxxxx
x     x xx xxxx   xx   xx x     x
x xxx x    xxx   x xx xxx x xxx x
x xxx x x xx   x xxxx x   x xxx x
x xxx x xxx x xxxx  x   x x xxx x
x     x xxxx xxxxxxx  x   x     x
xxxxxxx x x x x x x x x x xxxxxxx
            xxxx x   xx x       
   x  x  x     x  xxxx x   xxx xx
   xxx    xxxxx x xxx     xx x  x
 x xx xx    x xxxx  xx   x x xxxx
xxxx x xxxxxx   xxx xx  xx x    x
xxx xxxxx  x xx   x x x   x xx x
xxx x   xx      x  xx x  xx x  xx
xxx x x x xx xxx  xxx  xxx x x  
   xx      x x  x xxxx xxx x x  
     xxx  x x x  x xxxx x x xx xx
x xxxx xxx  xx   xxx x xxx      
 x  x x   x  xx  x x    xx    x x
x   x  xx   x   xxxx xx xxx xx  x
  xxx x x x x x   x  xxxxx x   x
   x      x  xx   xx xxxxx x x  x
xx x xx     x x  xx x   xx x  xxx
 x x x    xx xxx x xxxxxxx x    x
x x x x  x xxxxxx  xxx xxxxxxx  x
        x x  x xxx    x x   x   x
xxxxxxx  xx  x xx x xx  x x xxx 
x     x  xx  x x    x  xx   xx  
x xxx x   xxx   x x x x xxxxxx  x
x xxx x xx x xxxx x  x xx x x xx
x xxx x  x x  x xxx     x   x   x
x     x  xx  xxx x xx  xx  xx   
xxxxxxx       x x  xxx  xxx xxxx
CODE

begin
   db = SQLite3::Database.open "classified.db"
   db.execute "CREATE TABLE IF NOT EXISTS Documents(Id INTEGER PRIMARY KEY,
      Docname TEXT, Hash TEXT, Clause TEXT, QRcode TEXT)"

       db.execute "INSERT INTO Documents VALUES(1, 'file-01',\
                           '3d6d1146dc56af6', 'CONF', '#{QR}')"
rescue SQLite3::Exception => e
   puts "We have the problem"
   puts e  
ensure
   db.close if db
end

Of course, before trying to execute the script, please do not forget to install the library (gem) which implements SQLite3 database management functions, by executing the command line of the operating system shell prompt:

gem install sqlite3

These examples of scripts are only prototypical solutions. To make proper practical use of them, you need – of course – to further develop them.

Informacje Janusz Nawrat
Just ordinary man who likes thinking...

Skomentuj

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Log Out / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Log Out / Zmień )

Facebook photo

Komentujesz korzystając z konta Facebook. Log Out / Zmień )

Google+ photo

Komentujesz korzystając z konta Google+. Log Out / Zmień )

Connecting to %s

TOMASZ WEŁNA

artysta grafik | wykładowca

PRACOWNIA OKO

Szkoła Rysunku Malarstwa i Grafiki DR TOMASZA WEŁNY | KRAKÓW | Plac Matejki 10 | tel 691 81 75 74

Piękno neurobiologii

Blog Jerzego Vetulaniego

Teoria muzyki, zasady muzyki, podstawy muzyki

Teoria muzyki, zasady muzyki, podstawy muzyki - czyli to co każdy amator muzyki wiedzieć powinien :)

Personal Development & Inspirations

Przemyślenia i refleksje, którymi warto się podzielić (blog by Janusz Nawrat)

Business IT Cooperation Platform

Biznes i IT - dwa światy, które muszą współdziałać

%d bloggers like this: