How can I find the email of a GitHub user and write a Telegram bot to solve this problem?

Meme from the Internet
Meme from the Internet

This post will be useful to two categories of people: IT recruiters and novice developers who want to learn how to write simple programs for solving practical problems.





Task: we know the user profile on GitHub, you need to find the email of this user





The idea to write a bot came to me after a colleague shared with me the way IT recruiters solve this problem:





1. https://api.github.com/users/ /events/public









2. Ctrl+F "@"







3. ,





This is the search result and the email address found

EmailOnGitHub Chrome Store Python:





import requests, telebot, time

tkn = '___'
bot = telebot.TeleBot(tkn)


#   /start 

@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, ',     email     .     ,   ,    ')
                            

#    -        
#        email_finder

@bot.message_handler(content_types=['text'])
def send_text(message):

    bot.send_message(message.chat.id, email_finder(message.text))
      
      



, , , , email_finder.





, . :





#      ,       
#    ,    email   

def email_finder(nick):
    rawlist, newlist = [], []

    #    ,       

    url = f'https://api.github.com/users/{nick}/events/public'
    r = requests.get(url)

    #   
    #    -    ,  

    if r.status_code == 200:
        print('status 200 - OK')

        #   ,    ,     
        #      "  "

        if not r.json():
            return ' .   email.'

    elif url_status == 404:
        return '     '
    else:
        return ' '

    #    

    for element in r.json():
        if element['type'] == 'PushEvent':
            for commit in element['payload']['commits']:
            
                #       
                email = commit['author']['email']
                rawlist.append(email)
    f_list = '  : \n'

    #        

    for i in rawlist:
        if i not in newlist:
            newlist.append(i)
    for element in newlist:
        f_list = f_list + element + '\n'

    return f_list
      
      



The main part is ready. It remains to add the following lines:





#    

while True:
    try:
        print(' ...')
        bot.infinity_polling(True)

    except Exception as e:
        print(' ')
        time.sleep(15)
      
      



Our mail search bot is ready, you can start and use it. A trial version is available at @GitSorcerBot

If the user posted commits and left their mail, the bot will output the result:












All Articles