<commit_before>package main

import (
	"github.com/OUCC/prism/capture"

	"bytes"
	"encoding/base64"
	"fmt"
	"image/jpeg"
	"io/ioutil"
	"net/http"
	"net/url"
)

const (
	VIDEO_DEVICE = "/dev/video0"
)

func main() {
	img, err := capture.Capture(VIDEO_DEVICE)
	if err != nil {
		fmt.Println(err)
		return
	}

	buf := new(bytes.Buffer)
	err = jpeg.Encode(buf, img, nil)
	if err != nil {
		fmt.Println(err)
	}
	ioutil.WriteFile("test.jpg", buf.Bytes(), 0644)
	return

	s := base64.StdEncoding.EncodeToString(buf.Bytes())
	if err := post(s); err != nil {
		fmt.Println(err)
	}
}

func post(img string) error {
	var values url.Values
	values.Add("image", img)
	values.Add("key", POST_KEY)
	res, err := http.PostForm(POST_URL, values)
	if err != nil {
		return err
	}
	fmt.Printf("Status: %d\n", res.StatusCode)
	// TOOD
	return nil
}<commit_msg>[MOD] post image every 5minutes<commit_after>package main

import (
	"github.com/OUCC/prism/capture"

	"bytes"
	"encoding/base64"
	"fmt"
	"image/jpeg"
	//"io/ioutil"
	"net/http"
	"net/url"
	"time"
)

const (
	VIDEO_DEVICE = "/dev/video0"
)

func main() {
	for {
		img, err := capture.Capture(VIDEO_DEVICE)
		if err != nil {
			fmt.Println("Error: failed to capture: ", err)
			return
		}

		buf := new(bytes.Buffer)
		err = jpeg.Encode(buf, img, nil)
		if err != nil {
			fmt.Println(err)
		}
		//ioutil.WriteFile("test.jpg", buf.Bytes(), 0644) // for debug

		s := base64.StdEncoding.EncodeToString(buf.Bytes())
		if err := post(s); err != nil {
			fmt.Println(err)
		} else {
			fmt.Println(time.Now().Format(time.UnixDate), "StatusOK")
		}

		time.Sleep(5 * time.Minute)
	}
}

func post(img string) error {
	values := url.Values{}
	values.Add("image", img)
	values.Add("key", POST_KEY)
	res, err := http.PostForm(POST_URL, values)
	if err != nil || res.StatusCode != http.StatusOK {
		return err
	}
	return nil
}
{'fraction_non_alphanumeric': 0.17421790722761596, 'fraction_numerical': 0.010787486515641856, 'mean_word_length': 3.51338199513382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5148159', 'n_tokens_mistral': 809, 'n_tokens_neox': 758, 'n_words': 157}