-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParsersArchivos.hs
127 lines (95 loc) · 2.85 KB
/
ParsersArchivos.hs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module ParsersArchivos
(
parseAccount,
parseProfile,
parseVerified,
parsePhone,
parseTweets
) where
import TiposDatos
import TiposDatos2
import System.Exit
import Data.Aeson
import qualified Data.ByteString.Lazy as B
parseAccount :: String -> IO Account
parseAccount path = do
preparaAccount path
file <- B.readFile (path++".mod")
let account = decode file :: Maybe TiposDatos.Account
case account of
Nothing -> return TiposDatos.defaultAccount
Just account -> return account
preparaAccount :: String -> IO()
preparaAccount path = do
file <- readFile path --String
let mod = modAccFile file
writeFile (path++".mod") mod
return()
modAccFile :: String -> String
modAccFile string = drop 45 $ reverse $ drop 3 $ reverse string
parseProfile :: String -> IO Profile
parseProfile path = do
preparaProfile path
file <- B.readFile (path++".mod")
let profile = decode file :: Maybe TiposDatos.Profile
case profile of
Nothing -> return TiposDatos.defaultProfile
Just profile -> return profile
preparaProfile :: String -> IO()
preparaProfile path = do
file <- readFile path --String
let mod = modProFile file
writeFile (path++".mod") mod
return()
modProFile :: String -> String
modProFile string = drop 45 $ reverse $ drop 3 $ reverse string
parseVerified :: String -> IO Verified
parseVerified path = do
preparaVerified path
file <- B.readFile (path++".mod")
let verified = decode file :: Maybe TiposDatos.Verified
case verified of
Nothing -> return TiposDatos.defaultVerified
Just verified -> return verified
preparaVerified:: String -> IO()
preparaVerified path = do
file <- readFile path --String
let mod = modVeriFile file
writeFile (path++".mod") mod
return()
modVeriFile :: String -> String
modVeriFile string ="{" ++ (drop 79 $ reverse $ drop 4 $ reverse string)
parsePhone :: String -> IO Phone
parsePhone path = do
preparaPhone path
file <- B.readFile (path++".mod")
let phone = decode file :: Maybe TiposDatos2.Phone
case phone of
Nothing -> return TiposDatos2.defaultPhone
Just phone -> return phone
preparaPhone:: String -> IO()
preparaPhone path = do
file <- readFile path --String
let mod = modPhoneFile file
writeFile (path++".mod") mod
return()
modPhoneFile :: String -> String
modPhoneFile string ="{" ++ (drop 50 $ reverse $ drop 4 $ reverse string)
parseTweets :: String -> IO [Tweet]
parseTweets path = do
preparaTweets path
file <- B.readFile (path++".mod")
let tweets = decode file :: Maybe [Tweet]
case tweets of
Nothing -> exitSuccess
Just tweets -> return tweets
preparaTweets:: String -> IO()
preparaTweets path = do
file <- readFile path --String
let mod = modTweetsFile file
writeFile (path++".mod") mod
return()
modTweetsFile :: String -> String
modTweetsFile string = drop 25 string