Esempio n. 1
0
import nixie
import sys


class ReadFileHTTPRequestHandler(nixie.NixieHTTPRequestHandler):
    def get_data(self):
        path = ' '.join(sys.argv[1:])
        with open(path, 'r') as file:
            return int(file.read().replace('\n', ''))


nixie.serve(ReadFileHTTPRequestHandler)
Esempio n. 2
0
import nixie
import random


class RandomHTTPRequestHandler(nixie.NixieHTTPRequestHandler):
    def get_data(self):
        return random.randint(0, 999999)


nixie.serve(RandomHTTPRequestHandler)
Esempio n. 3
0
        # Comments
        text = re.sub(r'<!--(.*?)-->', '', text, flags=re.MULTILINE)
        # Tabs to spaces
        text = text.replace('\t', '    ')
        # More than 1 space to 4 spaces
        text = re.sub(r'[ ]{2,}', '    ', text)
        # Footnotes
        text = re.sub(r'^\[[^]]*\][^(].*', '', text, flags=re.MULTILINE)
        # Indented blocks of code
        text = re.sub(r'^( {4,}[^-*]).*', '', text, flags=re.MULTILINE)
        # Custom header IDs
        text = re.sub(r'{#.*}', '', text)
        # Replace newlines with spaces for uniform handling
        text = text.replace('\n', ' ')
        # Remove images
        text = re.sub(r'!\[[^\]]*\]\([^)]*\)', '', text)
        # Remove HTML tags
        text = re.sub(r'</?[^>]*>', '', text)
        # Remove special characters
        text = re.sub(r'[#*`~\-–^=<>+|/:]', '', text)
        # Remove footnote references
        text = re.sub(r'\[[0-9]*\]', '', text)
        # Remove enumerations
        text = re.sub(r'[0-9#]*\.', '', text)

        return len(text.split())


nixie.serve(WordCountHTTPRequestHandler)
Esempio n. 4
0
import nixie
import requests

class AICHTTPRequestHandler(nixie.NixieHTTPRequestHandler):
    def get_data(self):
        response = requests.get('https://nocache.aggregator-data.artic.edu/api/v1/artworks/search', {
            # Bypass an internal Elasticsearch cache (use only for realtime applications)
            'cache': 'false',
            # We only care about `pagination`, not `data`
            'limit': 0,
            # All artworks updated since 9:00 AM today
            'query[range][timestamp][gte]': 'now/1d+9h',
            # ...relative to local time in Chicago, IL
            'query[range][timestamp][time_zone]': '-06:00',
        })

        data = response.json()

        return data['pagination']['total']

nixie.serve(AICHTTPRequestHandler)
Esempio n. 5
0
import nixie
import sys
import os


class FileCountHTTPRequestHandler(nixie.NixieHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        if len(sys.argv) > 1 and os.path.isdir(sys.argv[1]):
            os.chdir(sys.argv[1])

        super().__init__(*args, **kwargs)

    def get_data(self):
        # counts both files and folders, for speed
        # https://stackoverflow.com/questions/2632205
        # surprisingly, faster than `ls -f | wc -l`
        return len(os.listdir('.'))


nixie.serve(FileCountHTTPRequestHandler)