Last active
May 28, 2020 08:43
-
-
Save boutros/25827d96e5ccf806225981a57bc80f9e to your computer and use it in GitHub Desktop.
ldif navn og epost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"github.com/go-ldap/ldif" | |
) | |
const q = ` | |
SPARQL | |
PREFIX : <https://persons.deichman.no/ontology/> | |
WITH <https://persons.deichman.no> | |
DELETE { ?p :name ?name } | |
INSERT { | |
?p :name "%s" ; | |
:email "%s" . | |
} | |
WHERE { | |
?p :username "deb%s" | |
OPTIONAL { ?p :name ?name } | |
} | |
;` | |
func main() { | |
b, err := ioutil.ReadFile("fullExport.ldif") | |
if err != nil { | |
log.Fatal(err) | |
} | |
data, err := ldif.Parse(string(b)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, e := range data.AllEntries() { | |
surname := e.GetAttributeValue("sn") | |
givenName := e.GetAttributeValue("givenName") | |
name := fmt.Sprintf("%s %s", givenName, surname) | |
debid := e.GetAttributeValue("uid") | |
email := e.GetAttributeValue("mail") | |
if name != "" && debid != "" { | |
fmt.Printf(q, name, email, debid) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment