Précédent   Forum du club des développeurs et IT Pro > Autres langages > Langages fonctionnels > Haskell
Haskell Forum d'entraide sur la programmation en langage fonctionnel Haskell
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 20/09/2011, 17h39   #1
Nel_Star
Invité régulier
 
Inscription : juillet 2011
Messages : 10
Détails du profil
Informations forums :
Inscription : juillet 2011
Messages : 10
Points : 5
Points : 5
Par défaut parseur pour envoyer des cv

Bonjour,
Je viens vous voir aujourd'hui car depuis un certain temps, j'essaie dautomatiser mes envois de cv.
J'ai donc pondu du code qui normalemen sur papier marchait plus ou moins mais qui en fait l'inverse en réalité.

J'ai un fichier tesfile.txt comme suis :ç

recrutement1@site.rage 52541 "cadre"
recrutement2@site.pat 4523 "balayeur"
recrutement3@site.lol 4520 "consultant"
recrutement1@sruisu.uiu 464646 "escroc"

Ainsi que le script suivant pour envoyer desles mails :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#! /bin/sh

path = "~/scripts/project_mall"
vc = "$path/curriculum.pdf"
tiv = "$path/motiv.pdf"

lignes = $(runhaskell parseMailDb.hs $1)
i = 1

until $i == $lignes
do  (mail1_s $(runhaskell parseMailDb.hs $1 2 $i) $(runhaskell parseMailDb.hs $1 3 $i) ; uuencode $vc $vc ; uuencode $tiv $tiv) | mailx -s "candidature spontanèe" $(runhaskell parseMailDb.hs $1 1 $i)
    $i++
done
mail1_s contient :

Code :
1
2
3
4
#! /bin/sh

echo message $1 lol $2
Et enfin mon script haskell :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import System.Environment
import System.IO

field_arg :: Int -> [String] -> String
field_arg x a = if length a > 2
                then if x < 4 then a !! x else "field number is too high"
                else "field number is too low"

line_arg :: Int -> [String] -> String
line_arg x a
    | x > length a = "line number is too big"
    | x < 1        = "line number is too low"
    | otherwise    = a !! x

extrcta :: Int -> Int -> String -> String
extrcta x n = field_arg x . words . line_arg n . lines


arg_list1 :: String -> [((Int, Int), Int -> Int -> String -> String)]
arg_list1 n = let n1 = read n
              in [((1, n1), extrcta 1 n1)
                 ,((2, n1), extrcta 2 n1)
                 ,((3, n1), extrcta 3 n1)
                 ]


main :: IO ()
main = do
        args <- getArgs
        case args of
                   (path: opt1: opt2: _) -> case (opt1, opt2) `lookup` arg_list1 opt1 of
                                                                                       Nothing -> putStrLn $ "Wrong argument " ++ opt1 ++ "or" ++ opt2
                                                                                       Just act -> do
                                                                                                    withFile path ReadMode (\handle -> do
                                                                                                                                        contents <- hGetContents handle
                                                                                                                                        putStrLn $ act contents)
                   (path: _) -> do
                                 withFile path ReadMode (\handle -> do
                                                                   contents <- hGetContents handle
                                                                   putStrLn $ show . length . lines contents)
                   _ -> putStrLn "Wrong number of argument"
Compilons le script ci-dessus, en disont parseMailDb. on l'appelle ainsi :
parseMailDb testfile.txt field line
Par exemple parseMailDb testfile.txt 1 4 rends recrutement1@sruisu.uiu

Le probleme c'est que je ne comprends pas pourquoi ça ne compile pas (je ne sais pas si le tout marche). De plus ma gestion des erreurs est mediocre....

Toute aide serait appreciée.
Cordialement Nel.
Nel_Star est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/09/2011, 15h39   #2
Nel_Star
Invité régulier
 
Inscription : juillet 2011
Messages : 10
Détails du profil
Informations forums :
Inscription : juillet 2011
Messages : 10
Points : 5
Points : 5
J'ai resolu l'affaire.

http://stackoverflow.com/questions/7498343/parse-a-cv-file

Salut.
Nel_Star est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/09/2011, 10h46   #3
Twinside
Membre du Club
 
Inscription : octobre 2007
Messages : 34
Détails du profil
Informations forums :
Inscription : octobre 2007
Messages : 34
Points : 43
Points : 43
C'est l'occasion de regarder du côté de regarder du côté de Parsec pour ce genre de problèmes, vu que c'est une librairie importante du monde Haskell, ça vaut le coup.
Twinside est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/09/2011, 12h25   #4
Yo Eight
Membre confirmé
 
Homme
Ingénieur développement logiciels
Inscription : mai 2009
Messages : 89
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : Finance

Informations forums :
Inscription : mai 2009
Messages : 89
Points : 285
Points : 285
Avec ce genre de parsing "simple", il pourrait être aussi intéressant de le faire soi meme avec une donnée de type

Code :
1
2
data Parser a = P{parse :: String -> Validation (String, a)}
ou Validation serait:
Code :
1
2
data Validation a = Err String | Value a
A chaque fois, qu'un parser réussi, on revoit le reste à traiter et la valeur parsée.

En implémentant un comportement monadique à Parser, on peut avoir une solution élégante avec propagation d'erreur
Yo Eight est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 09h22.


 
 
 
 
Partenaires

Hébergement Web