Skip to content

More examples/documentation #20

Description

@skondrashov

I am using this library and I wish to filter by location boxes, but I'm not sure where to start. An example of each type of filter, or some way to connect the dots for users between the APIs and this library would be nice!

extern crate twitter_stream;
extern crate ini;

use twitter_stream::{Token, TwitterStreamBuilder};
use twitter_stream::rt::{self, Future, Stream};

use ini::Ini;

fn main() {
	let conf = Ini::load_from_file("config.ini").expect("Unable to read config.ini");
	let bounding = conf.section(Some("geo_bounding")).expect("No geo_bounding section found in config");

	let bounds = vec![];
	for bound in &["west", "south", "east", "north"] {
		bounds.push(
			bounding
				.get(bound.to_owned()).expect(&format!("Unable to find value for '{}' in config", bound))
				.parse::<f64>()       .expect(&format!("Unable to parse value for '{}' as f64", bound))
		);
	}

	let bounds = ((bounds[0], bounds[1]), (bounds[2], bounds[3]));

	let future = TwitterStreamBuilder::filter(Token::new("consumer_key", "consumer_secret", "access_token", "access_secret",))
		.locations(bounds)
		.listen()
		.unwrap()
		.flatten_stream()
		.for_each(|json| {
			println!("{}", json);
			Ok(())
		})
		.map_err(|e| println!("error: {}", e));

	rt::run(future);
}

This is my best shot, but I get an error that I haven't been able to resolve:

26 |         .locations(bounds)                                                                                        
   |          ^^^^^^^^^ the trait `std::convert::From<((f64, f64), (f64, f64))>` is not implemented for `std::option::Option<&[((f64, f64), (f64, f64))]>`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions