Esempio n. 1
0
    def run_event(self):
        args = self.args

        stream = Stream(id=args.id,
                        password=args.password,
                        generator=args.generator)

        encoding = sys.stdin.encoding or locale.getdefaultlocale()[1]

        char_count = 0
        lines = []
        for line in sys.stdin:
            sys.stdout.write(line)
            line = line.decode(encoding, 'replace')
            if char_count + len(line) <= self.MAX_CHARS:
                lines.append(line)
            char_count += len(line)

        text = "".join(lines)[:self.MAX_CHARS]
        if isinstance(text, bytes):
            encoding = sys.stdin.encoding or locale.getdefaultlocale()[1]
            text = text.decode(encoding, 'replace')

        event = Event(type="code",
                      title=args.title or 'Capture Event',
                      markup=args.markup,
                      description=args.description,
                      text=text)

        result = stream.add_event(event)
        return result
Esempio n. 2
0
 def test_add_text(self):
     stream = Stream('foo', 'bar')
     with mock.patch('inthing.Stream.add_event') as add_event:
         stream.text('this is the text', title="My Text")
     event = add_event.call_args[0][0]
     assert isinstance(event, Event), 'must be an Event'
     self.assertEqual(event.type, 'text')
     self.assertEqual(event.description, 'this is the text')
     self.assertEqual(event.title, 'My Text')
Esempio n. 3
0
 def test_new(self):
     ret = {'id': "ABC", 'password': '******', 'url': 'https://example.org'}
     with mock.patch('inthing.jsonrpc.JSONRPC.call', mock.Mock(return_value=ret)):
         stream = Stream.new()
     self.assertEqual(stream.id, ret['id'])
     self.assertEqual(stream.password, ret['password'])
     self.assertEqual(stream.url, ret['url'])
Esempio n. 4
0
"""An example of posting a text event to a stream."""

from inthing import Stream


def mandel(xsize=80, ysize=20, max_iteration=50):
    """Render an ascii mandelbrot set!"""
    chars = " .,~:;+*%@##"
    rows = []
    for pixy in xrange(ysize):
        y0 = (float(pixy) / ysize) * 2 - 1
        row = ""
        for pixx in xrange(xsize):
            x0 = (float(pixx) / xsize) * 3 - 2
            x = 0
            y = 0
            iteration = 0
            while (x * x + y * y < 4) and iteration < max_iteration:
                xtemp = x * x - y * y + x0
                y = 2 * x * y + y0
                x = xtemp
                iteration += 1
            row += chars[iteration % 10]
        rows.append(row)
    return "```\n{}\n```\n#mandlebrot".format('\n'.join(rows))


stream = Stream.new()
result = stream.text(mandel(), title="Mandelbrot Set!")
result.browse()
Esempio n. 5
0
from inthing import Stream
s = Stream.new()
with Stream.new().capture('example') as capture:
    print('hello')
capture.browse()