Last active
November 5, 2019 18:25
-
-
Save PramodGarg/bc2f86e67c50354762065bf7d6e0e65f to your computer and use it in GitHub Desktop.
Populate messages in android emulator from csv
This file contains 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 csv | |
import telnetlib | |
def get_auth_code() : | |
with open('/Users/<username>/.emulator_console_auth_token', 'r') as file: # file is in root directory, replace username | |
return file.read() | |
def send_message(session, sender, msg): | |
session.write(bytes("sms send {} {}\n".format(sender, msg), encoding='utf-8')) | |
host = "localhost" | |
port = 5554 # get port of the emulator by adb devices | |
timeout = 100 | |
auth_code = get_auth_code() | |
session = telnetlib.Telnet(host, port, timeout) | |
session.write(bytes("auth {}\n".format(auth_code), encoding='utf-8')) | |
with open('messages.csv') as csv_file: # enter the csv file | |
csv_reader = csv.reader(csv_file, delimiter=',') | |
line_count = 0 | |
for row in csv_reader: | |
if line_count == 0: | |
print(f'Column names are {", ".join(row)}') | |
line_count += 1 | |
else: | |
message = row[1] | |
send_message(session, "1234567890", message) | |
line_count += 1 | |
print(f'Processed {line_count} lines.') | |
session.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment