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