Skip to content

Instantly share code, notes, and snippets.

@willinspire
Last active September 25, 2018 06:28
Show Gist options
  • Save willinspire/5a1f9dd7ee05ee1e5f53a0e584b3c9e6 to your computer and use it in GitHub Desktop.
Save willinspire/5a1f9dd7ee05ee1e5f53a0e584b3c9e6 to your computer and use it in GitHub Desktop.
Fetch asset-linked news stories categorized by the Wall Street Journal
#! /bin/bash
#### ABOUT ####----------------------------------------------------------------#
#
# Script: assetnews.sh
# Source: http://bit.ly/assetnews
#
# Fetch asset-linked news stories categorized by the Wall Street Journal
#
# This script can be customized to fetch news stories related to any mainstream
# financial asset by adjusting the 'WSJ_DSYM' variable accordingly. The default
# configuration fetches news related to bitcoin by targeting the following three
# tickers:
#
# --> INDEX/XX/ARCX/NYXBT
# --> FUTURE/US/XCBF/XBTV8
# --> FUTURE/US/GLBX/BTCU8
#
# Created by h8rt3rmin8r on 20180924 for ResoNova International Consulting, LLC
# Additional parameters and related functions will be released soon.
# Connect online at https://resonova.com
#
#### MIT LICENSE ####----------------------------------------------------------#
#
# Copyright (c) 2018 ResoNova International Consulting, LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#### SYSTEM COMPATIBILITY TEST ####--------------------------------------------#
PROGRAMS=( "bash" "curl" "date" "dos2unix" "jq" )
function depends() {
for i in ${PROGRAMS[@]}; do
command -v $i >/dev/null 2>&1 || { echo >&2 "Requires $i but it's not installed. Aborting."; exit 1; }
done
}
depends
#### FUNCTIONS AND VARIABLE ASSIGNMENTS ####-----------------------------------#
function dpast_utc_month () {
local m_past=${1:-0}
if ! date -v-${m_past}m --utc '+%FT%T.%3NZ' 2>/dev/null;
then date --date="-${m_past} month" --utc '+%FT%T.%3NZ'; fi
}
DT_A=$(dpast_utc_month 1)
DT_B=$(dpast_utc_month)
# Endpoint variables
CRL="curl -s "
WSJ_END_001='https://api.wsj.net/api/delToro/argus/recent-news'
# Request headers
# Example of completed request headers: https://pastebin.com/raw/i0UQkGC3
WSJ_H_EXAMPLE=$(${CRL}"https://pastebin.com/raw/i0UQkGC3" | dos2unix)
WSJ_H1='User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0'
WSJ_H2='Accept: */*'
WSJ_H3='Accept-Language: en-US,en;q=0.5'
WSJ_H4='Referer: https://www.wsj.com/watchlist'
WSJ_H5='Content-Type: application/json'
WSJ_H6='Origin: https://www.wsj.com'
WSJ_H7='Connection: keep-alive'
WSJ_H8='Cache-Control: max-age=0'
# Data parameters
# Example of data parameters: https://pastebin.com/raw/2vssG1FS
WSJ_D_EXAMPLE=$(${CRL}"https://pastebin.com/raw/2vssG1FS" | dos2unix)
WSJ_D=( '{' '"Symbols":["' '","' '"],"Source":"' '","Count":' ',"Skip":' ',"MinDate":"' '","MaxDate":"' '","Prominence":"' '"' '}' )
WSJ_DSYM=( "INDEX/XX/ARCX/NYXBT" "FUTURE/US/XCBF/XBTV8" "FUTURE/US/GLBX/BTCU8" )
WSJ_DSRC=( "103_115_424_425_426_427" )
WSJ_DCOU=( "30" "50" )
WSJ_DSKP=( "0" )
WSJ_DZDT=( "${DT_A}" "${DT_B}" )
WSJ_DPRO=( "prominent" )
WSJ_DSYM_X="${WSJ_D[1]}${WSJ_DSYM[0]}${WSJ_D[2]}${WSJ_DSYM[1]}${WSJ_D[2]}${WSJ_DSYM[2]}"
WSJ_DSRC_X="${WSJ_D[3]}${WSJ_DSRC[0]}"
WSJ_DCOU_X="${WSJ_D[4]}${WSJ_DCOU[0]}"
WSJ_DSKP_X="${WSJ_D[5]}${WSJ_DSKP[0]}"
WSJ_DZDT_X="${WSJ_D[6]}${WSJ_DZDT[0]}${WSJ_D[7]}${WSJ_DZDT[1]}"
WSJ_DPRO_X="${WSJ_D[8]}${WSJ_DPRO[0]}${WSJ_D[9]}"
WSJ_DX="${WSJ_D[0]}${WSJ_DSYM_X}${WSJ_DSRC_X}${WSJ_DCOU_X}${WSJ_DSKP_X}${WSJ_DZDT_X}${WSJ_DPRO_X}${WSJ_D[10]}"
#### CORE OPERATIONS ####------------------------------------------------------#
${CRL}"${WSJ_END_001}" -H "${WSJ_H1}" -H "${WSJ_H2}" -H "${WSJ_H3}" \
-H "${WSJ_H4}" -H "${WSJ_H5}" -H "${WSJ_H6}" -H "${WSJ_H7}" \
-H "${WSJ_H8}" --compressed --data "${WSJ_DX}"
################################################################################
# #
# "think outside the box" #
# #
# ($) ¯\_(ツ)_/¯ (฿) #
# #
#############################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment