Article API Service¶
When enabled along with all other Factiva Analytics APIs, this service allows to retrieve content for display purposes when end users need to read the underlying content from a calculated score or derived datapoint after processing Snapshots or Streams news articles.
ArticleFetcher¶
- class factiva.analytics.article_fetcher.article_fetcher.ArticleFetcher(oauth_user: OAuthUser = None)¶
Allows to fetch articles against the Article API Service using the provided OAuthUser credentials.
- Parameters:
oauth_user (OAuthUser) – An instance of an OAuthUser with working credentials. If not provided the user instance is created automatically from ENV variables.
Examples
Create an ArticleFetcher instance.
from factiva.analytics import ArticleFetcher ar = ArticleFetcher() ar
<class 'factiva.analytics.article_fetcher.article_fetcher.ArticleFetcher'> |-oauth_user: <class 'factiva.analytics.auth.oauthuser.OAuthUser'> | |-client_id = fbwqyORz0te484RQTt0E7qj6Tooj4Cs6 | |-token_status = OK | |-...
- fetch_single_article(an: str) UIArticle¶
Method that gets a single article’s content to be displayed in a user interface.
- Parameters:
an (str) – String containing the 32-character long article ID (AN). e.g. WSJO000020221229eict000jh
- Returns:
Python dict containing full articles’ data. This will be replaced when the
UIArticleclass is implemented.- Return type:
dict
Examples
Creating a new
Articlefetcherinstance which reads credential values from environment variables and returns a single article objectUIArticle:from factiva.analytics import ArticleFetcher ar = ArticleFetcher() article = ar.fetch_single_article(an='WSJO000020221229eict000jh') print(article.txt)
output
<class 'factiva.analytics.article_fetcher.article_fetcher.UIArticle'> |-an: WSJO000020221229eict000jh |-headline: Europe Taps Tech's Power-Hungry Data Centers to Heat Homes. |-source_code: WSJO |-source_name: The Wall Street Journal Online |-publication_date: 2022-12-29 |-metadata: <dict> - [4] keys |-content: <dict> - [19] keys |-included: <list> - [0] items |-relationships: <dict> - [0] keys
- Raises:
PermissionError – If the user doesn’t have access to the requested content
- oauth_user = None¶
User instance wich provides the credentials to connect to the Article API endpoint.
UIArticle¶
- class factiva.analytics.article_fetcher.article_fetcher.UIArticle(article_dict: dict)¶
Class that represents a single article for visualization purposes. Methods and attributes are tailored for front-end environments.
- Parameters:
article_dict (dict) – A python dict with the structure returned by the Dow Jones Article API service.
Examples
See ArticleFetcher class examples.
- an = None¶
Article unique identifier, also known as Accession Number
- content = {}¶
Article’s content dict. Full text with annotations and other UI elements.
- headline = None¶
Article’s headline, also known as title
- included = []¶
References to objects linked to a specific article
- metadata = {}¶
Article’s metadata dict. Contains Dow Jones Intelligent Identifiers among other codes.
- publication_date = None¶
Article’s publication date in ISO format as provided by the source. e.g. ‘2022-12-03’
- relationships = {}¶
References to related objects
- source_code = None¶
Article content creator’s code. e.g. WSJO
- source_name = None¶
Article content creator’s name. e.g. The Wall Street Journal Online