Skip to content

Commit 1a5d77b

Browse files
authored
Merge pull request #2586 from subzeroid/master
Integration with HikerAPI (fixed all issues via hikercli)
2 parents 3c61e53 + 382a8eb commit 1a5d77b

File tree

9 files changed

+1250
-26
lines changed

9 files changed

+1250
-26
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ You can find detailed commands usage [here](doc/COMMANDS.md).
7474

7575
5. Run `pip install -r requirements.txt`
7676

77-
6. Open the `credentials.ini` file in the `config` folder and write your Instagram account username and password in the corresponding fields
78-
77+
6. Open the `credentials.ini` file in the `config` folder and write your Instagram account username and password in the corresponding fields. Or use `hikerapi_token` from https://hikerapi.com/tokens (first 100 requests are free after registration and confirmation of your tg)
78+
7979
Alternatively, you can run the `make setup` command to populate this file for you.
8080

81-
7. Run the main.py script in one of two ways
81+
7. Run the main.py script in one of three ways
8282

8383
* As an interactive prompt `python3 main.py <target username>`
8484
* Or execute your command straight away `python3 main.py <target username> --command <command>`
85+
* Or execute using HikerAPI token via env `HIKERAPI_TOKEN=<hikerapi token> python3 main.py <target username> -c <command>`
8586

8687
### Use Osintgram v2 (beta)
8788
You can use Osintgram2 beta just switching to `v2` [branch](https://github.com/Datalux/Osintgram/tree/v2).

config/credentials.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[Credentials]
22
username =
3-
password =
3+
password =
4+
hikerapi_token =

docker_reqs.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
requests==2.24.0
21
requests-toolbelt==0.9.1
32
geopy>=2.0.0
43
prettytable==0.7.2
54
instagram-private-api==1.6.0
6-
gnureadline>=8.0.0
5+
gnureadline>=8.0.0
6+
hikerapi==1.7.1

main.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/usr/bin/env python3
2-
3-
from src.Osintgram import Osintgram
4-
import argparse
5-
from src import printcolors as pc
6-
from src import artwork
2+
import os
73
import sys
84
import signal
5+
import argparse
6+
7+
from src import artwork, config
8+
from src import printcolors as pc
9+
from src.hikercli import HikerCLI, hk
10+
from src.Osintgram import Osintgram
911

1012
is_windows = False
1113

@@ -18,7 +20,10 @@
1820

1921
def printlogo():
2022
pc.printout(artwork.ascii_art, pc.YELLOW)
21-
pc.printout("\nVersion 1.1 - Developed by Giuseppe Criscione\n\n", pc.YELLOW)
23+
pc.printout("\nVersion 1.1 - Developed by Giuseppe Criscione", pc.YELLOW)
24+
pc.printout(
25+
f"\nHikerAPI {hk.__version__} https://hikerapi.com/help/about\n\n", pc.YELLOW
26+
)
2227
pc.printout("Type 'list' to show all allowed commands\n")
2328
pc.printout("Type 'FILE=y' to save results to files like '<target username>_<command>.txt (default is disabled)'\n")
2429
pc.printout("Type 'FILE=n' to disable saving to files'\n")
@@ -92,6 +97,7 @@ def completer(text, state):
9297
else:
9398
return None
9499

100+
95101
def _quit():
96102
pc.printout("Goodbye!\n", pc.RED)
97103
sys.exit(0)
@@ -118,8 +124,10 @@ def _quit():
118124
args = parser.parse_args()
119125

120126

121-
api = Osintgram(args.id, args.file, args.json, args.command, args.output, args.cookies)
122-
127+
if config.getHikerToken():
128+
api = HikerCLI(args.id, args.file, args.json, args.command, args.output, args.cookies)
129+
else:
130+
api = Osintgram(args.id, args.file, args.json, args.command, args.output, args.cookies)
123131

124132

125133
commands = {

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
requests==2.24.0
21
requests-toolbelt==0.9.1
32
geopy>=2.0.0
43
prettytable==0.7.2
54
instagram-private-api==1.6.0
65
gnureadline>=8.0.0; platform_system != "Windows"
7-
pyreadline==2.1; platform_system == "Windows"
6+
pyreadline==2.1; platform_system == "Windows"
7+
hikerapi==1.7.1

src/Osintgram.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import codecs
77
from pathlib import Path
88

9-
import requests
9+
import httpx
1010
import ssl
1111
ssl._create_default_https_context = ssl._create_unverified_context
1212

@@ -598,27 +598,34 @@ def get_total_likes(self):
598598

599599
data = self.__get_feed__()
600600

601-
for post in data:
602-
like_counter += post['like_count']
603-
posts += 1
601+
likes = [int(p["like_count"]) for p in data]
602+
posts = len(likes)
603+
like_counter = sum(likes)
604+
min_ = min(likes)
605+
max_ = max(likes)
606+
avg = int(like_counter / posts)
607+
result = f" likes in {posts} posts (min: {min_}, max: {max_}, avg: {avg})\n"
604608

605609
if self.writeFile:
606610
file_name = self.output_dir + "/" + self.target + "_likes.txt"
607611
file = open(file_name, "w")
608-
file.write(str(like_counter) + " likes in " + str(like_counter) + " posts\n")
612+
file.write(str(like_counter) + result)
609613
file.close()
610614

611615
if self.jsonDump:
612616
json_data = {
613-
'like_counter': like_counter,
614-
'posts': like_counter
617+
"like_counter": like_counter,
618+
"posts": posts,
619+
"min": min_,
620+
"max": max_,
621+
"avg": avg,
615622
}
616623
json_file_name = self.output_dir + "/" + self.target + "_likes.json"
617-
with open(json_file_name, 'w') as f:
624+
with open(json_file_name, "w") as f:
618625
json.dump(json_data, f)
619626

620627
pc.printout(str(like_counter), pc.MAGENTA)
621-
pc.printout(" likes in " + str(posts) + " posts\n")
628+
pc.printout(result)
622629

623630
def get_media_type(self):
624631
if self.check_private_profile():
@@ -798,7 +805,7 @@ def get_photo_description(self):
798805
if self.check_private_profile():
799806
return
800807

801-
content = requests.get("https://www.instagram.com/" + str(self.target) + "/?__a=1")
808+
content = httpx.get("https://www.instagram.com/" + str(self.target) + "/?__a=1")
802809
data = content.json()
803810

804811
dd = data['graphql']['user']['edge_owner_to_timeline_media']['edges']

src/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import configparser
23
import sys
34

@@ -40,3 +41,7 @@ def getPassword():
4041
except KeyError:
4142
pc.printout('Error: missing "password" field in "config/credentials.ini"\n', pc.RED)
4243
sys.exit(0)
44+
45+
46+
def getHikerToken():
47+
return config["Credentials"].get("hikerapi_token") or os.getenv("HIKERAPI_TOKEN")

0 commit comments

Comments
 (0)