396861feb1
At Ksplice we used /usr/bin/python because we shipped dependencies as Debian / Red Hat packages, which would be installed against the system Python. We were also very careful to use only Python 2.3 features so that even old system Python would still work. None of that is true at Humbug. We expect users to install dependencies themselves, so it's more likely that the Python in $PATH is correct. On OS X in particular, it's common to have five broken Python installs and there's no expectation that /usr/bin/python is the right one. The files which aren't marked executable are not interesting to run as scripts, so we just remove the line there. (In general it's common to have libraries that can also be executed, to run test cases or whatever, but that's not the case here.) (imported from commit 437d4aee2c6e66601ad3334eefd50749cce2eca6)
59 lines
1.8 KiB
Python
Executable file
59 lines
1.8 KiB
Python
Executable file
#!/usr/bin/env python
|
|
import sys
|
|
from os import path
|
|
import logging
|
|
|
|
sys.path.append(path.join(path.dirname(__file__), '..'))
|
|
import humbug
|
|
|
|
class StreamLogger(object):
|
|
"""
|
|
Give a file-like interface to a logger instance.
|
|
"""
|
|
def __init__(self, logger, log_level=logging.INFO):
|
|
self.logger = logger
|
|
self.log_level = log_level
|
|
self.buffer = ""
|
|
|
|
def write(self, message):
|
|
self.buffer += message
|
|
|
|
if message[-1] == "\n":
|
|
self.logger.log(self.log_level, self.buffer.rstrip())
|
|
self.buffer = ""
|
|
|
|
logging.basicConfig(filename="/var/log/humbug/feedback-bot.log",
|
|
level=logging.DEBUG, format="%(asctime)s %(levelname)s\t%(message)s")
|
|
|
|
# The API prints to stdout, so capture and format those messages as well.
|
|
stdout_logger = StreamLogger(logging.getLogger("stdout"), logging.INFO)
|
|
sys.stdout = stdout_logger
|
|
|
|
stderr_logger = StreamLogger(logging.getLogger("stderr"), logging.ERROR)
|
|
sys.stderr = stderr_logger
|
|
|
|
prod_client = humbug.Client(
|
|
email="feedback@humbughq.com",
|
|
api_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
|
verbose=True,
|
|
site="https://humbughq.com")
|
|
staging_client = humbug.Client(
|
|
email="feedback@humbughq.com",
|
|
api_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
|
verbose=True,
|
|
site="https://staging.humbughq.com")
|
|
|
|
def forward_message(message):
|
|
if message["type"] != "private" or len(message["display_recipient"]) != 2:
|
|
return
|
|
forwarded_message = {
|
|
"type": "stream",
|
|
"to": "support",
|
|
"subject": "feedback from %s" % message["sender_email"],
|
|
"content": message["content"],
|
|
}
|
|
staging_client.send_message(forwarded_message)
|
|
logging.info("Forwarded feedback from %s" % (message["sender_email"],))
|
|
|
|
prod_client.call_on_each_message(forward_message)
|