-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from SSARCandy/i18n/de_de
I18n/de_de
- Loading branch information
Showing
8 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
const LANG = 'de_de'; | ||
const BASE_URL = 'http://www.starobserver.org'; | ||
|
||
const handleError = require('../utils/handleError').common; | ||
const notFoundError = require('../utils/handleError').notFound; | ||
const request = require('request'); | ||
const cheerio = require('cheerio'); | ||
const decoder = require('../utils/utils').decoder; | ||
|
||
function craw(baseData, callback) { | ||
let date = baseData.date.replace(/-/g, '').slice(2); | ||
request({ | ||
url: `${BASE_URL}/ap${date}.html`, | ||
encoding: null | ||
}, function(error, response, buf) { | ||
if (handleError(error, response)) { | ||
return callback(handleError(error, response)); | ||
} | ||
|
||
let decoded = decoder(buf); | ||
|
||
let $ = cheerio.load(decoded); | ||
let title = $('body > center > h3').text().trim(); | ||
let explanation = $('body > center > p:nth-child(6)').text().trim(); | ||
|
||
if (!title || !explanation) { | ||
return callback(notFoundError(baseData.date, LANG)); | ||
} | ||
|
||
baseData.title = title; | ||
baseData.explanation = explanation; | ||
baseData.lang = LANG; | ||
return callback(null, baseData); | ||
}); | ||
} | ||
|
||
module.exports = craw; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters