You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB
Go

package main
import (
"fmt"
"net/http"
"os"
"git.nroo.de/norwin/mobilizon-event-importer/mobilizon"
"git.nroo.de/norwin/mobilizon-event-importer/scrapers/facebook.com"
)
const usage = "usage:\nMOBI_INSTANCE= MOBI_EMAIL= MOBI_PASS= %s <facebook event id/url>\n"
func main() {
instance, _ := os.LookupEnv("MOBI_INSTANCE")
email, _ := os.LookupEnv("MOBI_EMAIL")
pass, _ := os.LookupEnv("MOBI_PASS")
if len(os.Args) < 2 || instance == "" || email == "" || pass == "" {
fmt.Printf(usage, os.Args[0])
return
}
fbEvent := os.Args[1]
var err error
var event *mobilizon.Event
fmt.Println("scraping fb event")
scraper := facebook.NewJsonLdScraper()
event, err = scraper.ScrapeEvent(fbEvent)
if err != nil {
fmt.Println("ScrapeEvent err:", err)
return
}
fmt.Println("creating mobi client")
c := mobilizon.NewMobilizonClient(instance)
fmt.Println("authorizing mobi user")
var user *mobilizon.User
if user, err = c.Authorize(email, pass); err != nil {
fmt.Println("Authorize err:", err)
return
}
url := string(event.Picture.URL)
fmt.Println("fetching event picture")
pic, err := http.Get(url)
if err != nil {
fmt.Println("Get pic err:", err)
return
}
defer pic.Body.Close()
event.Picture.Name = event.Picture.URL
fmt.Println("creating mobi event")
event, err = c.CreateEventWithImage(event.AsInput(), user.DefaultActor.Actor, pic.Body)
if err != nil {
fmt.Println("CreateEvent err:", err)
return
}
fmt.Println(event)
}