Files
mehl.mx/content/blog/2015-01-yourls-url-shortener-for-turpial.md

63 lines
3.3 KiB
Markdown
Raw Normal View History

2019-10-17 14:34:23 +02:00
---
title: Yourls URL Shortener for Turpial
date: 2015-01-24T01:58:32+00:00
2019-10-18 19:10:14 +02:00
aliases: yourls-url-shortener-for-turpial
2019-10-17 14:34:23 +02:00
categories:
- blog
2019-10-19 19:12:42 +02:00
- english
2019-10-17 14:34:23 +02:00
tags:
- chat
- server
---
Maybe you know [Yourls][1], a pretty cool URL shortener which you can set up on your own server very easily. Link shorteners are nice to have because
1. you can share long links with short urls and
2. you can view and organise all links you ever shared (incl. statistics and so on).
2019-10-18 23:53:42 +02:00
There are many alternatives like bit.ly, ur1.ca and so on, but Yourls belongs to YOU and you dont have to pay attention to ToS changes or the providers financial status. AND you can use whichever domain you own, for example in my case its *s.mehl.mx/blabla*.
2019-10-17 14:34:23 +02:00
2019-10-18 19:26:55 +02:00
And maybe you also know [Turpial][2], a Twitter client for GNU/Linux systems (I dont like Twitters web page). Until lately I used Choqok, a KDE optimised client, but there were many things which annoyed me: No image previews, slow development, unconvenient reply behaviour and so on. And hey, why not trying something new? So I started to use Turpial which seems to solve all these critic points. Well, like always I missed some preferences to configure. But since its [Free Software][3], one is able to look how the software works and to change it and to share the improvements which Ill do in the next step!
2019-10-17 14:34:23 +02:00
2019-10-18 23:53:42 +02:00
Turpial already offers some link shorteners but not Yourls. But we can add it manually. To do so, open the file `/usr/lib/python2.7/dist-packages/libturpial/lib/services/url/shortypython/shorty.py` as root. Now add the following somewhere between the already existing shorteners
2019-10-17 14:34:23 +02:00
2019-10-18 23:53:42 +02:00
```py
# Yourls
class Yourls(Service):
def shrink(self, bigurl):
resp = request('http://YOUR_DOMAIN/yourls-api.php', {'action': 'shorturl', 'format': 'xml', 'url': bigurl, 'signature': 'YOUR_SIGNATURE'})
returned_data = resp.read()
matched_re = re.search('(http://YOUR_DOMAIN/[^"]+)', returned_data)
if matched_re:
return matched_re.group(1)
else:
raise ShortyError('Failed to shrink url')
yourls = Yourls()
2019-10-18 23:53:42 +02:00
```
2019-10-17 14:34:23 +02:00
2019-10-18 23:53:42 +02:00
Just replace `YOUR_DOMAIN` and `YOUR_SIGNATURE` accordingly. The usage of a signature enables you to hide your username and password when sending the shorten requests, like an API key and looks like `f51qw35w6` ([more about passwordlessAPI][4]). You can retrieve your signature on your Yourls Admin page via *Tools*.
2019-10-17 14:34:23 +02:00
2019-10-18 23:53:42 +02:00
Then add the new service to the list of shorteners. In the same file search for `services = {` (on the bottom) and add somewhere in the following list:
2019-10-17 14:34:23 +02:00
2019-10-18 23:53:42 +02:00
```py
'yourls-instance': yourls,
```
2019-10-17 14:34:23 +02:00
2019-10-18 23:53:42 +02:00
Well, then just restart Turpial, go to Preferences > Services and choose *yourls-instance* from the list of Short URL services. Congrats, you should be able to short your URLs with Yourls in Turpial now :)
2019-10-17 14:34:23 +02:00
Any problems or improvements? Drop me a message!
2019-10-18 23:53:42 +02:00
---
**Notes:**
2019-10-17 14:34:23 +02:00
2019-10-18 23:53:42 +02:00
* For me, only hardcoding the signature worked but not the prompt for these data like in some other services stated in the file
* Another file worth your attention might be `/usr/lib/python2.7/dist-packages/turpial/ui/qt/templates/style.css`. There you can change colors, fonts and so on. For example, the *Ubuntu* font wasnt installed on my system so I just chose Sans Serif instead.
2019-10-17 14:34:23 +02:00
2019-10-18 23:53:42 +02:00
[1]: http://yourls.org/
[2]: http://turpial.org.ve/
[3]: https://fsfe.org/about/basics/freesoftware.html
[4]: https://github.com/YOURLS/YOURLS/wiki/PasswordlessAPI