Created
April 29, 2017 20:56
-
-
Save victorcarrico/62689d6dd0c2c67350f20969cbb88afe to your computer and use it in GitHub Desktop.
Send a message to a group of Instagram users (using instagram-python)
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
from InstagramAPI import Instagram | |
def get_user_info_and_login(): | |
try: | |
username = raw_input('Your Instagram username:\n') | |
password = raw_input('Your Instagram password:\n') | |
print 'Wait a second, logging in your account.\n' | |
api = Instagram(username, password) | |
api.login() | |
print 'Your are logged in.\n' | |
except: | |
print 'Login has failed, please try again.' | |
get_user_info_and_login() | |
return api | |
def main(): | |
api = get_user_info_and_login() | |
recipients = raw_input('Write the usernames of the recipients separating by comma (Ex: bruna,victor,chico)\n') | |
message = raw_input('Write the message:\n') | |
recipients_list = recipients.split(',') | |
recipients_ids_list = [] | |
for recipient in recipients_list: | |
user_info = api.searchUsername(recipient) | |
recipient_id = user_info.getUsernameId() | |
recipients_ids_list.append(str(recipient_id)) | |
print('Sending the message...\n') | |
try: | |
api.direct_message(recipients_ids_list, message) | |
except: | |
print 'Failed :( Please try again.\n' | |
else: | |
print 'Your message was successful sent! :D\n' | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment