Skip to content
Snippets Groups Projects
Select Git revision
  • a2b34eaf1838f2dd8d51491862b84944eb02227a
  • main default protected
2 results

data.sh

Blame
  • data.sh 3.23 KiB
    #!/bin/bash
    curl  https://www.kitco.com/charts/livegold.html > gold.html
    goldBID=$(cat gold.html | grep -E "sp-bid" | sed 's/[^.0-9]*//g')
    goldASK=$(cat gold.html | grep -E "sp-ask" | sed 's/[^.0-9]*//g')
    goldCHG=$(cat gold.html | grep -E "sp-chg-value" | sed 's/[^.0-9]*//g')
    goldCHGpercent=$(cat gold.html | grep -E "sp-chg-percent" | sed 's/[^.0-9]*//g')
    
    curl  https://www.kitco.com/charts/livesilver.html > silver.html
    silverBID=$(cat silver.html | grep -E "sp-bid" | sed 's/[^.0-9]*//g')
    silverASK=$(cat silver.html | grep -E "sp-ask" | sed 's/[^.0-9]*//g')
    silverCHG=$(cat silver.html | grep -E "sp-chg-value" | sed 's/[^.0-9]*//g')
    silverCHGpercent=$(cat silver.html | grep -E "sp-chg-percent" | sed 's/[^.0-9]*//g')
    
    curl  https://www.kitco.com/charts/liveplatinum.html > platinum.html
    platinumBID=$(cat platinum.html | grep -E "sp-bid" | sed 's/[^.0-9]*//g')
    platinumASK=$(cat platinum.html | grep -E "sp-ask" | sed 's/[^.0-9]*//g')
    platinumCHG=$(cat platinum.html | grep -E "sp-chg-value" | sed 's/[^.0-9]*//g')
    platinumCHGpercent=$(cat platinum.html | grep -E "sp-chg-percent" | sed 's/[^.0-9]*//g')
    
    curl https://www.kitco.com/charts/livepalladium.html > palladium.html
    palladiumBID=$(cat palladium.html | grep -E "sp-bid" | sed 's/[^.0-9]*//g')
    palladiumASK=$(cat palladium.html | grep -E "sp-ask" | sed 's/[^.0-9]*//g')
    palladiumCHG=$(cat palladium.html | grep -E "sp-chg-value" | sed 's/[^.0-9]*//g')
    palladiumCHGpercent=$(cat palladium.html | grep -E "sp-chg-percent" | sed 's/[^.0-9]*//g')
    
    date=$(date +%Y-%d-%m)
    time=$(date "+%H:%M:%S %p")
    
    #store to database
    $(/opt/lampp/bin/mysql -u root -e"use cw2; insert into gold (goldBit,goldAsk,goldChg,goldChgPercent,dateTime) values ($goldBID,$goldASK,$goldCHG,$goldCHGpercent,default)")
    
    $(/opt/lampp/bin/mysql -u root -e"use cw2; insert into silver (silverBit,silverAsk,silverChg,silverChgPercent,dateTime) values ($silverBID,$silverASK,$silverCHG,$silverCHGpercent,default)")
    
    $(/opt/lampp/bin/mysql -u root -e"use cw2; insert into platinum (platinumBit,platinumAsk,platinumChg,platinumChgPercent,dateTime) values ($platinumBID,$platinumASK,$platinumCHG,$platinumCHGpercent,default)")
    
    $(/opt/lampp/bin/mysql -u root -e"use cw2; insert into palladium (palladiumBit,palladiumAsk,palladiumChg,palladiumChgPercent,dateTime) values ($palladiumBID,$palladiumASK,$palladiumCHG,$palladiumCHGpercent,default)")
    
    #store to txt file
    echo -e "goldBid,$goldBID,goldAsk,$goldASK,goldChg,$goldCHG,goldChgPercent,$goldCHGpercent,$date $time\nsilverBid,$silverBID,silverAsk,$silverASK,silverChg,$silverCHG,silverChgPercent,$silverCHGpercent,$date $time\nplatinumBid,$platinumBID,platinumAsk,$platinumASK,platinumChg,$platinumCHG,platinumChgPercent,$platinumCHGpercent,$date $time\npalladiumBid,$palladiumBID,palladiumAsk,$palladiumASK,palladiumChg,$palladiumCHG,palladiumChgPercent,$palladiumCHGpercent,$date $time\n" >> data.txt
    
    #store to csv file
    gold=$(cat data.txt | grep -E 'gold' | cut -d ',' -f2,4,6,8,9)
    silver=$(cat data.txt | grep -E 'silver' | cut -d ',' -f2,4,6,8,9)
    platinum=$(cat data.txt | grep -E 'platinum' | cut -d ',' -f2,4,6,8,9)
    palladium=$(cat data.txt | grep -E 'palladium' | cut -d ',' -f2,4,6,8,9)
    
    echo "$gold" > gold.csv
    echo "$silver" > silver.csv
    echo "$platinum" > platinum.csv
    echo "$palladium" > palladium.csv