Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More examples/documentation #20

Open
skondrashov opened this issue Mar 23, 2019 · 1 comment
Open

More examples/documentation #20

skondrashov opened this issue Mar 23, 2019 · 1 comment

Comments

@skondrashov
Copy link

skondrashov commented Mar 23, 2019

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))]>`
@skondrashov
Copy link
Author

skondrashov commented Mar 23, 2019

Figured it out, just needed to change:
let bounds = ((bounds[0], bounds[1]), (bounds[2], bounds[3]));
to
let bounds = &[((bounds[0], bounds[1]), (bounds[2], bounds[3]))][..];

Maybe consider adding something like this code to the readme, so people don't get hung up on the type that locations takes like I did?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant