About: read commit logs from Github using json api
authorAthanasios Oikonomou <athoik@gmail.com>
Fri, 24 Jul 2015 22:51:14 +0000 (01:51 +0300)
committerAthanasios Oikonomou <athoik@gmail.com>
Fri, 24 Jul 2015 22:57:13 +0000 (01:57 +0300)
lib/python/Screens/About.py

index 9ba5799..9729605 100644 (file)
@@ -179,7 +179,7 @@ class CommitInfo(Screen):
                ]
                self.cachedProjects = {}
                self.Timer = eTimer()
-               self.Timer.callback.append(self.readCommitLogs)
+               self.Timer.callback.append(self.readGithubCommitLogs)
                self.Timer.start(50, True)
 
        def readCommitLogs(self):
@@ -204,6 +204,27 @@ class CommitInfo(Screen):
                        commitlog = _("Currently the commit log cannot be retrieved - please try later again")
                self["AboutScrollLabel"].setText(commitlog)
 
+       def readGithubCommitLogs(self):
+               url = 'https://api.github.com/repos/openpli/%s/commits' % self.projects[self.project][0]
+               commitlog = ""
+               from datetime import datetime
+               from json import loads
+               from urllib2 import urlopen
+               try:
+                       commitlog += 80 * '-' + '\n'
+                       commitlog += url.split('/')[-2] + '\n'
+                       commitlog += 80 * '-' + '\n'
+                       for c in loads(urlopen(url, timeout=5).read()):
+                               creator = c['commit']['author']['name']
+                               title = c['commit']['message']
+                               date = datetime.strptime(c['commit']['committer']['date'], '%Y-%m-%dT%H:%M:%SZ').strftime('%x %X')
+                               commitlog += date + ' ' + creator + '\n' + title + 2 * '\n'
+                       commitlog = commitlog.encode('utf-8')
+                       self.cachedProjects[self.projects[self.project][1]] = commitlog
+               except:
+                       commitlog += _("Currently the commit log cannot be retrieved - please try later again")
+               self["AboutScrollLabel"].setText(commitlog)
+
        def updateCommitLogs(self):
                if self.cachedProjects.has_key(self.projects[self.project][1]):
                        self["AboutScrollLabel"].setText(self.cachedProjects[self.projects[self.project][1]])