Publish HTML quickly. https://html.house
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

46 lines
1.1 KiB

  1. package htmlhouse
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "github.com/ChimeraCoder/anaconda"
  6. )
  7. func tweet(app *app, houseID, title string) {
  8. // Check for blacklisted titles
  9. if title == "HTMLhouse" {
  10. return
  11. }
  12. // Check if this has already been tweeted
  13. var tweetID int64
  14. err := app.db.QueryRow("SELECT tweet_id FROM tweetedhouses WHERE house_id = ?", houseID).Scan(&tweetID)
  15. switch {
  16. case err != nil && err != sql.ErrNoRows:
  17. fmt.Printf("Error selecting from tweetedhouses: %v", err)
  18. return
  19. }
  20. if tweetID != 0 {
  21. return
  22. }
  23. // Post to Twitter
  24. text := fmt.Sprintf("\"%s\" on #HTMLhouse - %s/%s.html #html #web #website", title, app.cfg.HostName, houseID)
  25. anaconda.SetConsumerKey(app.cfg.TwitterConsumerKey)
  26. anaconda.SetConsumerSecret(app.cfg.TwitterConsumerSecret)
  27. api := anaconda.NewTwitterApi(app.cfg.TwitterToken, app.cfg.TwitterTokenSecret)
  28. t, err := api.PostTweet(text, nil)
  29. if err != nil {
  30. fmt.Printf("Error posting tweet: %v", err)
  31. }
  32. // Mark it as "tweeted"
  33. _, err = app.db.Exec("INSERT INTO tweetedhouses (house_id, tweet_id) VALUES (?, ?)", houseID, t.Id)
  34. if err != nil {
  35. fmt.Printf("Error noting house tweet status: %v", err)
  36. return
  37. }
  38. }