Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Telegram bot that follows Libreoffice's Gerrit updates, and sends message when a kripton person sends a new patch. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions KriptonGerritBot.py
Original file line number Diff line number Diff line change
@@ -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='<<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)
Empty file added sentcommits/__init_dir__
Empty file.