article_date_extractor/lib.rs
1/*!
2This crate provides a library for extracting the publication date from
3an article or a blog post. It was heavily influenced by both the original
4[article-date-extractor](https://github.com/Webhose/article-date-extractor)
5written in Python, as well as its [Haskell port](https://github.com/amir/article-date-extractor).
6
7# Usage
8This crate is [on crates.io](https://crates.io/crates/article-date-extractor) and can be
9used by adding `article_date_extractor` to your dependencies in your project's `Cargo.toml`.
10
11```toml
12[dependencies]
13article-date-extractor = "0.1.0"
14```
15
16and this to your crate root:
17
18```rust
19extern crate article_date_extractor;
20```
21
22# Example: extracting a date from a news article
23
24`extract_article_published_date` expects both a link as well as an html body. In the following example the body is provided as part of the library's test fixtures.
25
26```rust
27extern crate article_date_extractor;
28extern crate chrono;
29
30fn main() {
31 use article_date_extractor::extract_date::extract_article_published_date;
32 use chrono::NaiveDate;
33 use std::env;
34
35 let link = "http://edition.cnn.com/2015/11/28/opinions/sutter-cop21-paris-preview-two-degrees/index.html";
36 let body = include_str!("./tests/fixtures/cnn.html");
37
38 assert_eq!(NaiveDate::from_ymd(2015, 11, 28), extract_article_published_date(&link, body).unwrap());
39}
40```
41
42*/
43
44#![recursion_limit = "1024"]
45extern crate regex;
46#[macro_use]
47extern crate lazy_static;
48extern crate chrono;
49extern crate select;
50extern crate serde_json;
51#[macro_use]
52extern crate error_chain;
53pub mod extract_date;
54mod errors;