Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"database/sql"
"os"
"strconv"
"strings"
_ "github.com/go-sql-driver/mysql"
strip "github.com/grokify/html-strip-tags-go"
)
var tag struct {
ID int
postTitle string
postContent string
}
var fileName = "file.bib"
func main() {
// db, err := sql.Open("mysql", "user:pass@tcp(domain.com:3306)/database")
db, err := sql.Open("mysql", "user:pass@/database")
checkError(err)
defer db.Close()
err = db.Ping()
checkError(err)
results, err := db.Query("SELECT ID, post_title, post_content FROM cea_posts WHERE post_type='post' AND post_status='draft'")
checkError(err)
if _, err := os.Stat(fileName); os.IsNotExist(err) {
_, err := os.Create(fileName)
checkError(err)
}
for results.Next() {
err = results.Scan(&tag.ID, &tag.postTitle, &tag.postContent)
checkError(err)
postContent := strip.StripTags(tag.postContent)
postContent = strings.TrimSpace(postContent)
f, err := os.OpenFile(fileName, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
checkError(err)
_, err = f.WriteString("@misc{\ntitle = {" + tag.postTitle + "}, url = {http://domain.com/wp-admin/post.php?action=edit&post=" + strconv.Itoa(tag.ID) + "},\nannote = {"+ postContent +"}\n}\n")
checkError(err)
}
}
func checkError(err error) {
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.