Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Feb 24, 2013
0 parents commit b0ab11b
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,3 @@
0.0.1 / 2013-02-23
------------------
* Initial release.
15 changes: 15 additions & 0 deletions LICENSE
@@ -0,0 +1,15 @@
(The MIT License)

Copyright (c) 2013, JP Richardson <jprichardson@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
@@ -0,0 +1,33 @@
Node.js - sky-tumblr-export
================

Type description here...


Why?
----



Installation
------------

npm install sky-tumblr-export



Example
------


```javascript
```

License
-------

(MIT License)

Copyright 2013, JP Richardson <jprichardson@gmail.com>


123 changes: 123 additions & 0 deletions bin/sky-tumblr-export
@@ -0,0 +1,123 @@
#!/usr/bin/env node

var program = require('commander')
, colors = require('colors')
, path = require('path')
, pandoc = require('pdc')
, request = require('request')
, S = require('string')
, fs = require('fs-extra')
, cl = require('cl')
, batch = require('batchflow')

var DEFAULT_API_KEY = "fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4"
, URL = "http://api.tumblr.com/v2/blog/{{url}}/{{resource}}?api_key={{api_key}}"

program
.version(require('../package.json').version)
.option('-u, --url [url]', 'REQUIRED. The url of the Tumblr blog.')
.option('-d, --dir <dir>', 'The directory to dump the files. Default is the current directory.', process.cwd())
.option('--api-key <apikey>', 'The API key. Optional.', DEFAULT_API_KEY)
.parse(process.argv);

if (!program.url) return program.outputHelp();

URL = S(URL).template({url: program.url, api_key: program.apiKey}).s

function main () {
console.log('Fetching articles...')

function fetchBlogInfo () {
var url = S(URL).template({resource: 'info'}).s
request({url: url, json: true}, function(err, resp, body) {
if (err || resp.statusCode !== 200) cl.exit(100, err)
outputSkyConfig(body.response)
})
}

function outputSkyConfig (blogInfo) {
if (!blogInfo || !blogInfo.blog) cl.exit(101, "Could not get blog info.")
blogInfo = blogInfo.blog

var skyConfig = {
blog: {},
articles: {urlformat: '{{slug}}',
index: 'index.html'},
build: {outputDir: 'public/'},
partials: {}
}

skyConfig.blog.name = blogInfo.name || 'BLOG NAME'
skyConfig.blog.url = blogInfo.url || program.url
skyConfig.blog.tagline = blogInfo.description || 'DESCRIPTION'

var configFile = path.join(program.dir, 'sky', 'config.json')
fs.outputFileSync(configFile, JSON.stringify(skyConfig, null, 2))

fetchArticles(blogInfo.posts)
}

function fetchArticles (postCount) {
var offset = 0
, limit = 20 //max as defined by API
, steps = postCount / limit

//is there a rem?
steps = postCount % limit === 0 ? steps : Math.floor(steps) + 1

URL = URL + '&offset={{offset}}&limit={{limit}}'
URL = S(URL).template({resource: 'posts', limit: limit}).s //limit doesn't change
function fetchIt (i) {
//console.log(offset)
var url = S(URL).template({offset: offset.toString()}).s
console.log(url)


offset += limit
if (i < steps)
fetchIt(i + 1)
else
done()
}
fetchIt(1)

}

function done () {
console.log('Done')
}

fetchBlogInfo()
}

//main()

var u = "http://api.tumblr.com/v2/blog/techneur.tumblr.com/posts?api_key=fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4&offset=0&limit=20"
request({url: u, json: true}, function(err, resp, body) {
iterateArticles(u, body.response, function() {
console.log('done')
})
}


function iterateArticles (url, data, callback) {
if (!data || !data.posts) cl.exit(102, "Got a bad response from %s", url)
var articles = data.posts

batch(articles).par()
.each(function(i, article, next) {

})
.error(function(err) {
console.error(err)
})
.end(function() {
callback()
})
}

function logArticle (title, date) {
var text = colors.cyan(S('Got').padLeft(10)) + ' : ' + colors.green('[' + S(date.toDateString()).padRight(12) + '] ') + title
console.log(text)
}

Empty file added lib/sky-tumblr-export.js
Empty file.
47 changes: 47 additions & 0 deletions package.json
@@ -0,0 +1,47 @@
{
"name": "sky-tumblr-export",
"version": "0.0.1",
"description": "Export your Tumblr blog into Markdown. Use it with Sky if you like.",
"homepage": [
""
],
"repository": {
"type": "git",
"url": ""
},
"keywords": [
"tumblr",
"markdown",
"export",
"dump",
"sky",
"blog",
"static"
],
"author": "JP Richardson <jprichardson@gmail.com>",
"licenses": [
{
"type": "MIT",
"url": ""
}
],
"dependencies": {
"commander": "~1.1.1",
"pdc": "~0.1.1",
"request": "~2.14.0",
"colors": "~0.6.0-1",
"string": "~1.2.1",
"fs-extra": "~0.5.0",
"cl": "0.0.1",
"batchflow": "~0.3.2",
"markdown-page": "~0.1.1"
},
"devDependencies": {},
"scripts": {
"test": "mocha test"
},
"bin": {
"potter-wordpress": "./bin/sky-tumblr-export"
},
"preferGlobal": true
}
17 changes: 17 additions & 0 deletions test/mocha.opts
@@ -0,0 +1,17 @@

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>503 Connection timed out</title>
</head>
<body>
<h1>Error 503 Connection timed out</h1>
<p>Connection timed out</p>
<h3>Guru Meditation:</h3>
<p>XID: 2981449970</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
Empty file added test/resources/.gitkeep
Empty file.
Empty file added test/sky-tumblr-export.test.js
Empty file.

0 comments on commit b0ab11b

Please sign in to comment.