44 "errors"
55 "github.com/EffnerApp/subparser/model"
66 "github.com/PuerkitoBio/goquery"
7+ "regexp"
78 "strings"
89 "time"
910)
@@ -61,6 +62,12 @@ func parsePlan(content string) (*model.Plan, error) {
6162 return nil , err
6263 }
6364
65+ // load the infos
66+ infos , err := findInfos (document )
67+ if err != nil {
68+ return nil , err
69+ }
70+
6471 // load the substitutions
6572 substitutions , err := findSubstitutions (document )
6673
@@ -73,10 +80,50 @@ func parsePlan(content string) (*model.Plan, error) {
7380 Date : date ,
7481 CreatedAt : createdAt ,
7582 Absent : absent ,
83+ Infos : infos ,
7684 Substitutions : substitutions ,
7785 }, nil
7886}
7987
88+ func findInfos (document * goquery.Document ) ([]string , error ) {
89+ table := document .Find ("table.F" )
90+
91+ if table == nil {
92+ return []string {}, nil
93+ }
94+
95+ table = table .First ()
96+
97+ if table == nil {
98+ return []string {}, nil
99+ }
100+
101+ infos := make ([]string , 0 )
102+
103+ space := regexp .MustCompile (`\s+` )
104+
105+ // very ugly but works...
106+ table .Find ("th.F" ).Each (func (_ int , th * goquery.Selection ) {
107+ text := th .Text ()
108+ text = strings .TrimPrefix (text , "\n " )
109+
110+ if text == "" {
111+ return
112+ }
113+
114+ text = strings .Replace (text , "\t " , " " , - 1 )
115+
116+ // some strange character they for some reason contain. Never touch this.
117+ text = strings .Replace (text , " " , " " , - 1 )
118+
119+ text = strings .TrimSpace (text )
120+ text = space .ReplaceAllString (text , " " )
121+
122+ infos = append (infos , text )
123+ })
124+ return infos , nil
125+ }
126+
80127func findSubstitutions (document * goquery.Document ) ([]model.Substitution , error ) {
81128 table := document .Find ("table.k" )
82129 if table != nil {
@@ -146,7 +193,7 @@ func findCreatedAt(document *goquery.Document) (time.Time, error) {
146193 text = text [11 :strings .Index (text , ")" )]
147194
148195 // parse the text into a date-time
149- date , err := time .Parse ("_2.01 .2006 um 15:04 Uhr" , text )
196+ date , err := time .Parse ("_2.1 .2006 um 15:04 Uhr" , text )
150197
151198 if err != nil {
152199 return time .Now (), err
0 commit comments