]> git.ipfire.org Git - location/libloc.git/blame - examples/python/create-database.py
python example script: Add country name and continent code.
[location/libloc.git] / examples / python / create-database.py
CommitLineData
e51e1dec
MT
1#!/usr/bin/python3
2
61b2d4e5 3import _location as location
726f9984 4import os
f852b157 5import sys
e51e1dec 6
726f9984 7ABS_SRCDIR = os.environ.get("ABS_SRCDIR", ".")
e51e1dec 8
726f9984 9private_key_path = os.path.join(ABS_SRCDIR, "examples/private-key.pem")
e51e1dec 10
726f9984
MT
11with open(private_key_path, "r") as pkey:
12 w = location.Writer(pkey)
e51e1dec 13
726f9984
MT
14 # Set the vendor
15 w.vendor = "IPFire Project"
bc1bcc15 16
726f9984
MT
17 # Set a description
18 w.description = "This is a geo location database"
e51e1dec 19
726f9984
MT
20 # Set a license
21 w.license = "CC"
e51e1dec 22
33a92f6a
SS
23 # Add a country
24 c = w.add_country("DE")
b186d83f
SS
25 c.continent_code = "EU"
26 c.name = "Germany"
33a92f6a 27
726f9984
MT
28 # Add an AS
29 a = w.add_as(204867)
30 a.name = "Lightning Wire Labs GmbH"
e51e1dec 31
726f9984 32 print(a)
e51e1dec 33
726f9984
MT
34 # Add a network
35 n = w.add_network("2a07:1c44:5800::/40")
36 n.country_code = "DE"
37 n.asn = a.number
dc5a0417 38 n.set_flag(location.NETWORK_FLAG_ANYCAST)
726f9984
MT
39
40 print(n)
41
42 # Write the database to disk
43 for f in sys.argv[1:]:
44 w.write(f)