[go: up one dir, main page]

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn1 <hrdina.pavel@gmail.com>2019-07-28 20:44:04 +0200
committern1 <hrdina.pavel@gmail.com>2019-07-28 20:44:04 +0200
commitd7ed49271838121a3e116f460646c1860fdd70c1 (patch)
tree6711bcb416aa0c9f99c2fed7149b3c1fbadfec90
parent2f2c732c35e67a1beb9ed760e95b627ebe8d63b7 (diff)
Fixed: fetch_news() and fetch_top_news() now returns datetime object for date key.0.2.5.1
-rw-r--r--README.rst6
-rw-r--r--karpet/core.py5
-rw-r--r--karpet/meta.py2
-rw-r--r--test_karpet.py11
4 files changed, 17 insertions, 7 deletions
diff --git a/README.rst b/README.rst
index 7646176..6218849 100644
--- a/README.rst
+++ b/README.rst
@@ -132,7 +132,7 @@ Retrieves crypto news.
'url': 'https://cointelegraph.com/ ....', # Truncated.
'title': 'Shell Invests in Blockchain-Based Energy Startup',
'description': 'The world’s fifth top oil and gas firm, Shell, has...', # Truncated.
- 'date': datetime.datetime(2019, 7, 10, 19, 0, 13),
+ 'date': datetime.datetime(2019, 7, 28, 9, 24, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600)))
'image': 'https://images.cointelegraph.com/....jpg' # Truncated.
}
news = k.fetch_news("btc", limit=30) # Gets 30 news.
@@ -156,7 +156,7 @@ Retrieves top crypto news in 2 categories:
{
'url': 'https://cointelegraph.com/...', # Truncated.
'title': 'Bank of China’s New Infographic Shows Why Bitcoin Price Is Going Up',
- 'date': '2019-07-27T10:07:00+01:00',
+ 'date': datetime.datetime(2019, 7, 27, 10, 7, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600))),
'image': 'https://images.cointelegraph.com/images/740_aHR...', # Truncated.
'description': 'The Chinese central bank released on its website an ...' # Truncated.
}
@@ -164,7 +164,7 @@ Retrieves top crypto news in 2 categories:
{
'url': 'https://cointelegraph.com/...', # Truncated.
'title': 'Bitcoin Price Shuns Volatility as Analysts Warn of Potential Drop to $7,000',
- 'date': '2019-07-22T09:21:00+01:00',
+ 'date': datetime.datetime(2019, 7, 27, 10, 7, tzinfo=datetime.timezone(datetime.timedelta(seconds=3600))),
'image': 'https://images.cointelegraph.com/images/740_aHR0c...' # Truncated.
'description': 'Stability around $10,600 for Bitcoin price is ...' # Truncated.
}
diff --git a/karpet/core.py b/karpet/core.py
index ad44c8b..bd724e6 100644
--- a/karpet/core.py
+++ b/karpet/core.py
@@ -11,7 +11,7 @@ import requests
import aiohttp
import re
-from datetime import timedelta
+from datetime import datetime, timedelta
import time
import asyncio
@@ -465,7 +465,8 @@ class Karpet:
# Date.
try:
- news["date"] = dom.find("meta", {"property": "article:published_time"})["content"]
+ d = dom.find("meta", {"property": "article:published_time"})["content"]
+ news["date"] = datetime.strptime(d, "%Y-%m-%dT%H:%M:%S%z")
except:
news["date"] = None
diff --git a/karpet/meta.py b/karpet/meta.py
index fdbef70..baf4f0d 100644
--- a/karpet/meta.py
+++ b/karpet/meta.py
@@ -1,2 +1,2 @@
-__version__ = "0.2.5"
+__version__ = "0.2.5.1"
__description__ = "Library for fetching coin/token metrics data from the internet."
diff --git a/test_karpet.py b/test_karpet.py
index 222337f..91f89ae 100644
--- a/test_karpet.py
+++ b/test_karpet.py
@@ -1,6 +1,6 @@
from karpet import Karpet
-from datetime import date, timedelta
+from datetime import datetime, date, timedelta
def get_last_week():
@@ -53,6 +53,9 @@ def test_fetch_news():
assert "title" in news[0]
assert "date" in news[0]
+ if news[0]["date"] is not None:
+ assert isinstance(news[0]["date"], datetime)
+
def test_fetch_news_with_limit():
@@ -75,6 +78,12 @@ def test_fetch_top_news():
assert "title" in editors_choice[0]
assert "date" in editors_choice[0]
+ if editors_choice[0]["date"] is not None:
+ assert isinstance(editors_choice[0]["date"], datetime)
+
assert "url" in hot_stories[0]
assert "title" in hot_stories[0]
assert "date" in hot_stories[0]
+
+ if hot_stories[0]["date"] is not None:
+ assert isinstance(hot_stories[0]["date"], datetime)