Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

greed dots for your bots #6

Open
V-inz opened this issue Jan 10, 2017 · 2 comments
Open

greed dots for your bots #6

V-inz opened this issue Jan 10, 2017 · 2 comments

Comments

@V-inz
Copy link
Contributor

V-inz commented Jan 10, 2017

greendots.go

// This little program uses qrencode to generate the QR-Code you need,
// to get Threema-Status "green" for your bots.
// You need Package qrencode installed on your system:  # apt-get install qrencode
package main

import (
	"fmt"
	"log"
	"os"
	"os/exec"

	"github.com/o3ma/o3"
)


func main() {
	var (
		pass = []byte{0xA, 0xB, 0xC, 0xD, 0xE}
		idpath  = "threema.id"
		tid     o3.ThreemaID
	)

	// check whether an id file exists
	if _, err := os.Stat(idpath); err != nil {
		fmt.Printf("Identity-file '%s' missing.\n", idpath)
	} else {
		// load existing ID
		tid, err = o3.LoadIDFromFile(idpath, pass)
		if err != nil {
			log.Fatal(err)
		}
	}

	// concat QR-Code content. "3mid" maybe is a shortcut for Threema-ID
	qrcode := fmt.Sprintf("3mid:%s,%x", tid.String(), tid.GetPubKey()[:])
	fmt.Printf(qrcode + "\n")

	// shell-execute command to generate the PNG image "threemaid.png"
	qrcode_command := fmt.Sprintf("qrencode  -l Q -o threemaid.png \"%s\"", qrcode)
	c := exec.Command("sh","-c", qrcode_command)
	if err := c.Run(); err != nil { 
		fmt.Println("Error: ", err)
	}
}
@willnix
Copy link
Contributor

willnix commented Jan 11, 2017

Cool! Something like this was on our todo list for a while. :)
Any specific reason you use "qrencode" instead of a go qrcode package? [1|2]
That's the only thing keeping my from merging it into master right away.
I would not want the code to depend on some external tool to be installed.

[1] https://github.com/skip2/go-qrcode
[2] https://github.com/qpliu/qrencode-go

@V-inz
Copy link
Contributor Author

V-inz commented Jan 11, 2017

serve ;) greendots.go
no reason, just fastest at this moment ...

// This program uses github.com/skip2/go-qrcode to generate the QR-Code you need,
// to get Threema-Status green for your bots.
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/o3ma/o3"

	// https://github.com/skip2/go-qrcode
	// $ go get -u github.com/skip2/go-qrcode/...
	qrcode "github.com/skip2/go-qrcode"
)

func main() {
	var (
		pass = []byte{0xA, 0xB, 0xC, 0xD, 0xE}
		idpath  = "threema.id"
		tid     o3.ThreemaID
	)

	// check whether an id file exists
	if _, err := os.Stat(idpath); err != nil {
		fmt.Printf("Identity-file '%s' missing.\n", idpath)
	} else {
		// load existing ID
		tid, err = o3.LoadIDFromFile(idpath, pass)
		if err != nil {
			log.Fatal(err)
		}
	}

	// concat QR-Code content. "3mid" maybe is a shortcut for Threema-ID
	qrtext := fmt.Sprintf("3mid:%s,%x", tid.String(), tid.GetPubKey()[:])
	fmt.Printf(qrtext + "\n")

	// generate the PNG-Image "threemaid.png"
	err := qrcode.WriteFile(qrtext, qrcode.Medium, 256, "threemaid.png")
	if err != nil { 
		log.Fatal(err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants