API reference¶
Format a date according to Reuters style. |
|
|
Format the day of the week according to Reuters style. |
|
Format a time according to Reuters style. |
Check whether a full slug is valid. |
|
Check whether a packaging slug is valid. |
|
Check whether a wild slug is valid. |
|
|
Metadata about a Refinitiv Instrument Code. |
|
A full Reuters slug. |
Format dates, times and slugs in Reuters editorial style.
- reuters_style.date(dt)¶
Format a date according to Reuters style.
Style guide entry:
In text, use the sequence month/day/year, e.g., “Iraq’s invasion of Kuwait on Aug. 2, 1990, led to…” or “the Aug. 2 invasion” or “the August 1990 invasion.”
If a specific date is used, put the year inside commas. Spell out months in text, but abbreviate them followed by a full stop when they are used with a specific date – Jan.1.
When spelling out duration, write, “The tournament runs from May 22 to 24,” not “…runs from May 22-24.” Write “arrived on Monday,” not “arrived Monday” and “on Tuesday,” rather than “yesterday,” “today,” “tomorrow.” Write “the 1939-45 war” but “from 1939 to 1945,” not “from 1939-45.” Write 9/11, not 9-11. In commodities stories, write “Brazil’s 2013/14 soybean crop” (conventional use), not “2013-14.”
Abbreviate as follows, noting the dot after the abbreviation: Jan., Feb., March, April, May, June, July, Aug., Sept., Oct., Nov., Dec.
- Parameters:
dt (datetime) – The datetime to format. (datetime)
- Returns:
The formatted date. (str)
- Return type:
Examples
>>> import reuters_style >>> reuters_style.date(datetime(2021, 9, 1)) 'Sept. 1, 2021' >>> reuters_style.date(datetime(2021, 3, 1)) 'March 1, 2021'
- reuters_style.dayofweek(dt, tabular=False)¶
Format the day of the week according to Reuters style.
Style guide entry:
Always precede the day of the week with the word “on” as in she said on Monday, not she said Monday. Do not abbreviate the days of the week, except in a tabular format: Sun, Mon, Tue, Wed, Thu, Fri, Sat (three letters, without periods).
- Parameters:
- Returns:
The formatted day of the week. (str)
- Return type:
Examples
>>> import reuters_style >>> reuters_style.dayofweek(datetime(2021, 9, 1)) 'Wednesday' >>> reuters_style.dayofweek(datetime(2021, 9, 1), tabular=True) 'Wed'
- reuters_style.time(dt, include_timezone=True)¶
Format a time according to Reuters style.
Style guide entry:
Abbreviations of time zones are acceptable providing the GMT equivalent is given. BST (British Summer Time) = GMT +1 CET (Central European Time) = GMT +1 CDT (Central Daylight Time) = GMT -5 CST (Central Standard Time) = GMT -6 EST (Eastern Standard Time) = GMT -5 MDT (Mountain Daylight Time) = GMT -6 MST (Mountain Standard Time) = GMT -7 PST (Pacific Standard Time) = GMT -8.and
When referring to times, first give the local time by the 12-hour clock (without using the words local time) and follow it with a bracketed conversion to a 24-hour clock time for a specified time zone, e.g., “will meet at 10 a.m. (1600 GMT).”
Use figures except for noon and midnight. Use a colon to separate hours and minutes, e.g., 3:15 p.m. Use the style “on Friday,” “on Saturday,” rather than the looser “today,” “yesterday,” “tomorrow.”
Do not use phrases like “several months ago” or “recently,” which suggest we do not know when something happened or are too lazy to find out. Be precise – “last August” or “on Feb. 2.”
- Parameters:
- Returns:
The formatted time. (str)
- Return type:
Examples
>>> import reuters_style >>> from datetime import datetime >>> reuters_style.time(datetime(2021, 9, 1, 12, 0)) 'noon GMT' >>> reuters_style.time(datetime(2021, 9, 1, 12, 0), include_timezone=False) 'noon' >>> reuters_style.time(datetime(2021, 9, 1, 12, 30)) '12:30 p.m. GMT' >>> reuters_style.time(datetime(2021, 9, 1, 12, 30), include_timezone=False) '12:30 p.m.' >>> import pytz >>> tz = pytz.timezone("Africa/Johannesburg") >>> dt = tz.localize(datetime(2021, 9, 1, 12, 30)) >>> reuters_style.time(dt) '12:30 p.m. SAST' >>> reuters_style.time(dt, include_timezone=False) '12:30 p.m. (1030 GMT)'
- reuters_style.validate_slug(slug)¶
Check whether a full slug is valid.
Style guide entry:
A slug is a simple human readable method of grouping content for packaging, either internally or externally. By using the same slug for the same real world event Reuters can ensure that it is easy to find pictures, text, graphics, video, audio that all belong together.
A slug has two parts:
a packaging slug (FERRARI-IPO/)
a wild slug (PROSPECTUS)
They come together as the full slug in FERRARI-IPO/PROSPECTUS.
- Parameters:
slug (str) – The full slug to validate. (str)
- Returns:
Whether the full slug is valid. (bool)
- Raises:
ValueError – If the full slug is invalid.
- Return type:
Examples
>>> import reuters_style >>> reuters_style.validate_slug("FERRARI-IPO/PROSPECTUS") True >>> reuters_style.validate_slug("FERRARI-IPO/PROSPECTUS REPORT") Traceback (most recent call last): ... ValueError: Wild slug can only contain uppercase letters, hyphens and slashes.
- reuters_style.validate_packaging_slug(slug)¶
Check whether a packaging slug is valid.
Style guide entry:
A slug is a simple human readable method of grouping content for packaging, either internally or externally. By using the same slug for the same real world event Reuters can ensure that it is easy to find pictures, text, graphics, video, audio that all belong together.
A slug has two parts:
a packaging slug (FERRARI-IPO/)
a wild slug (PROSPECTUS)
They come together as the full slug in FERRARI-IPO/PROSPECTUS.
The packaging slug is the part that is used to pull a package of stories together with visuals and so MUST STAY THE SAME for as long as the story runs through updates, wrap-ups and for days, weeks or even months sometimes. Once a packaging slug (the first two words before the “/” mark) has been established, it should be adopted by all services and regions. For example: MALAYSIA-POLITICS/ or BRITAIN-POLITICS/.
- Parameters:
slug (str) – The packaging slug to validate. (str)
- Returns:
Whether the packaging slug is valid. (bool)
- Raises:
ValueError – If the packaging slug is invalid.
- Return type:
Examples
>>> import reuters_style >>> reuters_style.validate_packaging_slug("FERRARI-IPO/") True >>> reuters_style.validate_packaging_slug("FERRaRI IPO") Traceback (most recent call last): ... ValueError: Packaging slug can only contain uppercase letters, hyphens and slashes.
- reuters_style.validate_wild_slug(slug)¶
Check whether a wild slug is valid.
Style guide entry:
A slug is a simple human readable method of grouping content for packaging, either internally or externally. By using the same slug for the same real world event Reuters can ensure that it is easy to find pictures, text, graphics, video, audio that all belong together.
A slug has two parts:
a packaging slug (FERRARI-IPO/)
a wild slug (PROSPECTUS)
They come together as the full slug in FERRARI-IPO/PROSPECTUS.
If this story develops other angles that warrant separate content, you can add words after the “/” mark, like this: MALAYSIA-POLITICS/STATEMENT, MALAYSIA-POLITICS/PROTEST, or BRITAIN-POLITICS/PM. The part after the “/” mark is called the wild slug.
- Parameters:
slug (str) – The wild slug to validate. (str)
- Returns:
Whether the wild slug is valid. (bool)
- Raises:
ValueError – If the wild slug is invalid.
- Return type:
Examples
>>> import reuters_style >>> reuters_style.validate_wild_slug("PROSPECTUS") True >>> reuters_style.validate_wild_slug("PROSPECTUS REPORT") Traceback (most recent call last): ... ValueError: Wild slug can only contain uppercase letters, hyphens and slashes.
- class reuters_style.RIC(code, title)¶
Bases:
objectMetadata about a Refinitiv Instrument Code.
Refinitiv Instrument Codes (RICs), or ticker symbols, are crucial in helping customers find news and market data. All financial instruments — stocks, bonds, currencies and commodities — as well as many types of economic data have RICs.
Real world codes include IBM.N, EUR=, and XAU=.
- Parameters:
Examples
>>> import reuters_style >>> reuters_style.RIC(code="AAPL.O", title="Apple Inc") RIC(code='AAPL.O', title='Apple Inc') >>> obj = reuters_style.RIC(code="XAU=", title="Gold") >>> obj.code 'XAU=' >>> obj.title 'Gold' >>> print(obj) XAU=
- class reuters_style.Slug(packaging_slug, wild_slug)¶
Bases:
objectA full Reuters slug.
Style guide entry:
A slug is a simple human readable method of grouping content for packaging, either internally or externally. By using the same slug for the same real world event Reuters can ensure that it is easy to find pictures, text, graphics, video, audio that all belong together.
A slug has two parts:
a packaging slug (FERRARI-IPO/)
a wild slug (PROSPECTUS)
They come together as the full slug in FERRARI-IPO/PROSPECTUS.
Examples
>>> import reuters_style >>> reuters_style.Slug(packaging_slug="FERRARI-IPO/", wild_slug="PROSPECTUS") Slug(packaging_slug='FERRARI-IPO/', wild_slug='PROSPECTUS') >>> obj = reuters_style.Slug( ... packaging_slug="FERRARI-IPO/", wild_slug="PROSPECTUS" ... ) >>> obj.packaging_slug 'FERRARI-IPO/' >>> obj.wild_slug 'PROSPECTUS' >>> print(obj) FERRARI-IPO/PROSPECTUS >>> obj.full_slug 'FERRARI-IPO/PROSPECTUS' >>> obj.validate() True
- validate()¶
Validate the slug.
- Returns:
Whether the slug is valid. (bool)
- Raises:
ValueError – If the slug is invalid.
- Return type: