PyJSONProxy

simple proxy and scraper
git clone https://git.ce9e.org/PyJSONProxy.git

commit
826fca0491ac3df3d3315c79811a05814ab1ec39
parent
e4ec571ed9fa190ae3487e4067d7e42a45f460e2
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2015-12-03 23:36
explicit type no longer needed

Diffstat

M README.rst 2 --
M example.cfg 1 -
M jsonproxy/__init__.py 12 +++---------
M jsonproxy/api.py 4 +---
M jsonproxy/templates/index.html 2 +-

5 files changed, 5 insertions, 16 deletions


diff --git a/README.rst b/README.rst

@@ -48,7 +48,6 @@ HTML pages, PyJSONProxy can extract information from there::
   48    48     ENDPOINTS = {
   49    49         'github': {
   50    50             'host': 'https://github.com/',
   51    -1             'type': 'scrape',
   52    51             'fields': {
   53    52                 'login': '.vcard-username',
   54    53                 'fullname': '.vcard-fullname',
@@ -93,7 +92,6 @@ description to both endpoints and fields::
   93    92     ENDPOINTS = {
   94    93         'github': {
   95    94             'host': 'https://github.com/',
   96    -1             'type': 'scrape',
   97    95             'doc': 'Access data about GitHub users',
   98    96             'fields': {
   99    97               'login': '.vcard-username',

diff --git a/example.cfg b/example.cfg

@@ -4,7 +4,6 @@ ENDPOINTS = {
    4     4 	},
    5     5 	'user': {
    6     6 		'host': 'https://github.com/',
    7    -1 		'type': 'scrape',
    8     7 		'fields': {
    9     8 			'login': '.vcard-username',
   10     9 			'fullname': '.vcard-fullname',

diff --git a/jsonproxy/__init__.py b/jsonproxy/__init__.py

@@ -8,7 +8,6 @@ from flask import Flask
    8     8 
    9     9 from .api import api
   10    10 
   11    -1 TYPES = ['proxy', 'scrape']
   12    11 ENDPOINTS = 'ENDPOINTS'
   13    12 
   14    13 
@@ -31,14 +30,9 @@ def check_config(config):
   31    30 		errors.append('No endpoints configured.')
   32    31 	else:
   33    32 		for key, data in config[ENDPOINTS].items():
   34    -1 			_type = data.get('type', 'proxy')
   35    -1 			if _type not in TYPES:
   36    -1 				errors.append('Unknown endpoint type %s for endpoint %s. '
   37    -1 					'Choose one of %s.' % (_type, key, ', '.join(TYPES)))
   38    -1 			elif _type == 'scrape':
   39    -1 				if 'fields' not in data or len(data['fields']) == 0:
   40    -1 					errors.append('No fields configured for endpoint %s of type %s.' %
   41    -1 						(key, _type))
   -1    33 			if 'fields' in data:
   -1    34 				if len(data['fields']) == 0:
   -1    35 					errors.append('No fields configured for endpoint %s.' % key)
   42    36 				else:
   43    37 					errors += list(check_fields_config(data['fields'], key))
   44    38 

diff --git a/jsonproxy/api.py b/jsonproxy/api.py

@@ -88,9 +88,8 @@ def main(endpoint, path):
   88    88 		abort(404)
   89    89 
   90    90 	url = request.url.replace(request.host_url + endpoint + '/', config['host'])
   91    -1 	_type = config.get('type', 'proxy')
   92    91 
   93    -1 	if _type == 'scrape':
   -1    92 	if 'fields' in config:
   94    93 		response = scrape(url, config)
   95    94 	else:
   96    95 		response = proxy(url, config)
@@ -115,7 +114,6 @@ def _doc(endpoint):
  115   114 	data = {
  116   115 		'title': endpoint,
  117   116 		'doc': config.get('doc', ''),
  118    -1 		'type': config.get('type', 'proxy'),
  119   117 		'fields': list(_fields_doc(config)),
  120   118 	}
  121   119 

diff --git a/jsonproxy/templates/index.html b/jsonproxy/templates/index.html

@@ -7,7 +7,7 @@
    7     7 	<body>
    8     8 		{% for endpoint in endpoints %}
    9     9 		<section>
   10    -1 			<h2>{{ endpoint.title }} ({{ endpoint.type }})</h2>
   -1    10 			<h2>{{ endpoint.title }}</h2>
   11    11 			<p>{{ endpoint.doc }}</p>
   12    12 			{% if endpoint.fields %}
   13    13 			<dl>