Generating bilingual EUR-LEX web addresses in Python

Following on from the Python courses that I recently completed, I wrote a little bit of code that generates the URLs for finding bilingual versions of EU Directives and Regulations in Eur-Lex. This can be useful for allowing a translator to access to a bilingual version for then aligning the output in Trados using Bilingual Excel.

How does it work?

It asks you to specify the language versions you with to use, and you specify one language to appear on the left-hand side, and one on the right-hand side. This can be useful for the order of the columns for alignment using the Bilingual Excel filetype in Trados.

You are asked to specific the year number and the item number (e.g. CRR which is Regulation (EU) 575/2013 (note the old order) or the IFD: Directive (EU) 2019/2034), and whether you are dealing with a Directive or Regulation. Future iterations will handle Decisions etc. The itemtype ensures the correct “filler” letter in the URL.

In case the item number (e.g. 575 or 36) is not four digits in length, item.zfill(4) pads it to four digits (i.e. 0575 or 0036).

If you want the original version as it first appeared in the Official Journal then you select Original (O). Consolidated versions are chosen using (C). In the latter case you are asked for the date of the consolidated version (note this date is when in enters into force, not the data of the OJ publication). This also needs either a 3 (for legislation) or 0 (consolidated legislation) to be entered into the URL.

The Code:

#filename bits
urlstart = "https://eur-lex.europa.eu/legal-content/"
urlcelex = "/TXT/?uri=CELEX:"
exportfiletype = ".txt"
sep = "-"

# input language, year number, item number and whether Directive or Regulation
sourcelang = input("Enter left language (EN = English, DE = German):")
targetlang = input("Enter right language (EN = English, DE = German):")
year = input("Enter year:")
fileyear = year + "_"
item = input("Enter item:")
paditem = item.zfill(4)
fileitem = paditem
rlvo = input("Enter type (D for Directive, R for Regulation):")

if rlvo == "D":
     itemtype = "L"
     
elif rlvo == "R":
     itemtype = "R"

# consolidated
consolidated = input("Consolidated version (C) or Original version (O):")

if consolidated == "O":
    legislation = 3
    unconsurl = urlstart + sourcelang + sep + targetlang + urlcelex + str(legislation) + str(year) + itemtype + str(paditem)
    print(unconsurl)

elif consolidated == "C":
    legislation = 0
    consolyear = input("Enter year of consolidated version as YYYY:")
    consolmonth = input("Enter month of consolidated version:")
    padconsolmonth = consolmonth.zfill(2)
    consolday = input("Enter day of consolidated version:")
    padconsolday = consolday.zfill(2)
    consurl = urlstart + sourcelang + sep + targetlang + urlcelex + str(legislation) + str(year) + itemtype + str(paditem) + sep + consolyear + padconsolmonth + padconsolday
    print(consurl)
Visited 31 times, 1 visit(s) today