diff --git a/KriptonGerritBot.py b/KriptonGerritBot.py new file mode 100644 index 0000000..fd3e218 --- /dev/null +++ b/KriptonGerritBot.py @@ -0,0 +1,50 @@ +import json +import urllib2 +import os +import time +import telegram + +kripton_people = [ + 'kadertarlan', + 'yeliztaneroglu', + 'ozcanesen', + 'aybuke', + 'gulsahkose' + ] + +bot = telegram.Bot(token='<>') + +while True: + data = urllib2.urlopen('http://gerrit.libreoffice.org/changes/?n=25&O=81') + json_text = data.read() + json_text = json_text[5:] # trim + + latest_changes = json.loads(json_text) + + for patch in latest_changes: + + _number = str(patch['_number']) + + if patch['owner']['username'] in kripton_people and not os.path.exists("sentcommits/" + _number): + + message = 'Gonderen: ' + patch['owner']['username'] + \ + '\n - Durum: ' + patch['status'] + \ + '\n - Baslik: ' + patch['subject'] + \ + '\n - Degisiklik: +' + str(patch['insertions']) + ' -' + str(patch['deletions']) + \ + '\n - Baglanti: https://gerrit.libreoffice.org/#/c/' + _number + + subscribers = [] + for update in bot.getUpdates(): + chat_id = update['message']['chat']['id'] + if chat_id not in subscribers: + subscribers.append(chat_id) + + for chat_id in subscribers: + try: + bot.sendMessage(chat_id, message) + except: + pass + + open("sentcommits/" + _number, 'a').close() # touch sentcommits/id + + time.sleep(10) diff --git a/sentcommits/__init_dir__ b/sentcommits/__init_dir__ new file mode 100644 index 0000000..e69de29