Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from cristeahub/travis
Browse files Browse the repository at this point in the history
Travis
  • Loading branch information
cristeahub committed Oct 6, 2015
2 parents 4629eab + 0fd436f commit fc7beed
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ fn show_week_period_for_week_number(w: usize, year: i32) {
);
}

fn get_week_number() -> isize {
let client = Client::new();

let mut res = client
.get(WEEKDAY_WEBSITE)
.header(Connection::close())
.send()
.unwrap_or_else(|why| {
panic!("Error fetching week number, make sure you have an internet connection");
});

let mut body = String::new();
res.read_to_string(&mut body).unwrap();

let body_index = body.find("<body>\n").unwrap() + "<body>\n".len();
let break_index = body.find("<br />").unwrap();
let week_number = &body[body_index..break_index];

return match week_number.parse::<isize>() {
Ok(num) => num,
_ => -1,
};
}

fn main() {
let year = Local::now().year();

Expand All @@ -69,23 +93,15 @@ fn main() {

print_help();
} else {
let client = Client::new();

let mut res = client
.get(WEEKDAY_WEBSITE)
.header(Connection::close())
.send()
.unwrap_or_else(|why| {
panic!("Error fetching week number, make sure you have an internet connection");
});

let mut body = String::new();
res.read_to_string(&mut body).unwrap();

let body_index = body.find("<body>\n").unwrap() + "<body>\n".len();
let break_index = body.find("<br />").unwrap();
println!("{}", get_week_number());
}
}

let week_number = &body[body_index..break_index];
println!("{}", week_number);
#[test]
fn week_number_should_be_between_1_and_53() {
if let 1...53 = get_week_number() {
assert!(true, "Week number is between 1 and 53");
} else {
assert!(false, "Week number is not between 1 and 53");
}
}

0 comments on commit fc7beed

Please sign in to comment.