Exemple #1
0
def test_from_dict():
    from_dict = News.from_dict({
        "title": "title",
        "description": "description",
        "url": "url",
        "published": "published",
        "full_text": "full_text",
    })
    assert from_dict.title == "title"
    assert from_dict.description == "description"
    assert from_dict.url == "url"
    assert from_dict.published == "published"
    assert from_dict.full_text == "full_text"
Exemple #2
0
def get_csv_by_date(date, datastore=datastores[0], delimeter=","):
    date = parse_time(date)
    res = datastore.load_by_date(date)
    csv_head = "title{}description{}published{}url{}fulltext".format(
        delimeter, delimeter, delimeter, delimeter)
    csv_list = [csv_head]
    found = False
    for item in res:
        found = True
        csv_string = News.from_dict(item).to_csv(delimeter)
        csv_list.append(csv_string)
    if found:
        with open("{}.csv".format(date.date()), "w") as f:
            f.write("\n".join(csv_list))
    else:
        print("No news at {}".format(date.date()))