Skip to content

Instantly share code, notes, and snippets.

@Mukundan314
Last active December 18, 2019 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mukundan314/49d9b2c355cbdf220f13ee2eee1db919 to your computer and use it in GitHub Desktop.
Save Mukundan314/49d9b2c355cbdf220f13ee2eee1db919 to your computer and use it in GitHub Desktop.
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