diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..490b385 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +node_modules +*.obj +*.out +*.pyc +package-lock.json +.vscode \ No newline at end of file diff --git a/01/crawler/main.py b/01/crawler/main.py index c9e3d77..fd529a3 100644 --- a/01/crawler/main.py +++ b/01/crawler/main.py @@ -8,5 +8,9 @@ from urllib2 import urlopen # Python 2 -rsp = urlopen('http://ip.sxisa.com/') -print(rsp.read()) \ No newline at end of file +def ip(): + rsp = urlopen('http://ip.sxisa.com/') + return rsp.read() + +if __name__ == '__main__': + print(ip()) \ No newline at end of file diff --git a/01/crawler/node/app.js b/01/crawler/node/app.js new file mode 100644 index 0000000..5849a0e --- /dev/null +++ b/01/crawler/node/app.js @@ -0,0 +1,15 @@ +#!/usr/bin/env node +const request = require('request'); + +function ip(callback) { + request('http://ip.sxisa.com/', (err, rsp, body) => { + if (err) throw (err) + if (callback) callback(body) + }) +} + +module.exports = ip; + +if (require.main === module) { + ip(console.log); +} \ No newline at end of file diff --git a/01/crawler/node/package.json b/01/crawler/node/package.json new file mode 100644 index 0000000..48dd2a5 --- /dev/null +++ b/01/crawler/node/package.json @@ -0,0 +1,14 @@ +{ + "name": "crawler", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "start": "node ./app.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "request": "^2.85.0" + } +}