Skip to content

Commit d999671

Browse files
authored
Merge pull request #118 from balestek/master
2 parents 22a59c0 + 2ccf8fb commit d999671

2 files changed

Lines changed: 96 additions & 63 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ python3 setup.py install
2424

2525
## 📚 Usage:
2626

27+
### Find information from a username
28+
2729
```
2830
toutatis -u username -s instagramsessionid
2931
```
32+
33+
### Find information from an Instagram ID
34+
35+
```
36+
toutatis -i instagramID -s instagramsessionid
37+
```
38+
3039
## 📈 Example
3140

3241
```

toutatis/core.py

Lines changed: 87 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
)
1111
import pycountry
1212

13-
def getUserId(username,sessionsId):
13+
14+
def getUserId(username, sessionsId):
1415
headers = {"User-Agent": "iphone_ua", "x-ig-app-id": "936619743392459"}
1516
api = requests.get(
1617
f'https://i.instagram.com/api/v1/users/web_profile_info/?username={username}',
@@ -20,36 +21,55 @@ def getUserId(username,sessionsId):
2021
try:
2122
if api.status_code == 404:
2223
return {"id": None, "error": "User not found"}
23-
24+
2425
id = api.json()["data"]['user']['id']
25-
return {"id":id, "error": None}
26+
return {"id": id, "error": None}
2627

2728
except decoder.JSONDecodeError:
28-
return {"id":None, "error":"Rate limit"}
29-
30-
def getInfo(username,sessionId):
31-
userId = getUserId(username, sessionId)
32-
if userId["error"]:
33-
return userId
34-
35-
response = requests.get(
36-
f'https://i.instagram.com/api/v1/users/{userId["id"]}/info/',
37-
headers={'User-Agent': 'Instagram 64.0.0.14.96'},
38-
cookies={'sessionid': sessionId}
39-
).json()["user"]
40-
41-
infoUser = response
42-
infoUser["userID"] = userId["id"]
43-
44-
return {"user":infoUser, "error":None}
29+
return {"id": None, "error": "Rate limit"}
30+
31+
32+
def getInfo(search, sessionId, searchType="username" or "id"):
33+
if searchType == "username":
34+
data = getUserId(search, sessionId)
35+
if data["error"]:
36+
return data
37+
userId = data["id"]
38+
else:
39+
try:
40+
userId = str(int(search))
41+
except ValueError:
42+
return {"user": None, "error": "Invalid ID"}
43+
44+
try:
45+
response = requests.get(
46+
f'https://i.instagram.com/api/v1/users/{userId}/info/',
47+
headers={'User-Agent': 'Instagram 64.0.0.14.96'},
48+
cookies={'sessionid': sessionId}
49+
)
50+
if response.status_code == 429:
51+
return {"user": None, "error": "Rate limit"}
52+
53+
response.raise_for_status()
54+
55+
info_user = response.json().get("user")
56+
if not info_user:
57+
return {"user": None, "error": "Not found"}
58+
59+
info_user["userID"] = userId
60+
return {"user": info_user, "error": None}
61+
62+
except requests.exceptions.RequestException:
63+
return {"user": None, "error": "Not found"}
64+
4565

4666
def advanced_lookup(username):
4767
"""
4868
Post to get obfuscated login infos
4969
"""
50-
data = "signed_body=SIGNATURE."+quote_plus(dumps(
51-
{"q":username, "skip_recovery":"1"},
52-
separators=(",",":")
70+
data = "signed_body=SIGNATURE." + quote_plus(dumps(
71+
{"q": username, "skip_recovery": "1"},
72+
separators=(",", ":")
5373
))
5474
api = requests.post(
5575
'https://i.instagram.com/api/v1/users/lookup/',
@@ -60,88 +80,92 @@ def advanced_lookup(username):
6080
"X-IG-App-ID": "124024574287414",
6181
"Accept-Encoding": "gzip, deflate",
6282
"Host": "i.instagram.com",
63-
#"X-FB-HTTP-Engine": "Liger",
83+
# "X-FB-HTTP-Engine": "Liger",
6484
"Connection": "keep-alive",
6585
"Content-Length": str(len(data))
6686
},
6787
data=data
6888
)
6989

7090
try:
71-
return({"user": api.json(),"error": None})
91+
return ({"user": api.json(), "error": None})
7292
except decoder.JSONDecodeError:
73-
return({"user": None, "error": "rate limit"})
93+
return ({"user": None, "error": "rate limit"})
94+
7495

7596
def main():
7697
parser = argparse.ArgumentParser()
77-
parser.add_argument('-s', '--sessionid',help="Instagram session ID",required=True)
78-
parser.add_argument('-u','--username',help="One username",required=True)
98+
parser.add_argument('-s', '--sessionid', help="Instagram session ID", required=True)
99+
group = parser.add_mutually_exclusive_group(required=True)
100+
group.add_argument('-u', '--username', help="One username")
101+
group.add_argument('-i', '--id', help="User ID")
79102
args = parser.parse_args()
80103

81-
sessionsId=args.sessionid
82-
83-
infos = getInfo(args.username, sessionsId)
84-
if not infos["user"]:
104+
sessionsId = args.sessionid
105+
search_type = "id" if args.id else "username"
106+
search = args.id or args.username
107+
infos = getInfo(search, sessionsId, searchType=search_type)
108+
if not infos.get("user"):
85109
exit(infos["error"])
86110

87-
infos=infos["user"]
88-
89-
print("Informations about : "+infos["username"])
90-
print("userID : "+infos["userID"])
91-
print("Full Name : "+infos["full_name"])
92-
print("Verified : "+str(infos['is_verified'])+" | Is buisness Account : "+str(infos["is_business"]))
93-
print("Is private Account : "+str(infos["is_private"]))
94-
print("Follower : "+str(infos["follower_count"]) + " | Following : "+str(infos["following_count"]))
95-
print("Number of posts : "+str(infos["media_count"]))
111+
infos = infos["user"]
112+
113+
print("Informations about : " + infos["username"])
114+
print("userID : " + infos["userID"])
115+
print("Full Name : " + infos["full_name"])
116+
print("Verified : " + str(infos['is_verified']) + " | Is buisness Account : " + str(
117+
infos["is_business"]))
118+
print("Is private Account : " + str(infos["is_private"]))
119+
print(
120+
"Follower : " + str(infos["follower_count"]) + " | Following : " + str(infos["following_count"]))
121+
print("Number of posts : " + str(infos["media_count"]))
96122
# print("Number of tag in posts : "+str(infos["following_tag_count"]))
97123
if infos["external_url"]:
98-
print("External url : "+infos["external_url"])
99-
print("IGTV posts : "+str(infos["total_igtv_videos"]))
100-
print("Biography : "+(f"""\n{" "*25}""").join(infos["biography"].split("\n")))
101-
print("Linked WhatsApp : "+str(infos["is_whatsapp_linked"]))
102-
print("Memorial Account : "+str(infos["is_memorialized"]))
103-
print("New Instagram user : "+str(infos["is_new_to_instagram"]))
104-
105-
124+
print("External url : " + infos["external_url"])
125+
print("IGTV posts : " + str(infos["total_igtv_videos"]))
126+
print("Biography : " + (f"""\n{" " * 25}""").join(infos["biography"].split("\n")))
127+
print("Linked WhatsApp : " + str(infos["is_whatsapp_linked"]))
128+
print("Memorial Account : " + str(infos["is_memorialized"]))
129+
print("New Instagram user : " + str(infos["is_new_to_instagram"]))
130+
106131
if "public_email" in infos.keys():
107132
if infos["public_email"]:
108-
print("Public Email : "+infos["public_email"])
133+
print("Public Email : " + infos["public_email"])
109134

110135
if "public_phone_number" in infos.keys():
111136
if str(infos["public_phone_number"]):
112-
phonenr = "+"+str(infos["public_phone_country_code"])+" "+str(infos["public_phone_number"])
137+
phonenr = "+" + str(infos["public_phone_country_code"]) + " " + str(infos["public_phone_number"])
113138
try:
114139
pn = phonenumbers.parse(phonenr)
115140
countrycode = region_code_for_country_code(pn.country_code)
116141
country = pycountry.countries.get(alpha_2=countrycode)
117142
phonenr = phonenr + " ({}) ".format(country.name)
118-
except: # except what ??
119-
pass # pass what ??
143+
except: # except what ??
144+
pass # pass what ??
120145
print("Public Phone number : " + phonenr)
121146

122-
other_infos=advanced_lookup(args.username)
123-
147+
other_infos = advanced_lookup(infos["username"])
148+
124149
if other_infos["error"] == "rate limit":
125150
print("Rate limit please wait a few minutes before you try again")
126-
151+
127152
elif "message" in other_infos["user"].keys():
128153
if other_infos["user"]["message"] == "No users found":
129154
print("The lookup did not work on this account")
130155
else:
131156
print(other_infos["user"]["message"])
132-
157+
133158
else:
134159
if "obfuscated_email" in other_infos["user"].keys():
135160
if other_infos["user"]["obfuscated_email"]:
136-
print("Obfuscated email : "+other_infos["user"]["obfuscated_email"])
161+
print("Obfuscated email : " + other_infos["user"]["obfuscated_email"])
137162
else:
138163
print("No obfuscated email found")
139164

140-
if "obfuscated_phone"in other_infos["user"].keys():
165+
if "obfuscated_phone" in other_infos["user"].keys():
141166
if str(other_infos["user"]["obfuscated_phone"]):
142-
print("Obfuscated phone : "+str(other_infos["user"]["obfuscated_phone"]))
167+
print("Obfuscated phone : " + str(other_infos["user"]["obfuscated_phone"]))
143168
else:
144169
print("No obfuscated phone found")
145-
print("-"*24)
146-
print("Profile Picture : "+infos["hd_profile_pic_url_info"]["url"])
147-
170+
print("-" * 24)
171+
print("Profile Picture : " + infos["hd_profile_pic_url_info"]["url"])

0 commit comments

Comments
 (0)