Exemplo n.º 1
0
    def test_flatmap(self):
        print('Test flatmap')
        orig = ExList([1, 2, 3, 4, 5])

        def f(x):
            return ExList([x])

        self.assertEqual(orig.flatmap(f), orig)
Exemplo n.º 2
0
    def test_foreach(self):
        import sys
        from io import StringIO

        print('Test foreach')
        io = StringIO()
        sys.stdout = io
        orig = ExList([1, 2, 3, 4, 5])
        orig.foreach(print)
        self.assertEqual(io.getvalue(), '1\n2\n3\n4\n5\n')
        sys.stdout = sys.__stdout__
Exemplo n.º 3
0
def main():
    key = os.getenv("TODOIST_TOKEN")
    if key is None:
        print("Environment Variable named $TODOIST_TOKEN doesn't exist!")
        sys.exit()

    api = todoist.TodoistAPI(key, 'https://todoist.com', None, None)
    api.sync()
    items = ExList(api.state['items'])\
            .filter(hasDeadLine)\
            .filter(missDeadLine)\
            .filter(isRecurring)
    items.map(lambda item: (item, item['due']))\
         .map(lambda itemAndDue: resetSchedule(api, itemAndDue[0], itemAndDue[1]))\
         .foreach(lambda itemAndDue: reschedule(api, itemAndDue[0], itemAndDue[1]))
def main():
    key = os.getenv("TODOIST_TOKEN")
    if key is None:
        print("Environment Variable named $TODOIST_TOKEN doesn't exist!")
        sys.exit()

    api = todoist.TodoistAPI(key, 'https://todoist.com', None, None)
    api.sync()
    logger.debug('Filtering start')
    items = ExList(api.completed.get_all()['items'])\
            .filter(completedYesterday)
    logger.debug('Filtering finished')
    message = makeText(api.projects, items)
    sendSlackMessage(message)
Exemplo n.º 5
0
 def test_take(self):
     print('Test take')
     orig = ExList([1, 2, 3, 4, 5])
     ideal = ExList([1, 2, 3])
     self.assertEqual(orig.take(3), ideal)
Exemplo n.º 6
0
 def test_drop(self):
     print('Test drop')
     orig = ExList([1, 2, 3, 4, 5])
     ideal = ExList([3, 4, 5])
     self.assertEqual(orig.drop(2), ideal)
Exemplo n.º 7
0
 def test_slice(self):
     print('Test drop')
     orig = ExList([1, 2, 3, 4, 5])
     ideal = ExList([3, 4])
     self.assertEqual(orig[2:4], ideal)
Exemplo n.º 8
0
 def test_map(self):
     print('Test map')
     orig = ExList([1, 2, 3, 4, 5])
     ideal = ExList([2, 4, 6, 8, 10])
     self.assertEqual(orig.map(lambda x: x * 2), ideal)
Exemplo n.º 9
0
 def f(x):
     return ExList([x])
Exemplo n.º 10
0
 def test_flatten(self):
     print('Test flatten')
     lst = ExList([1, 2])
     orig = ExList([lst, lst, lst])
     ideal = ExList([1, 2, 1, 2, 1, 2])
     self.assertEqual(orig.flatten(), ideal)
Exemplo n.º 11
0
 def test_fold(self):
     print('Test fold')
     orig = ExList([1, 2, 3, 4, 5])
     ideal = 15
     self.assertEqual(orig.fold(0, lambda x, y: x + y), ideal)
Exemplo n.º 12
0
 def test_filter(self):
     print('Test filter')
     orig = ExList([1, 2, 3, 4, 5])
     ideal = ExList([2, 4])
     self.assertEqual(orig.filter(lambda x: x % 2 == 0), ideal)