Created
July 11, 2017 17:58
-
-
Save martin-grindr/db7d57cbc5fd5bf35be226d7444b1680 to your computer and use it in GitHub Desktop.
Treasure Data echo server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import json | |
| from http.server import BaseHTTPRequestHandler, HTTPServer | |
| from optparse import OptionParser | |
| class RequestHandler(BaseHTTPRequestHandler): | |
| def do_GET(self): | |
| self.send_response(200) | |
| print("GET:") | |
| print(self.path) | |
| def do_POST(self): | |
| self.send_response(200) | |
| print("Events:") | |
| content_length = int(self.headers['content-length']) | |
| body = self.rfile.read(content_length) | |
| events = json.loads(body) | |
| for key, d in events.items(): | |
| print('\033[1m' + key.split('.')[1] + '\033[0m') | |
| for i in d: | |
| try: | |
| print("🤵 " + i['profile_id'] + " 🕰 " + i['keen']['timestamp'] + " 🌍 " + i['geohash']) | |
| except KeyError as e: | |
| print("🤵 " + i['profile_id'] + " 🕰 " + i['keen']['timestamp']) | |
| print("\n") | |
| do_PUT = do_POST | |
| do_DELETE = do_GET | |
| def main(): | |
| server = HTTPServer(('', 80), RequestHandler) | |
| server.serve_forever() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment