Last active
December 18, 2019 07:42
-
-
Save Mukundan314/49d9b2c355cbdf220f13ee2eee1db919 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import json | |
import os | |
from telegram.ext import Updater, CommandHandler | |
def count(update, context): | |
with urllib.request.urlopen('https://api.github.com/orgs/fedora-infra/repos') as res: | |
repos = json.load(res) | |
reply = "Number of repos: {}".format(len(repos)) | |
context.bot.send_message(chat_id=update.effective_chat.id, text=reply) | |
def fork_counts(update, context): | |
with urllib.request.urlopen('https://api.github.com/orgs/fedora-infra/repos') as res: | |
repos = json.load(res) | |
reply = '\n'.join(["{}: {}".format(repo['name'], repo['forks_count']) for repo in repos]) | |
context.bot.send_message(chat_id=update.effective_chat.id, text=reply) | |
updater = Updater(token=os.environ['BOT_TOKEN'], use_context=True) | |
dispatcher = updater.dispatcher | |
count_handler = CommandHandler('count', count) | |
dispatcher.add_handler(count_handler) | |
fork_counts_handler = CommandHandler('fork_counts', fork_counts) | |
dispatcher.add_handler(fork_counts_handler) | |
updater.start_polling() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment