Skip to content

Commit

Permalink
Move from bitly over to da.gd. It is free software.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Apr 7, 2014
1 parent 44421dc commit 383b55c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
3 changes: 3 additions & 0 deletions bugwarrior/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 6 additions & 9 deletions bugwarrior/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings
import subprocess

import bitlyapi
import requests
import dogpile.cache
import six
from twiggy import log
Expand All @@ -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(
Expand All @@ -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):
Expand Down
27 changes: 9 additions & 18 deletions bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import six
from twiggy import log

from bugwarrior.config import asbool
from bugwarrior.db import MARKUP, URLShortener, ABORT_PROCESSING


Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"six",
"jinja2>=2.7.2",
"pycurl",
"bitlyapi>=0.1.1",
"dogpile.cache>=0.5.3",
],
tests_require=[
Expand Down

0 comments on commit 383b55c

Please sign in to comment.