Skip to content

Commit

Permalink
Add a flag to print sent articles showing them as such for analysis a…
Browse files Browse the repository at this point in the history
…nd sharing.
  • Loading branch information
AWare committed Oct 22, 2019
1 parent af0f3c5 commit c741547
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions projects/backend/capi/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const getMainMediaAtom = (

const parseArticleResult = async (
result: IContent,
print: boolean,
): Promise<[number, CAPIContent]> => {
const path = result.id
console.log(`Parsing CAPI response for ${path}`)
Expand Down Expand Up @@ -148,6 +149,7 @@ const parseArticleResult = async (
elements,
starRating,
mainMedia: getMainMediaAtom(result.blocks),
print,
},
]
return article
Expand All @@ -167,6 +169,7 @@ const parseArticleResult = async (
bylineHtml: bylineHtml || '',
standfirst: trail || '',
elements,
print,
},
]

Expand All @@ -187,6 +190,7 @@ const parseArticleResult = async (
bylineHtml: bylineHtml || '',
standfirst: trail || '',
elements,
print,
},
]

Expand Down Expand Up @@ -228,6 +232,7 @@ const parseArticleResult = async (
bylineHtml: bylineHtml || '',
standfirst: trail || '',
crossword,
print,
},
]

Expand Down Expand Up @@ -258,6 +263,7 @@ const parseArticleResult = async (
html: `<pre>${JSON.stringify(result.apiUrl)}</pre>`,
},
],
print,
},
]
}
Expand All @@ -280,7 +286,7 @@ export const getArticles = async (
capi: 'printsent' | 'search',
): Promise<{ [key: string]: CAPIContent }> => {
const paths = ids.map(_ => `internal-code/page/${_}`)

const print = capi === 'printsent'
const endpoint = capi === 'printsent' ? printsent(paths) : search(paths)
if (endpoint.length > 1000) {
console.warn(
Expand Down Expand Up @@ -316,7 +322,7 @@ export const getArticles = async (
const data = SearchResponseCodec.decode(input)
const results: IContent[] = data.results
const articlePromises = await Promise.all(
results.map(result => attempt(parseArticleResult(result))),
results.map(result => attempt(parseArticleResult(result, print))),
)

//If we fail to get an article in a collection we just ignore it and move on.
Expand Down
1 change: 1 addition & 0 deletions projects/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export interface Content extends WithKey {
showQuotedHeadline: boolean
mediaType: MediaType
sportScore?: string
print: boolean
}
export interface Article extends Content {
type: 'article'
Expand Down

0 comments on commit c741547

Please sign in to comment.