-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsearch.py
More file actions
46 lines (37 loc) · 1.39 KB
/
Copy pathsearch.py
File metadata and controls
46 lines (37 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
# !/bin/python
import json
from instagram.instagram import Instagram
import sys
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("-u", "--username", required=True, help="Instagram username")
ap.add_argument("-p", "--password", required=True, help="Instagram password")
ap.add_argument("-c", "--contacts", required=True, help="Contacts list in txt file")
# TODO : add infinite option
args = vars(ap.parse_args())
insta = Instagram(args["username"], args["password"])
if not insta.login():
print "Login failed [" + json.loads(insta.lastResponse.text)["message"] + "]"
sys.exit(-1)
numbers = [line.rstrip('\n') for line in open(args["contacts"], 'r')]
contacts = []
for number in numbers:
contact = dict()
contact["phone_numbers"] = [number]
contact["first_name"] = number
contact["email_addresses"] = []
contacts.append(contact)
if insta.syncFromAdressBook(contacts):
result = insta.lastJson
if result["status"] != "ok":
print "Syncing contacts failed " + result["status"]
sys.exit(-3)
for item in result["items"]:
try:
print item["user"]["extra_display_name"] + " = " + item["user"]["username"]
except KeyError:
print "UNKNOWN NUMBER = " + item["user"]["username"]
else:
print "Failed to get contacts [" + json.loads(insta.lastResponse.text)["message"] + "]"
sys.exit(-2)