From 776893f3a11b5a0aa42935f8c574aa23d095cc9c Mon Sep 17 00:00:00 2001 From: lamdt laptop Date: Sun, 31 Mar 2013 02:02:30 +0700 Subject: [PATCH] get from git --- Python/vccrptr.py | 110 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 2 deletions(-) diff --git a/Python/vccrptr.py b/Python/vccrptr.py index b043164..f27e08d 100644 --- a/Python/vccrptr.py +++ b/Python/vccrptr.py @@ -3,6 +3,15 @@ from datetime import date as dtdate from datetime import timedelta +import urllib +from xml.dom import minidom + +from pprint import pprint + +# find this token in git.vccloud.vn, "News Feed" item below right column +GIT_TOKEN = 'c9sArqzmoVMqgy7BUjyh' + +GIT_URL = "http://git.vccloud.vn/dashboard.atom?private_token="+GIT_TOKEN """ A simple script auto generate data for reporting weekly at BBTeam - VCCloud""" @@ -21,8 +30,105 @@ def get_week_boundary(day_in_week=dtdate.today()): return (mon_of_week.strftime(date_format), sat_of_week.strftime(date_format)) +def send_request(url): + return urllib.urlopen(url) + +# get data (branch name + commit-content, commit-time) from git +# lists or json ??? +# structure: +# [ +# [ +# 'branch name 1', +# 'updated time 1', +# [ +# ['commit content 1','commit time 1'], +# ['commit content 2','commit time 2'], +# ['commit content n','commit time n'], +# ] +# ], +# [ +# 'branch name n', +# 'updated time n', +# [ +# ['commit content 1','commit time 1'], +# ['commit content 2','commit time 2'], +# ['commit content n','commit time n'], +# ] +# ] +# ] + +def get_from_git(): + url = GIT_URL + res = send_request(url) + """ parse XML: + + tag:git.vccloud.vn,2013-03-29:878 + + LamDT pushed to branch master at vpn + 2013-03-29T04:30:49Z + + + LamDT + lamdt@vccloud.vn + + +
+

+ at VCC + (#edf2b1ce83f) + at 2013-03-29 11:30:48 +

+

button fix for chrome

+
+
+
+ """ + result = [] + dom = minidom.parse(res) + item_list = dom.getElementsByTagName('entry') + + for node in item_list: + entry = [] + # get title + title = node.getElementsByTagName('title') + entry.append(title[0].firstChild.nodeValue) + + # # get update + update = node.getElementsByTagName('updated') + entry.append(update[0].firstChild.nodeValue) + + # get commits + entry_commits = [] + commits = node.getElementsByTagName('div') + + for commit in commits: + entry_commit_one = [] + + # get commit time + for commit_time in commit.getElementsByTagName('i'): + # print commit_time.firstChild.nodeValue + entry_commit_one.append(commit_time.firstChild.nodeValue) + + # get commit content + for commit_content in commit.getElementsByTagName('p'): + # print commit_content.firstChild.nodeValue + entry_commit_one.append(commit_content.firstChild.nodeValue) + + entry_commits.append(entry_commit_one) + + entry.append(entry_commits) + + # result concatenation + result.append(entry) + + pprint (result) + + def get_subject(wbdr=get_week_boundary()): - return "Báo cáo tuần (%s -> %s)" % wbdr + # print get_from_git('c9sArqzmoVMqgy7BUjyh') + # return "Báo cáo tuần (%s -> %s)" % wbdr + return get_from_git() + if __name__ == "__main__": - print get_subject() + get_subject() \ No newline at end of file