Skip to content

Conversation

@fake-name
Copy link
Contributor

@fake-name fake-name commented May 11, 2018

Principally, this fixes #26.

It also adds some simple logging (at the path "Main.LinkUnshortener"), and also imports the two exceptions into the __init__.py file. This makes it much nicer to use, since you no longer need two separate imports if you want to catch exceptions.

You can now do:

import unshortenit

try:
    itemurl = unshortenit.UnshortenIt().unshorten(itemurl)
except (unshortenit.NotFound, unshortenit.UnshortenFailed):
	itemurl = None

@fake-name
Copy link
Contributor Author

Note that I generally have fairly verbose logging, and it might be worth replacing all the log.info calls with log.debug, if you prefer the library to be more silent.

@fake-name
Copy link
Contributor Author

fake-name commented May 11, 2018

Additional stupid junk: You can now provide a dict-like object to the UnshortenIt() instance, and it will then use that to allow you to provide already-resolved urls.

This was done for my use case where I have some inputs that consume RSS feeds, and the RSS feeds contain shortened links.

Due to the nature of RSS, I see the same posts fairly repeatedly, and waiting for them to resolve again, and again, and again..... This way, I can provide a custom dict-like object that saves the seen URLs in a database.

The end result is a feed where I previously took > 5 minutes to process the contained links now takes ~5 seconds.

I don't know why the pypy test is failing. It works in my local pypy3 install. Are the tests accidentally using pypy2?

Push the caching up one layer so it's much more sensibly located.
Add a flag that lets you forcibly ignore the cache entirely.
… modified.

Instead, only do the cache query if we think we need to actually modify the link.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behaviour of UnshortenIt() object and the unshorten() call in the documentation is wrong

1 participant