Skip to content

Instantly share code, notes, and snippets.

@yoo2001818
Forked from tnraro/shortly.js
Last active August 29, 2015 14:20
Show Gist options
  • Save yoo2001818/1b213c7c31cfdb943e3f to your computer and use it in GitHub Desktop.
Save yoo2001818/1b213c7c31cfdb943e3f to your computer and use it in GitHub Desktop.
var plugin = {
name: 'shortly.me',
name_ko: '나를 짧게',
name_jp: '私を短く',
author: 'admin@tnraro.com',
version: '0.1.0',
description: '나를 짧게 해줍니다.',
alias: ['짧게'],
depends: ['Command'],
init: init,
destroy: destroy
}
var config = {
host: "http://shortly.me/shorten?url="
};
var request, async;
try{
request = require('request');
async = require('async');
}catch(e){
console.error('plz try "npm install ."');
throw "Node modules not found";
}
function init(bot, callback){
console.log('hi');
bot.registerCommand('shortly', plugin.description, '<url>', cmd, 0, plugin.alias);
callback();
}
function cmd(bot, message, command, args){
args.shift();
var parallel = [];
args.forEach(function(url, i){
if(url.match(/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?$/) !== null){
parallel.push(function(callback){
if(url.match(/^(https?:\/\/)/) === null){
url = 'http://' + url;
}
request(config.host + encodeURIComponent(url), function(err, res, body){
if(!err && res.statusCode === 200){
bot.session.sendText(message.chatRoom, body);
}
});
});
}
});
async.parallel(parallel, function(err, results){
if(err){
console.error(err);
throw err;
}
console.log(results);
});
}
function destroy(bot, callback){
console.log('hi');
bot.unregisterCommand('shortly');
callback();
}
from urllib.parse import quote
from urllib.request import urlopen
import sys
argv = sys.argv[1:]
host = "http://shortly.me/shorten?url="
for url in argv:
after = urlopen(host+quote(url)).read().decode('utf-8')
print("\""+url+"\" -> "+after)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment