PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Stock Market On Mint 18.2 Bash & Perl Example

Go down

Stock Market On Mint 18.2 Bash & Perl Example Empty Stock Market On Mint 18.2 Bash & Perl Example

Post by jamied_uk 23rd July 2017, 03:50

jamied_uk
jamied_uk
Admin

Posts : 2951
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Stock Market On Mint 18.2 Bash & Perl Example Empty Re: Stock Market On Mint 18.2 Bash & Perl Example

Post by jamied_uk 23rd July 2017, 03:57

First Install:

Code:
sudo apt-get install -y libfinance-quote-perl

If above fails you can use:

finance-quote.sourceforge.net/download.html


stocks2.csv


Code:
TWTR,NYSE
TGT,NYSE
DAL,NYSE
DVN,NYSE
DOW,NYSE
TWX,NYSE
FOXA,NYSE
TSLA,NASDAQ


Perl_stock.pl


Code:
#!/usr/bin/perl
# (c) J~Net 2016
#ALL RIGHTS RESERVED!
#
# sudo apt-get install -y libfinance-quote-perl
# Usage ./perl_stock.pl stocks.csv  > output.txt
# cat output.txt
#
# Original https://linuxconfig.org/fetch-stock-quotes-with-perl-finance-quote-module
#

use Finance::Quote;

my $q = Finance::Quote->new();
open (FIN, $ARGV[0]) || die ("Could not open $ARGV[0]");

while ($line = <FIN>) {
  ($field1,$field2) = split ',', $line;

my %hash = (
    $field1 => $field2 );

  chomp(%hash);

  foreach my $i (keys %hash) {
  my %data = $q->fetch( $hash{$i}, $i);

print $hash{$i} . " " . $i . " Price " . $data{$i, 'price'} . "\n";
  }

}
close (FIN);

# write output to file
use strict;
use warnings;

# gedit output.txt

Run.sh

Code:
#!/bin/bash
# Usage: ./Run.sh
#
#echo -en "\e[92m\c"
if [ -e final.txt ]
then
    mv final.txt old_final.txt
fi

#  sh Run.sh &&
sh run3.sh > final.txt
cat final.txt

if [ -e old_final.txt ]
then
    echo "Now For The Differences... "
    diff old_final.txt final.txt
    echo "> Means ^ & < Means Down!"
fi
echo "Finished."


Run3.sh

Code:
#!/bin/bash
# Usage ./Run.sh
if [ -e output2.txt ]
then
    mv output2.txt old_output.txt
fi

./perl_stock.pl stocks2.csv  > output2.txt

if [ -e old_output.txt ]
then
    echo "Now For The Differences... "
    diff old_output.txt output.txt
    echo "> Means ^ & < Means Down!"
fi

cat output2.txt


Last edited by jamied_uk on 20th November 2017, 23:21; edited 1 time in total
jamied_uk
jamied_uk
Admin

Posts : 2951
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Stock Market On Mint 18.2 Bash & Perl Example Empty Re: Stock Market On Mint 18.2 Bash & Perl Example

Post by jamied_uk 23rd July 2017, 04:01

For more info

Original https://linuxconfig.org/fetch-stock-quotes-with-perl-finance-quote-module





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





The unreliable bash side



./stock_full.sh tickers.txt

use perl to get stock prices

perlmaven.com/writing-to-files-with-perl

perlmonks.org/?node_id=960

marketwatch.com/tools/quotes/lookup.asp?siteID=mktw&Lookup=t&Country=all&Type=All

perlmaven.com/subroutines-and-functions-in-perl

stackoverflow.com/questions/10682087/how-to-redirect-console-output-to-a-text-file

askubuntu.com/questions/515900/how-to-compare-two-files

encrypted.google.com/search?q=read+file+in+linux+bash+compare+2+files+
jamied_uk
jamied_uk
Admin

Posts : 2951
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Stock Market On Mint 18.2 Bash & Perl Example Empty Re: Stock Market On Mint 18.2 Bash & Perl Example

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum