TimeChainZ – Book Publishing Download Authentication

Professor Robert Goodman is a prominent child psychiatrist who is the lead author of a highly regarded book on the subject, Child and Adolescent Psychiatry. With the permission of the publisher, Wiley-Blackwell, a free PDF download was made available to the public at: http://youthinmind.info/py/yiminfo/GoodmanScott3.py

In the original application, there was a counter to record the number of downloads, which involved downloading the book programmatically. Unfortunately, in early 2019, it was reported that the Microsoft Edge browser did not work with this download. This browser did work with the traditional <a href tag and PDF file. There was a desire, however, to maintain a count of downloads. ChainZy provided a very simple way of replacing the more complicated and less reliable approach.

The Replaced Download Application

The public page for downloading the book, http://youthinmind.info/py/yiminfo/GoodmanScott3.py, used an HTML <a href tag to call a download and count program:

<a href="downloadbook.py"><big>Download in English</big></a>

The downloadbook.py program retrieved the PDF file, stamped the download into a database table and output the file contents to the calling browser:

from y14routines import *
#surprisingly sensitive ... do it this way to avoid embedding any chars between the Content-* instructions
x='''Content-Disposition: attachment; filename="GoodmanScott2012.pdf"'''
y='''Content-Type: application/pdf''' print '''%s%s\r\n'''%(x,y)
sql='''insert into youthinmind.goodmanscottdownloads values(%s,now())''' dbx.execute(sql,(country,));
t=f.read(); f.close(); print t

Unfortunately, this program no longer worked with Edge browser. Simple experimentation showed that Edge did work reliably with <a href=../../yiminfo/GoodmanScott3rdEdition2012.pdf>. This approach did not, however, allow download counting.

A Simpler ChainZy Solution

In the ChainZy solution, the public page (http://youthinmind.info/py/yiminfo/GoodmanScott3.py) for downloading the book uses the proven <a href approach above, combined with a JavaScript fetch (call) to ChainZy for stamping of the event:

<a href="../../yiminfo/GoodmanScott3rdEdition2012.pdf" target=_blank onclick="fetch('http://chainzy.hyperneph.com/?u=UserID&d=GoodmanScott');" > <big>Download in English</big></a>

The downloadbook.py program is no longer needed and has been archived. The UserID of course is private to the ChainZy application. To count the number of stamped downloads (n=14 at the time), it is as simple as using ChainZy receiver output with grep:

tail -n500000 2018-11-28T08\:12\:41.599383.cz | grep GoodmanScott | wc -l 14


In this example, a line of JavaScript, added to a conventional <a href tag, replaces 8 lines of Python program and a database table. The ChainZy approach is applicable for average website developers, whereas the previous approach required a programmer and permission to access the database management system (DBMS). In this case, book downloads are only for the author’s interest. In a case in which downloads might involve charges or potential contention, ChainZy offers forensic strength accounting with data verifiable by multiple, disinterested parties implemented with a single line of JavaScript code.