Re: [#!/fr] Conversion de monnaies

Page principale
Supprimer ce message
Répondre à ce message
Auteur: KOENIG Yvan
Date:  
À: La liste francophone des scripts shell
Sujet: Re: [#!/fr] Conversion de monnaies
Bonsoir

Je viens de retrouver le script avec lequel il m'est possible de récupérer des historiques :
DOW_JONES, NASDAQ, AAPL

--{code}
--[SCRIPT grab_history_DOW_JONES_&_NASDAQ]
(*
Enregistrer le script en tant que Script : grab_history_DOW_JONES_&_NASDAQ.scpt
déplacer le fichier créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.

menu Scripts > Numbers > grab_history_DOW_JONES_&_NASDAQ

Le script télécharge (via Curl) l'historique des informations sur les indices DOW JONES et NASDAQ.
Il les enregistre dans un fichier de valeurs tabulées puis ouvre celui-ci dans Numbers.

L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".

**********

Save the script as a Script : grab_history_DOW_JONES_&_NASDAQ.scpt

Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.

menu Scripts > Numbers > grab_history_DOW_JONES_&_NASDAQ

Using Curl, it download historic datas about DOW JONES and NASDAQ.
It save them in a Tab Separated Values text file which it open with Numbers.

The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.

Yvan KOENIG (VALLAURIS, France)

2010/10/21
2010/10/23 -- added optional Sort and optional Save
*)
--=====

property theApp : "Numbers"

property tri_ascendant : true
(*
true = sort ascending upon dates
false = don't sort *)
property enregistre_numbers : true
(*
true = Save the Numbers documents
false = Don't save *)

--=====

on run
    local t3, une_date, ce_jour, ce_mois, cette_annee, t4, noms_indices, nom_indice, parms, texte, les_fichiers, un_fichier, the_range

    
    set t3 to "http://ichart.finance.yahoo.com/table.csv?s="

    
    set une_date to current date
    set ce_jour to day of une_date
    set ce_mois to (month of une_date as number) - 1 (* CAUTION, yahoo number months from 0 to 11 *)
    set cette_annee to year of une_date
    set t4 to "&d=" & ce_mois & "&e=" & ce_jour & "&f=" & cette_annee & "&g=d&a=9&b=1&c=1928&ignore=.csv"

    
    set les_fichiers to {}
    repeat with noms_indices in {{"DOW_JONES", "%5EDJI"}, {"NASDAQ", "%5EIXIC"}, {"Apple", "AAPL"}}
        set {nom_indice, parms} to noms_indices
        (*
Download the full archived table of values *)
        set texte to do shell script "curl " & quoted form of (t3 & parms & t4)
        (*
Build a list of the created text files *)
        copy my enregistre_en_TSV(texte, nom_indice) to end of les_fichiers
    end repeat
    (*
Today, the Dow Jones files have 20609 rows so, on old machines (PPC ones)
the import and the save process may require more than the default two minutes.
To take care of that, I tell Applescript that each process is allowed to require four minutes. *)
(* J'ai désactivé la partie qui insère les données dans des tables de Numbers *)
(*
    tell application "Numbers"
        repeat with un_fichier in les_fichiers
            with timeout of 240 seconds
                open file un_fichier
            end timeout

            
            if tri_ascendant then
                tell document 1 to tell sheet 1 to tell table 1
                    set the_range to "A2:" & name of cell -1 of column 1
                    sort by column 1 direction ascending in rows range the_range
                end tell
            end if -- tri_ascendant

            
            if enregistre_numbers then
                my ring_the_bell()
                with timeout of 240 seconds
                    save document 1
                end timeout
            end if -- enregistre_numbers
        end repeat -- with un_fichier
    end tell
*)
end run


--=====

on ring_the_bell()
    beep 1
end ring_the_bell


--=====

on enregistre_en_TSV(le_texte, l_indice)
    local p2d, nom_fichier_texte, le_fichier
    (*
Replace every comma delimiters by a TAB character *)
    set le_texte to my remplace(le_texte, ",", tab)
    (*
If the system uses the decimal comma, replace the used decimal periods by commas *)
    if character 2 of (0.5 as text) is "," then set le_texte to my remplace(le_texte, ".", ",")
    (*
Build the path of the folder in which we will save the temporary text file *)
    set p2d to "" & (path to temporary items)
    (*
Build the unique name of the temporary text file *)
    set nom_fichier_texte to (do shell script "date +" & l_indice & "_%Y%m%d_%H%M%S.txt")
    (*
Build the full path of the temporary text file *)
    set le_fichier to p2d & nom_fichier_texte
    (*
Create the temporary text file *)
    tell application "System Events" to make new file at end of folder p2d with properties {name:nom_fichier_texte}
    (*
Write datas in the temporary text file *)
    write le_texte to file le_fichier
    (*
Returns the full path of the temporary text file *)
    return le_fichier
end enregistre_en_TSV


--=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
    local oTIDs, l
    set oTIDs to AppleScript's text item delimiters
    set AppleScript's text item delimiters to d1
    set l to text items of t
    set AppleScript's text item delimiters to d2
    set t to l as text
    set AppleScript's text item delimiters to oTIDs
    return t
end remplace


--=====
--[/SCRIPT]
--{code}

Avec un peu de chance quelqu'un saura adapter à la récupération des taux de change.

Yvan KOENIG (VALLAURIS, France) vendredi 16 septembre 2011 22:52:05




_______________________________________________
archives :
http://listes.patpro.net/list/sshfr.fr.html
http://listes.patpro.net/mailman/listinfo/script_shell_fr