()
| 899 | FUNCTION fetchQuotes |
| 900 | ------------------------------------------------------------------*/ |
| 901 | async function fetchQuotes(){ |
| 902 | if (!QUOTE_SHOW_QUOTES) return unknownQuotesData; |
| 903 | |
| 904 | if (TESTING) return unknownQuotesData; |
| 905 | |
| 906 | let response; |
| 907 | |
| 908 | const quotesURL = baseQuotesURL + '?maxLength=' + QUOTE_MAX_LENGTH + '&tags=' + QUOTE_TAGS.join('%7C'); // %7C is code for | |
| 909 | |
| 910 | try { |
| 911 | writeLOG(`Fetching quotes at url: ${quotesURL}`); |
| 912 | const request = new Request(quotesURL); |
| 913 | request.timeoutInterval = 30; |
| 914 | response = await request.loadJSON(); |
| 915 | } catch (error) { |
| 916 | writeLOG(`Couldn't fetch quotes from ${quotesURL}`); |
| 917 | return unknownQuotesData; |
| 918 | } |
| 919 | writeLOG("JSON Quotes Data: " + JSON.stringify(response)); |
| 920 | let quoteWithAuthor = []; |
| 921 | // Wrap text |
| 922 | let wrapText = (s, w) => s.replace( |
| 923 | new RegExp(`(?![^\\n]{1,${w}}$)([^\\n]{1,${w}})\\s`, 'g'), ' $1| ' |
| 924 | ); |
| 925 | quoteWithAuthor = wrapText(response.content,QUOTE_WRAP_LENGTH).split('|'); |
| 926 | quoteWithAuthor.push({rsize: DETAIL_RSIZE, title: "[" + response.author + "]"}); |
| 927 | return { |
| 928 | quote: response.content, |
| 929 | author: response.author, |
| 930 | quoteWithAuthor: quoteWithAuthor, |
| 931 | length: response.length |
| 932 | } |
| 933 | } |
| 934 | /*------------------------------------------------------------------ |
| 935 | FUNCTION fetchCalendar |
| 936 | ------------------------------------------------------------------*/ |
no test coverage detected