Esempio n. 1
0
func main() {
	configFile := flag.String("config-file", "", "Config file for RETS connection")
	metadataFile := flag.String("metadata-options", "", "Config file for metadata options")
	output := flag.String("output", "", "Directory for file output")

	config := common.Config{}
	config.SetFlags()

	metadataOpts := MetadataOptions{}
	metadataOpts.SetFlags()

	flag.Parse()

	if *configFile != "" {
		err := config.LoadFrom(*configFile)
		if err != nil {
			panic(err)
		}
	}
	fmt.Printf("Connection Settings: %v\n", config)
	if *metadataFile != "" {
		err := metadataOpts.LoadFrom(*metadataFile)
		if err != nil {
			panic(err)
		}
	}
	fmt.Printf("Search Options: %v\n", metadataOpts)

	// should we throw an err here too?
	session, err := config.Initialize()
	if err != nil {
		panic(err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
	defer cancel()

	capability, err := rets.Login(session, ctx, rets.LoginRequest{URL: config.URL})
	if err != nil {
		panic(err)
	}
	defer rets.Logout(session, ctx, rets.LogoutRequest{URL: capability.Logout})

	reader, err := rets.MetadataStream(session, ctx, rets.MetadataRequest{
		URL:    capability.GetMetadata,
		Format: metadataOpts.Format,
		MType:  metadataOpts.MType,
		ID:     metadataOpts.ID,
	})
	defer reader.Close()
	if err != nil {
		panic(err)
	}
	out := os.Stdout
	if *output != "" {
		out, _ = os.Create(*output + "/metadata.xml")
		defer out.Close()
	}
	io.Copy(out, reader)
}
Esempio n. 2
0
func main() {
	configFile := flag.String("config-file", "", "Config file for RETS connection")
	searchFile := flag.String("search-options", "", "Config file for search options")
	output := flag.String("output", "", "Directory for file output")

	config := common.Config{}
	config.SetFlags()

	searchOpts := SearchOptions{}
	searchOpts.SetFlags()

	flag.Parse()

	if *configFile != "" {
		err := config.LoadFrom(*configFile)
		if err != nil {
			panic(err)
		}
	}
	fmt.Printf("Connection Settings: %v\n", config)
	if *searchFile != "" {
		err := searchOpts.LoadFrom(*searchFile)
		if err != nil {
			panic(err)
		}
	}
	fmt.Printf("Search Options: %v\n", searchOpts)

	// should we throw an err here too?
	session, err := config.Initialize()
	if err != nil {
		panic(err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
	defer cancel()

	urls, err := rets.Login(session, ctx, rets.LoginRequest{URL: config.URL})
	if err != nil {
		panic(err)
	}
	defer rets.Logout(session, ctx, rets.LogoutRequest{URL: urls.Logout})

	if urls.GetPayloadList != "" {
		fmt.Println("Payloads: ", urls.GetPayloadList)
		payloads, err := rets.GetPayloadList(session, ctx, rets.PayloadListRequest{
			URL: urls.GetPayloadList,
			ID:  fmt.Sprintf("%s:%s", searchOpts.Resource, searchOpts.Class),
		})
		if err != nil {
			panic(err)
		}
		err = payloads.ForEach(func(payload rets.CompactData, err error) error {
			fmt.Printf("%v\n", payload)
			return err
		})
		if err != nil {
			panic(err)
		}
	}

	fmt.Println("Search: ", urls.Search)
	req := rets.SearchRequest{
		URL: urls.Search,
		SearchParams: rets.SearchParams{
			Select:     searchOpts.Select,
			Query:      searchOpts.Query,
			SearchType: searchOpts.Resource,
			Class:      searchOpts.Class,
			Format:     searchOpts.Format,
			QueryType:  searchOpts.QueryType,
			Count:      searchOpts.CountType,
			Limit:      searchOpts.Limit,
		},
	}
	if strings.HasPrefix(req.SearchParams.Format, "COMPACT") {
		processCompact(session, ctx, req, output)
	} else {
		processXML(session, ctx, req, searchOpts.ElementName, output)
	}
}
Esempio n. 3
0
func main() {
	optionsFile := flag.String("object-options", "", "Get object")
	configFile := flag.String("config-file", "", "Config file for RETS connection")
	output := flag.String("output", "", "Directory for file output")

	config := common.Config{}
	config.SetFlags()

	getOptions := GetObjectOptions{}
	getOptions.SetFlags()

	flag.Parse()

	if *configFile != "" {
		err := config.LoadFrom(*configFile)
		if err != nil {
			panic(err)
		}
	}
	fmt.Printf("Connection Settings: %v\n", config)
	if *optionsFile != "" {
		err := getOptions.LoadFrom(*optionsFile)
		if err != nil {
			panic(err)
		}
	}
	fmt.Printf("GetObject Options: %v\n", getOptions)

	// should we throw an err here too?
	session, err := config.Initialize()
	if err != nil {
		panic(err)
	}
	// setup timeout control
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
	defer cancel()
	// login
	capability, err := rets.Login(session, ctx, rets.LoginRequest{URL: config.URL})
	if err != nil {
		panic(err)
	}
	// make sure we close the rets connection
	defer rets.Logout(session, ctx, rets.LogoutRequest{URL: capability.Logout})
	// feedback
	fmt.Println("GetObject: ", capability.GetObject)
	// warning, this does _all_ of the photos
	response, err := rets.GetObjects(session, ctx, rets.GetObjectRequest{
		URL: capability.GetObject,
		GetObjectParams: rets.GetObjectParams{
			Resource: getOptions.Resource,
			Type:     getOptions.Type,
			ID:       getOptions.ID,
		},
	})
	if err != nil {
		panic(err)
	}
	defer response.Close()
	err = response.ForEach(func(o *rets.Object, err error) error {
		fmt.Println("PHOTO-META: ", o.ContentType, o.ContentID, o.ObjectID, len(o.Blob))
		// if we arent saving, then we quit
		if *output == "" {
			return nil
		}
		path := fmt.Sprintf("%s/%s", *output, o.ContentID)
		os.MkdirAll(path, os.ModePerm)
		f, err := os.Create(fmt.Sprintf("%s/%d", path, o.ObjectID))
		if err != nil {
			return err
		}
		defer f.Close()
		_, err = f.Write(o.Blob)
		return err
	})
	if err != nil {
		panic(err)
	}
}