Beispiel #1
0
    def post(cls, request):
        doc = xml_fromstring(request.body)
        node = doc[0][0]
        device_id = node.attrib['id']

        return dict(device_id=device_id,
                    )
Beispiel #2
0
    def post(cls, request):
        doc = xml_fromstring(request.body)
        node = doc[0][0]
        device_id = node.attrib['id']

        return dict(device_id=device_id,
                    )
Beispiel #3
0
def api_pivotal_webhook_v3(request, user_profile, stream):
    # type: (HttpRequest, UserProfile, Text) -> Tuple[Text, Text]
    payload = xml_fromstring(request.body)

    def get_text(attrs):
        # type: (List[str]) -> str
        start = payload
        try:
            for attr in attrs:
                start = start.find(attr)
            return start.text
        except AttributeError:
            return ""

    event_type = payload.find('event_type').text
    description = payload.find('description').text
    project_id = payload.find('project_id').text
    story_id = get_text(['stories', 'story', 'id'])
    # Ugh, the URL in the XML data is not a clickable url that works for the user
    # so we try to build one that the user can actually click on
    url = "https://www.pivotaltracker.com/s/projects/%s/stories/%s" % (project_id, story_id)

    # Pivotal doesn't tell us the name of the story, but it's usually in the
    # description in quotes as the first quoted string
    name_re = re.compile(r'[^"]+"([^"]+)".*')
    match = name_re.match(description)
    if match and len(match.groups()):
        name = match.group(1)
    else:
        name = "Story changed"  # Failed for an unknown reason, show something
    more_info = " [(view)](%s)" % (url,)

    if event_type == 'story_update':
        subject = name
        content = description + more_info
    elif event_type == 'note_create':
        subject = "Comment added"
        content = description + more_info
    elif event_type == 'story_create':
        issue_desc = get_text(['stories', 'story', 'description'])
        issue_type = get_text(['stories', 'story', 'story_type'])
        issue_status = get_text(['stories', 'story', 'current_state'])
        estimate = get_text(['stories', 'story', 'estimate'])
        if estimate != '':
            estimate = " worth %s story points" % (estimate,)
        subject = name
        content = "%s (%s %s%s):\n\n~~~ quote\n%s\n~~~\n\n%s" % (
            description,
            issue_status,
            issue_type,
            estimate,
            issue_desc,
            more_info)
    return subject, content
Beispiel #4
0
def api_pivotal_webhook_v3(request: HttpRequest,
                           user_profile: UserProfile) -> Tuple[str, str]:
    payload = xml_fromstring(request.body)

    def get_text(attrs: List[str]) -> str:
        start = payload
        try:
            for attr in attrs:
                start = start.find(attr)
            return start.text
        except AttributeError:
            return ""

    event_type = payload.find("event_type").text
    description = payload.find("description").text
    project_id = payload.find("project_id").text
    story_id = get_text(["stories", "story", "id"])
    # Ugh, the URL in the XML data is not a clickable URL that works for the user
    # so we try to build one that the user can actually click on
    url = f"https://www.pivotaltracker.com/s/projects/{project_id}/stories/{story_id}"

    # Pivotal doesn't tell us the name of the story, but it's usually in the
    # description in quotes as the first quoted string
    name_re = re.compile(r'[^"]+"([^"]+)".*')
    match = name_re.match(description)
    if match and len(match.groups()):
        name = match.group(1)
    else:
        name = "Story changed"  # Failed for an unknown reason, show something
    more_info = f" [(view)]({url})."

    if event_type == "story_update":
        subject = name
        content = description + more_info
    elif event_type == "note_create":
        subject = "Comment added"
        content = description + more_info
    elif event_type == "story_create":
        issue_desc = get_text(["stories", "story", "description"])
        issue_type = get_text(["stories", "story", "story_type"])
        issue_status = get_text(["stories", "story", "current_state"])
        estimate = get_text(["stories", "story", "estimate"])
        if estimate != "":
            estimate = f" worth {estimate} story points"
        subject = name
        content = f"{description} ({issue_status} {issue_type}{estimate}):\n\n~~~ quote\n{issue_desc}\n~~~\n\n{more_info}"
    return subject, content
Beispiel #5
0
 def convert(self, rows, time=lambda x:x):
     from defusedxml.ElementTree import fromstring as xml_fromstring
     from dateutil import parser as date_parser
     count = 0
     for ts, data in rows:
         doc = xml_fromstring(data)
         node = doc[0][0]
         device_id = node.attrib['id']
         start_time = doc[0][0][0][0].attrib['time']
         ts = date_parser.parse(start_time)
         values = doc[0][0][0][0][9]
         reader = csv.reader(values.text.split('\n'))
         for row in reader:
             #count += 1 ; print count
             if not row: continue
             unixtime = timegm(ts.timetuple()) + int(row[0])
             #yield [unixtime, time.strftime('%H:%M:%S', time.localtime(unixtime))]+ row[1:]
             yield [time(unixtime), ]+ row[1:]
Beispiel #6
0
 def convert(self, rows, time=lambda x: x):
     from defusedxml.ElementTree import fromstring as xml_fromstring
     from dateutil import parser as date_parser
     count = 0
     for ts, data in rows:
         doc = xml_fromstring(data)
         node = doc[0][0]
         device_id = node.attrib['id']
         start_time = doc[0][0][0][0].attrib['time']
         ts = date_parser.parse(start_time)
         values = doc[0][0][0][0][9]
         reader = csv.reader(values.text.split('\n'))
         for row in reader:
             #count += 1 ; print count
             if not row: continue
             unixtime = timegm(ts.timetuple()) + int(row[0])
             #yield [unixtime, time.strftime('%H:%M:%S', time.localtime(unixtime))]+ row[1:]
             yield [
                 time(unixtime),
             ] + row[1:]