Home | Legal Tech | Projects | Writings

GDPR Quicksearch

Quickly search the GDPR for keywords.

The GDPR is a pretty new piece of legislation, and merits dipping in and out of. Not only that, but (for better or worse) a lot of the interpretation can be found in the recitals.

The script lets you quickly dip in to the GDPR and pull out all the articles and recitals containing a search term of your choice. Finally, it prompts you to generate a report which will be saved and opened for printing / reference.

Tasklist

  1. Write a python script to search the GDPR
  2. Run the script and enter the search term
  3. Generate a report for printing / saving if desired

1. Write the script

This step is as simple as pasting the code below into a new python file.

Make a new file called gdprsearch.py. In the terminal you can quickly create it with:

$ touch gdprsearch.py

Once the file is open in your text editor, enter the following program:

import requests
import json
import webbrowser

gdpr_text = requests.get("http://enceladus.world/gdpr_json")

j = gdpr_text.json()

while True:
    search_term = input("Search or q to quit")

    if type(search_term) == str:
        try:
            if search_term.upper() == "Q":
                quit()
        except TypeError as e:
            print("Type error - enter a valid string")

        result_string = ""
        for line in j:
            if search_term.upper() in line['text'].upper():
                if line['section'] != "Recitals":
                    print("Chapter {} {} {} {} ({}) {}".format(line['chapter'], line['section'], line['subtitle'], line['article'], line['num'], line['text']))
                    result_string += "Chapter {} {} {} {} ({}) {}".format(line['chapter'], line['section'], line['subtitle'], line['article'], line['num'], line['text'])
                else:
                print("Recital {}".format(line['text']))
		result_string += "Recital {}".format(line['text'])
        open_choice = input("Save report? (y/n)")
        if open_choice.upper() == "Y":
            report_name = search_term + ".txt"
            with open(report_name, "w") as search_file:
                search_file.write("Search term = {}".format(search_term))
                search_file.write(result_string)
            webbrowser.open(report_name)

    else:
        break

2. Run the script and enter search term

We've got our script, and now it is time to run it.

Open your terminal, and go to the directory you saved gdprsearch.py in (your text reports will also be saved here). Use the "cd" command to change directories, for example, if I saved this in a folder named "gdprfolder" in my home directory, I could access it from anywhere with:

$ cd ~/gdprfolder

Check the script is indeed in your current director by entering ls -l and ensuring the filename is listed there.

Now run the script by entering the following:

$ python3 gdprsearch.py

If you entered the script correctly, you should see it prompt you for a search term (or enter 'q' to quit). Enter your search term, and hit return.

You should see the results printed out in your terminal, followed by another prompt.

3. Generate report

It's not always useful to have the text in a terminal, so let's generate a file with the results of the search.

In the prompt, enter 'y' to generate a report (anything else skips the step and goes back to the start of the program).

A report should open up automatically in your default application (usually a text editor or browser).

Save this or print it in the usual way!

Once you've closed the file, the program will start again.