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 :
mail1_s contient :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Et enfin mon script haskell :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 #! /bin/sh echo message $1 lol $2
Compilons le script ci-dessus, en disont parseMailDb. on l'appelle ainsi :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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"
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.
Partager