From 43c17d62ce2f4ac6010316ff036842dc25aaba4a Mon Sep 17 00:00:00 2001 From: kaliko Date: Sun, 26 Jan 2014 19:11:18 +0100 Subject: [PATCH] Plain api keys obfuscation --- sima/__init__.py | 12 +++++++++++- sima/lib/simafm.py | 19 ++++++++++--------- sima/utils/utils.py | 15 ++++++++++++++- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/sima/__init__.py b/sima/__init__.py index f78f634..d9d4fd5 100644 --- a/sima/__init__.py +++ b/sima/__init__.py @@ -1,4 +1,14 @@ # -*- coding: utf-8 -*- -# VIM MODLINE +LFM = {'apikey': 'NG4xcDlxcXJwMjk4MTZycTgwM3E3b3I5MTEzb240cG8', + 'host':'ws.audioscrobbler.com', + 'version': '2.0', + } + +ECH = {'apikey': 'WlRKQkhTS0JHWFVDUEZZRFA', + 'host': 'developer.echonest.com', + 'version': 'v4', + } + + # vim: ai ts=4 sw=4 sts=4 expandtab diff --git a/sima/lib/simafm.py b/sima/lib/simafm.py index 12ca0d5..d29817e 100644 --- a/sima/lib/simafm.py +++ b/sima/lib/simafm.py @@ -23,7 +23,7 @@ Consume last.fm web service """ -__version__ = '0.3.0' +__version__ = '0.3.1' __author__ = 'Jack Kaliko' @@ -35,6 +35,10 @@ from socket import timeout as SocketTimeOut from time import sleep from xml.etree.cElementTree import ElementTree +from sima import LFM +from sima.utils.utils import getws +getws(LFM) + # Some definitions WAIT_BETWEEN_REQUESTS = timedelta(0, 0.4) LFM_ERRORS = dict({'2': 'Invalid service -This service does not exist', @@ -138,18 +142,15 @@ class AudioScrobblerCache(): class SimaFM(): """ """ - api_key = '4a1c9ddec29816ed803d7be9113ba4cb' - host = 'ws.audioscrobbler.com' - version = '2.0' - root_url = 'http://%s/%s/' % (host, version) + root_url = 'http://{host}/{version}/'.format(**LFM) request = dict({'similar': '?method=artist.getsimilar&artist=%s&' +\ - 'api_key=%s' % api_key, + 'api_key={apikey}'.format(**LFM), 'top': '?method=artist.gettoptracks&artist=%s&' +\ - 'api_key=%s' % api_key, + 'api_key={apikey}'.format(**LFM), 'track': '?method=track.getsimilar&artist=%s' +\ - '&track=%s' + '&api_key=%s' % api_key, + '&track=%s' + 'api_key={apikey}'.format(**LFM), 'info': '?method=artist.getinfo&artist=%s' +\ - '&api_key=%s' % api_key, + 'api_key={apikey}'.format(**LFM), }) cache = dict({}) timestamp = datetime.utcnow() diff --git a/sima/utils/utils.py b/sima/utils/utils.py index 07c317f..a75effd 100644 --- a/sima/utils/utils.py +++ b/sima/utils/utils.py @@ -18,16 +18,29 @@ # along with sima. If not, see . # # -"""generic tools and utilitaries for sima +"""generic tools and utilities for sima """ import traceback import sys from argparse import ArgumentError, Action +from base64 import b64decode as push +from codecs import getencoder from os import environ, access, getcwd, W_OK, R_OK from os.path import dirname, isabs, join, normpath, exists, isdir, isfile + +def getws(dic): + """ + Decode Obfuscated api key. + Only preventing API keys harvesting over the network + https://developer.echonest.com/forums/thread/105 + """ + aka = push(bytes(dic.get('apikey') + '=', 'utf-8')) + aka = getencoder('rot-13')(str((aka), 'utf-8'))[0] + dic.update({'apikey':aka}) + def get_mpd_environ(): """ Retrieve MPD env. var. -- 2.39.5