<commit_before>package main

import (
	"encoding/json"
	"log"
	"os/exec"
	"sort"
	"time"

	"launchpad.net/goamz/aws"
	"launchpad.net/goamz/s3"
)

var bucket *s3.Bucket

func init() {
	auth, err := aws.EnvAuth()
	if err != nil {
		log.Panicln("couldn't get AWS auth credentials: " + err.Error())
	}

	region := aws.USEast

	conn := s3.New(auth, region)
	bucket = conn.Bucket("bitjester.co")
}

func main() {
	filename := time.Now().Format("diacam/2006-01-02T15:04:05-0700.jpg")
	capture := exec.Command("raspistill", "-o", "-")

	image, err := capture.Output()
	if err != nil {
		log.Panicln("couldn't capture an image: " + err.Error())
	}

	err = upload(filename, image)
	if err != nil {
		log.Panicln("couldn't upload image to S3: " + err.Error())
	}

	log.Printf("uploaded %s\n", filename)

	writeManifest()
}

func upload(filename string, contents []byte) (err error) {
	err = bucket.Put(filename, contents, "image/jpeg", s3.PublicRead)
	return
}

func writeManifest() (err error) {
	resp, err := bucket.List("diacam/2014", "", "diacam/2014", 1000)
	if err != nil {
		return
	}

	keys := make([]string, 0)
	for _, key := range resp.Contents {
		keys = append(keys, key.Key)
	}
	sort.Sort(sort.Reverse(sort.StringSlice(keys)))

	log.Println(keys)

	json, err := json.Marshal(keys)
	if err != nil {
		return
	}

	bucket.Put("diacam/MANIFEST.json", json, "application/json", s3.PublicRead)

	return
}<commit_msg>Take command-line args that allow customization (and one-off test shots).<commit_after>package main

import (
	"encoding/json"
	"flag"
	"log"
	"os/exec"
	"sort"
	"time"

	"launchpad.net/goamz/aws"
	"launchpad.net/goamz/s3"
)

var bucket *s3.Bucket

var bucketName = flag.String("bucket", "bitjester.co", "the name of the bucket to upload into")
var prefix = flag.String("prefix", "diacam/", "a string with which to prefix names of uploads")
var updateManifest = flag.Bool("update-manifest", false, "add uploaded file as an entry in ${prefix}MANIFEST.json")

func init() {
	auth, err := aws.EnvAuth()
	if err != nil {
		log.Panicln("couldn't get AWS auth credentials: " + err.Error())
	}

	region := aws.USEast

	conn := s3.New(auth, region)
	bucket = conn.Bucket(*bucketName)
}

func main() {
	flag.Parse()
	
	filename := time.Now().Format(*prefix + "2006-01-02T15:04:05-0700.jpg")
	capture := exec.Command("raspistill", "-o", "-")

	image, err := capture.Output()
	if err != nil {
		log.Panicln("couldn't capture an image: " + err.Error())
	}

	err = upload(filename, image)
	if err != nil {
		log.Panicln("couldn't upload image to S3: " + err.Error())
	}

	log.Printf("uploaded %s\n", filename)

	if *updateManifest {
		writeManifest()
	}
}

func upload(filename string, contents []byte) (err error) {
	err = bucket.Put(filename, contents, "image/jpeg", s3.PublicRead)
	return
}

func writeManifest() (err error) {
	resp, err := bucket.List(*prefix + "201", "", *prefix + "201", 1000)
	if err != nil {
		return
	}

	keys := make([]string, 0)
	for _, key := range resp.Contents {
		keys = append(keys, key.Key)
	}
	sort.Sort(sort.Reverse(sort.StringSlice(keys)))

	log.Println(keys)

	json, err := json.Marshal(keys)
	if err != nil {
		return
	}

	bucket.Put(*prefix + "MANIFEST.json", json, "application/json", s3.PublicRead)

	return
}
{'fraction_non_alphanumeric': 0.1753846153846154, 'fraction_numerical': 0.022153846153846152, 'mean_word_length': 4.001538461538462, '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': '2420821', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1220, 'n_words': 290}