@@ -43,16 +43,6 @@ func (indexer *ForumIndexer) Close() {
4343func (indexer * ForumIndexer ) run () {
4444 log .Info ("starting forum indexer" )
4545
46- hosts := []string {
47- "www.pathofexile.com" ,
48- "br.pathofexile.com" ,
49- "ru.pathofexile.com" ,
50- "th.pathofexile.com" ,
51- "de.pathofexile.com" ,
52- "fr.pathofexile.com" ,
53- "es.pathofexile.com" ,
54- }
55-
5646 accounts := []string {
5747 "Chris" , "Jonathan" , "Erik" , "Mark_GGG" , "Samantha" , "Rory" , "Rhys" , "Qarl" , "Andrew_GGG" ,
5848 "Damien_GGG" , "Joel_GGG" , "Ari" , "Thomas" , "BrianWeissman" , "Edwin_GGG" , "Support" , "Dylan" ,
@@ -84,18 +74,18 @@ func (indexer *ForumIndexer) run() {
8474 }
8575
8676 var wg sync.WaitGroup
87- wg .Add (len (hosts ))
77+ wg .Add (len (Locales ))
8878
89- for _ , host := range hosts {
90- host := host
79+ for _ , l := range Locales {
80+ l := l
9181 go func () {
9282 for {
9383 for _ , account := range accounts {
9484 select {
9585 case <- indexer .closeSignal :
9686 return
9787 default :
98- indexer .index (host , account , timezone )
88+ indexer .index (l , account , timezone )
9989 time .Sleep (time .Second )
10090 }
10191 }
@@ -135,34 +125,7 @@ var postURLExpression = regexp.MustCompile("^/forum/view-thread/([0-9]+)/page/([
135125var threadURLExpression = regexp .MustCompile ("^/forum/view-thread/([0-9]+)" )
136126var forumURLExpression = regexp .MustCompile ("^/forum/view-forum/([0-9]+)" )
137127
138- var monthReplacer = strings .NewReplacer (
139- "ม.ค." , "Jan" ,
140- "ก.พ." , "Feb" ,
141- "มี.ค." , "Mar" ,
142- "เม.ย." , "Apr" ,
143- "พ.ค." , "May" ,
144- "มิ.ย." , "Jun" ,
145- "ก.ค." , "Jul" ,
146- "ส.ค." , "Aug" ,
147- "ก.ย." , "Sep" ,
148- "ต.ค." , "Oct" ,
149- "พ.ย." , "Nov" ,
150- "ธ.ค." , "Dec" ,
151- "janv." , "Jan" ,
152- "févr." , "Feb" ,
153- "mars" , "Mar" ,
154- "avril" , "Apr" ,
155- "mai" , "May" ,
156- "juin" , "Jun" ,
157- "juil." , "Jul" ,
158- "août" , "Aug" ,
159- "sept." , "Sep" ,
160- "oct." , "Oct" ,
161- "nov." , "Nov" ,
162- "déc." , "Dec" ,
163- )
164-
165- func ScrapeForumPosts (doc * goquery.Document , timezone * time.Location ) ([]* ForumPost , error ) {
128+ func ScrapeForumPosts (doc * goquery.Document , locale * Locale , timezone * time.Location ) ([]* ForumPost , error ) {
166129 posts := []* ForumPost (nil )
167130
168131 err := error (nil )
@@ -178,21 +141,9 @@ func ScrapeForumPosts(doc *goquery.Document, timezone *time.Location) ([]*ForumP
178141 }
179142 post .BodyHTML = body
180143
181- timeText := monthReplacer .Replace (sel .Find (".post_date" ).Text ())
182-
183- for _ , format := range []string {
184- "Jan _2, 2006 3:04:05 PM" ,
185- "2/1/2006 15:04:05" ,
186- "2.1.2006 15:04:05" ,
187- "_2 Jan 2006, 15:04:05" ,
188- "_2 Jan 2006 15:04:05" ,
189- } {
190- if t , err := time .ParseInLocation (format , timeText , timezone ); err == nil {
191- post .Time = t
192- break
193- }
194- }
195- if post .Time .IsZero () {
144+ timeText := sel .Find (".post_date" ).Text ()
145+
146+ if post .Time , err = locale .ParseTime (timeText , timezone ); err != nil {
196147 log .WithField ("text" , timeText ).Error ("unable to parse time" )
197148 return false
198149 }
@@ -226,32 +177,32 @@ func ScrapeForumPosts(doc *goquery.Document, timezone *time.Location) ([]*ForumP
226177 return posts , nil
227178}
228179
229- func (indexer * ForumIndexer ) forumPosts (host , poster string , page int , timezone * time.Location ) ([]* ForumPost , error ) {
230- doc , err := indexer .requestDocument (host , fmt .Sprintf ("/account/view-posts/%v/page/%v" , poster , page ))
180+ func (indexer * ForumIndexer ) forumPosts (locale * Locale , poster string , page int , timezone * time.Location ) ([]* ForumPost , error ) {
181+ doc , err := indexer .requestDocument (locale . ForumHost () , fmt .Sprintf ("/account/view-posts/%v/page/%v" , poster , page ))
231182 if err != nil {
232183 return nil , err
233184 }
234- posts , err := ScrapeForumPosts (doc , timezone )
185+ posts , err := ScrapeForumPosts (doc , locale , timezone )
235186 if err != nil {
236187 return nil , err
237188 }
238189 for _ , post := range posts {
239- post .Host = host
190+ post .Host = locale . ForumHost ()
240191 }
241192 return posts , nil
242193}
243194
244- func (indexer * ForumIndexer ) index (host , poster string , timezone * time.Location ) {
195+ func (indexer * ForumIndexer ) index (locale * Locale , poster string , timezone * time.Location ) {
245196 logger := log .WithFields (log.Fields {
246- "host" : host ,
197+ "host" : locale . ForumHost () ,
247198 "poster" : poster ,
248199 })
249200
250201 cutoff := time .Now ().Add (time .Hour * - 12 )
251202 activity := []Activity (nil )
252203
253204 for page := 1 ; ; page ++ {
254- posts , err := indexer .forumPosts (host , poster , page , timezone )
205+ posts , err := indexer .forumPosts (locale , poster , page , timezone )
255206 if err != nil {
256207 logger .WithError (err ).Error ("error requesting forum posts" )
257208 }
0 commit comments