remove unused metaremote

This commit is contained in:
j 2016-04-02 16:03:16 +02:00
parent a172e7b4b7
commit 55c1388e72
3 changed files with 0 additions and 127 deletions

View file

@ -26,7 +26,6 @@ from utils import remove_empty_folders, get_ratio
from websocket import trigger_event
import db
import media
#import metaremote as meta
import meta
import settings
import state

View file

@ -1,37 +0,0 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import json
from urllib.parse import urlencode
from ox.cache import read_url
import settings
import logging
logger = logging.getLogger(__name__)
def request(action, data):
data = urlencode({
'action': action,
'data': json.dumps(data)
})
url = 'http://meta.openmedialibrary.com/api/'
try:
return json.loads(read_url(url, data, timeout=60).decode('utf-8'))['data']
except:
logger.debug('metadata request failed', exc_info=True)
return {}
def find(query):
logger.debug('find %s', query)
return request('findMetadata', {'query': query}).get('items', [])
def lookup(key, value):
logger.debug('lookup %s %s', key, value)
data = request('getMetadata', {key: value})
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
if key in data and not isinstance(data[key], list):
data[key] = [data[key]]
return data

View file

@ -1,89 +0,0 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from tornado.web import Application
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
import oxtornado
from oxtornado import actions
import meta
import utils
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
def findMetadata(data):
'''
takes {
query: string,
}
returns {
items: [{
key: value
}]
}
key is one of the supported identifiers: isbn, olid...
'''
response = {}
logger.debug('findMetadata %s', data)
response['items'] = meta.find(data['query'])
return response
actions.register(findMetadata)
def getMetadata(data):
'''
takes {
key: value
includeEdits: boolean
}
key can be one of the supported identifiers: isbn, oclc, olid,...
'''
logger.debug('getMetadata %s', data)
if 'includeEdits' in data:
include_edits = data.pop('includeEdits')
else:
include_edits = False
key, value = next(iter(data.items()))
if key == 'isbn':
value = utils.normalize_isbn(value)
logger.debug('getMetadata key=%s value=%s', key, value)
response = meta.lookup(key, value)
if response:
response['primaryid'] = [key, value]
return response
actions.register(getMetadata)
def run():
options = {
'debug': True
}
handlers = [
(r'/api/', oxtornado.ApiHandler),
]
http_server = HTTPServer(Application(handlers, **options))
port = 9855
address = ''
http_server.listen(port, '')
main = IOLoop.instance()
if ':' in address:
host = '[%s]' % address
elif not address:
host = '[::1]'
else:
host = address
url = 'http://%s:%s/' % (host, port)
print(url)
main.start()
if __name__ == '__main__':
run()