From 383b55cac63aa44f0c88e278b29e4ed252067191 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Mon, 7 Apr 2014 15:56:26 -0400 Subject: [PATCH] Move from bitly over to da.gd. It is free software. --- bugwarrior/README.rst | 3 +++ bugwarrior/db.py | 15 ++++++--------- bugwarrior/services/__init__.py | 27 +++++++++------------------ setup.py | 1 - 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/bugwarrior/README.rst b/bugwarrior/README.rst index 8058a3f5a..73e769b41 100644 --- a/bugwarrior/README.rst +++ b/bugwarrior/README.rst @@ -61,6 +61,9 @@ Create a ``~/.bugwarriorrc`` file with the following contents. # If unspecified, the default taskwarrior config will be used. #taskrc = /path/to/.taskrc + # Setting this to true will shorten links with http://da.gd/ + #shorten = False + # Defines whether or not issues should be matched based upon their description. # For historical reasons, and by default, we will attempt to match issues # based upon the presence of the '(bw)' marker in the task description. diff --git a/bugwarrior/db.py b/bugwarrior/db.py index 064721cf3..41b2420da 100644 --- a/bugwarrior/db.py +++ b/bugwarrior/db.py @@ -5,7 +5,7 @@ import warnings import subprocess -import bitlyapi +import requests import dogpile.cache import six from twiggy import log @@ -19,7 +19,7 @@ MARKUP = "(bw)" -DOGPILE_CACHE_PATH = os.path.expanduser('~/.cache/bitly.dbm') +DOGPILE_CACHE_PATH = os.path.expanduser('~/.cache/dagd.dbm') if not os.path.isdir(os.path.dirname(DOGPILE_CACHE_PATH)): os.mkdirs(os.path.dirname(DOGPILE_CACHE_PATH)) CACHE_REGION = dogpile.cache.make_region().configure( @@ -42,15 +42,12 @@ def __new__(cls, *args, **kwargs): ) return cls._instance - def __init__(self, bitly_user, bitly_key): - self.bitly_user = bitly_user - self.bitly_key = bitly_key - - self.bitly = bitlyapi.BitLy(bitly_user, bitly_key) - @CACHE_REGION.cache_on_arguments() def shorten(self, url): - return self.bitly.shorten(longUrl=url)['url'] + if not url: + return '' + base = 'http://da.gd/s' + return requests.get(base, params=dict(url=url)).text.strip() class NotFound(Exception): diff --git a/bugwarrior/services/__init__.py b/bugwarrior/services/__init__.py index 4e5a46308..047792093 100644 --- a/bugwarrior/services/__init__.py +++ b/bugwarrior/services/__init__.py @@ -7,6 +7,7 @@ import six from twiggy import log +from bugwarrior.config import asbool from bugwarrior.db import MARKUP, URLShortener, ABORT_PROCESSING @@ -34,13 +35,9 @@ def __init__(self, config, target): if config.has_option('general', 'annotation_length'): self.anno_len = self.config.getint('general', 'annotation_length') - self.bitly_api_user = None - if config.has_option('general', 'bitly.api_user'): - self.bitly_api_user = config.get('general', 'bitly.api_user') - - self.bitly_api_key = None - if config.has_option('general', 'bitly.api_key'): - self.bitly_api_key = config.get('general', 'bitly.api_key') + self.shorten = False + if config.has_option('general', 'shorten'): + self.shorten = asbool(config.get('general', 'shorten')) self.description_template = None if config.has_option(self.target, 'description_template'): @@ -89,8 +86,7 @@ def get_issue_for_record(self, record, extra=None): 'description_length': self.desc_len, 'description_template': self.description_template, 'target': self.target, - 'bitly_api_key': self.bitly_api_key, - 'bitly_api_user': self.bitly_api_user, + 'shorten': self.shorten, 'add_tags': self.add_tags, } origin.update(self.get_service_metadata()) @@ -247,20 +243,15 @@ def get_priority(self): def get_processed_url(self, url): """ Returns a URL with conditional processing. - If the following config keys are set: + If the following config key are set: - - [general]bitly.api_user - - [general]bitly.api_key + - [general]shorten returns a shortened URL; otherwise returns the URL unaltered. """ - if (self.origin['bitly_api_user'] and self.origin['bitly_api_key']): - shortener = URLShortener( - self.origin['bitly_api_user'], - self.origin['bitly_api_key'], - ) - return shortener.shorten(url) + if self.origin['shorten']: + return URLShortener().shorten(url) return url def parse_date(self, date): diff --git a/setup.py b/setup.py index 44fba74a6..74400380e 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,6 @@ "six", "jinja2>=2.7.2", "pycurl", - "bitlyapi>=0.1.1", "dogpile.cache>=0.5.3", ], tests_require=[