hackdash.py 1.95 KB
Newer Older
1
2
3
4
5
6
7
8
9
#!/usr/bin/python
# -*- coding: utf-8 -*-

from http_API import API
from toolbox import Util
from hosted import node, device, log
from datetime import datetime
import time, json
from collections import namedtuple
10
from textwrap import TextWrapper
11
12
13
14
15
16
17

class Hackdash(object):
    def __init__(self, config):
        self.util = Util()
        self.hackdash_api = API(url="https://hackdash.org/api/v2/{}/projects".format(config['project_name']))
        self.created_after = datetime.strptime(config['created_after'], '%d/%m/%Y %H:%M:%S')
        self.lastRefresh = 0
18
19
20
        self.lineWidth = 120
        self.lineHeight = 30
        self.wrapper = TextWrapper(width=self.lineWidth)
21
22
23
24
25
26
27
28
29

    def refresh(self):
        self.hackdash_api.query()
        projects = self.hackdash_api.response
        for project_data in projects:
            project = Project(project_data)
            if project.created > self.created_after:
                title = self.util.line(u'{} | {}'.format(project.title, project.status), height=50)
                self.util.offset['y'] += 50
30
31
32
33
34
35
36
37
38
                if len(project.description) > self.lineWidth:
                    for line in self.wrapper.wrap(text=project.description):
                        desc = self.util.line(line, height=self.lineHeight)
                        self.util.offset['y'] += self.lineHeight
                        self.util.lines.append(desc)
                else:
                    desc = self.util.line(u'{}...'.format(project.description[:self.lineWidth]), height=self.lineHeight)
                    self.util.lines.append(desc)
                self.util.offset['y'] += self.lineHeight + 20
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
                self.util.lines.append(title)

    def update(self):
        self.refresh()
        self.util.updateFile()

class Project:
    def __init__(self, data):
        self.__dict__.update(data)

    @property
    def created(self):
        return datetime.strptime(self.created_at, '%Y-%m-%dT%H:%M:%S.%fZ')

# "2019-04-06T13:18:42.163Z"