<commit_before>#!/bin/python
# -*- coding: utf-8 -*-

"""
The JSON API allows to do queries on the whole database of BGP Ranking
via the Web interface.

By default, the path where the webservice is listening is
http://domain/json

You need to send a well-formed JSON object with a entry 'method' and as
value the name of the function you want to call (listed bellow).

The other entries of the JSON Object will depend on the function. To keep
it simple, the name of each entry is the parameter name from the Redis API.

The default parameters are as consistent as possible with the one of the
Redis API (:class:`bgpranking.api`)

"""


from flask import Flask, json, request
import StringIO
import csv

import bgpranking


logging = True
try:
    if logging:
            from pubsublogger import publisher
            publisher.channel = 'API_Web'
except:
    logging = False


app = Flask(__name__)
app.debug = True

authorized_methods = ['all_ranks_single_asn', 'all_ranks_all_asns',
        'block_descriptions', 'asn_description', 'ips_description',
        'stats', 'cached_dates', 'cached_daily_rank', 'cached_top_asns',
        'ip_lookup']

class SetEncoder(json.JSONEncoder):
    def default(self, obj):
        if type(obj) == type(set()):
            return list(obj)
        return json.JSONEncoder.default(self, obj)

def __default_dates_sources(req):
    dates_sources = req.get('dates_sources')
    if dates_sources is None:<commit_msg>prepare bgpranking webservice to use the PyPi package<commit_after>#!/bin/python
# -*- coding: utf-8 -*-

"""
The JSON API allows to do queries on the whole database of BGP Ranking
via the Web interface.

By default, the path where the webservice is listening is
http://domain/json

You need to send a well-formed JSON object with a entry 'method' and as
value the name of the function you want to call (listed bellow).

The other entries of the JSON Object will depend on the function. To keep
it simple, the name of each entry is the parameter name from the Redis API.

The default parameters are as consistent as possible with the one of the
Redis API (:class:`bgpranking.api`)

"""


from flask import Flask, json, request
import StringIO
import csv

import bgpranking.redis as bgpranking
bgpranking.asnhistory.redis_host='127.0.0.1'
bgpranking.asnhistory.redis_port=6389
bgpranking.ipasn.hostname='127.0.0.1'
bgpranking.ipasn.port=6390
bgpranking.ptr_host='127.0.0.1'
bgpranking.ptr_port=8323

logging = True
try:
    if logging:
            from pubsublogger import publisher
            publisher.channel = 'API_Web'
except:
    logging = False


app = Flask(__name__)
app.debug = True

authorized_methods = ['all_ranks_single_asn', 'all_ranks_all_asns',
        'block_descriptions', 'asn_description', 'ips_description',
        'stats', 'cached_dates', 'cached_daily_rank', 'cached_top_asns',
        'ip_lookup']

class SetEncoder(json.JSONEncoder):
    def default(self, obj):
        if type(obj) == type(set()):
            return list(obj)
        return json.JSONEncoder.default(self, obj)

def __default_dates_sources(req):
    dates_sources = req.get('dates_sources')
    if dates_sources is None:
{'fraction_non_alphanumeric': 0.08970309538850284, 'fraction_numerical': 0.01010739102969046, 'mean_word_length': 3.8203957382039575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5432916', 'n_tokens_mistral': 992, 'n_tokens_neox': 959, 'n_words': 344}