Ejemplo n.º 1
0
func hello(res http.ResponseWriter, req *http.Request) {
	conn := db.NewConnection()
	rows, err := conn.Query(`
		SELECT notice_id, agency
		FROM notice LEFT JOIN notice_agency ON (notice.id = notice_id)
		ORDER BY published, notice_id, agency`)
	if err != nil {
		log.Panic(err)
	}
	lastNotice := ""
	for rows.Next() {
		var docNum string
		var agency sql.NullString
		if err := rows.Scan(&docNum, &agency); err != nil {
			log.Panic(err)
		}
		if docNum != lastNotice {
			fmt.Fprintf(res, "%s\n", docNum)
			lastNotice = docNum
		}
		if agency.Valid {
			fmt.Fprintf(res, "\t%s\n", agency.String)
		}
	}
}
Ejemplo n.º 2
0
func Process() {
	conn := db.NewConnection()
	var nextDoc sql.NullString
	row := conn.QueryRow(`
		SELECT notice.id
		FROM notice LEFT JOIN stats ON (notice.id = stats.id)
		WHERE stats.id IS NULL
		LIMIT 1`)
	if err := row.Scan(&nextDoc); err != nil {
		log.Panic(err)
	}

	if nextDoc.Valid {
		notice := fetch(nextDoc.String)
		xml := fetchXML(&notice)
		sql := conn.Rebind(`
			INSERT INTO stats
			(id, xml_len, regtext_len, page_len, is_correction)
			VALUES (?, ?, ?, ?, ?)`)
		conn.MustExec(
			sql,
			nextDoc.String, len(xml), regtextLen(xml),
			notice.PageLength, notice.CorrectionOf != "")

	}
}
Ejemplo n.º 3
0
func SyncNew() {
	conn := db.NewConnection()
	var maxPublished sql.NullString
	row := conn.QueryRow("SELECT max(published) from notice")
	if err := row.Scan(&maxPublished); err != nil {
		log.Panic(err)
	}

	insertNotices(conn, fetch(sql.NullString{"", false}, maxPublished))
}
Ejemplo n.º 4
0
func Backfill() {
	conn := db.NewConnection()
	var minPublished sql.NullString
	row := conn.QueryRow("SELECT min(published) from notice")
	if err := row.Scan(&minPublished); err != nil {
		log.Panic(err)
	}

	insertNotices(conn, fetch(minPublished, sql.NullString{"", false}))
}