-
-
Save amicalmant/5f732713476daeaaa6155fc8917a73fd to your computer and use it in GitHub Desktop.
Migrate Links From Standard And Branded Bit.LY To Your YOURLS Install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
#Simple script for importing data from bitly to yourls using bitly and yourls API. | |
#authored by: Piotr Krzyzek - https://piotrkrzyzek.com | |
#https://gist.github.com/PiotrKrzyzek/9d26c24c1d015c7c64e3ca79b3cb3ea1 | |
#You must define variables 'yourls_host', 'bitly_token' and 'yourls_signature' | |
#as appropriate (see tutorial here: https://piotrkrzyzek.com/migrate-from-bitly-to-yourls/) | |
import urllib2, json, urllib | |
#Add the following data | |
yourls_host = 'your-domain-where-yours-is-installed.com' | |
bitly_token = 'your-bitly-token' | |
yourls_signature = 'your-yourls-signature-key' | |
def pushto_yourls_api(data): | |
url_dest = 'http://'+yourls_host+'/yourls-api.php' | |
for x in data['data']['link_history']: | |
link = x['link'].split('/')[3] | |
long_url = x['long_url'] | |
values = dict(action='shorturl', url = unicode(long_url).encode('utf-8'), keyword = link , signature=yourls_signature) | |
req_data = urllib.urlencode(values) | |
req = urllib2.Request(url_dest, req_data) | |
rsp = urllib2.urlopen(req) | |
content = rsp.read() | |
print content | |
origen_url = 'https://api-ssl.bitly.com/v3/user/link_history?format=json&access_token='+bitly_token+'&limit=50' | |
bitly_result = True | |
offset = 0 | |
while bitly_result: | |
url = origen_url + '&offset=' + str(offset) | |
print url | |
response = urllib.urlopen(url) | |
data = json.loads(response.read()) | |
if len(data['data']['link_history']) < 50: | |
bitly_result = False | |
offset +=50 | |
pushto_yourls_api(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
#Simple script for importing data customized links only from | |
#a bitly branded domain to yourls using bitly and yourls API. | |
#Modified by Christian Aubry - http://christian.aubry.org | |
#If you want to get both your custom links *and* generic | |
#bitly short urls in your yourls database, you must first | |
#make this possible in your user/config.php file. To do so, | |
#edit line 49 (YOURLS v1.7.2) as follows: | |
# | |
#define( 'YOURLS_UNIQUE_URLS', false ); | |
# | |
#Then apply this script *after* applying the original script. | |
import urllib2, json, urllib | |
#Add the following data | |
yourls_host = 'your-domain-where-yours-is-installed.com' | |
bitly_token = 'your-bitly-token' | |
yourls_signature = 'your-yourls-signature-key' | |
def pushto_yourls_api(data): | |
url_dest = 'http://'+yourls_host+'/yourls-api.php' | |
for x in data['data']['link_history']: | |
link = x['keyword_link'].split('/')[3] | |
long_url = x['long_url'] | |
values = dict(action='shorturl', url = unicode(long_url).encode('utf-8'), keyword = link , signature=yourls_signature) | |
req_data = urllib.urlencode(values) | |
req = urllib2.Request(url_dest, req_data) | |
rsp = urllib2.urlopen(req) | |
content = rsp.read() | |
print content | |
origen_url = 'https://api-ssl.bitly.com/v3/user/link_history?format=json&access_token='+bitly_token+'&limit=50'+'&custom_bitlink=on&filterActive=true' | |
bitly_result = True | |
offset = 0 | |
while bitly_result: | |
url = origen_url + '&offset=' + str(offset) | |
print url | |
response = urllib.urlopen(url); | |
data = json.loads(response.read()) | |
if len(data['data']['link_history']) < 50: | |
bitly_result = False | |
offset +=50 | |
pushto_yourls_api(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment