Skip to content

Commit 72f4456

Browse files
committed
Black and pyflakes
1 parent af0490b commit 72f4456

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1401
-1122
lines changed

examples/bot.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
from instagrapi import Client
66
from instagrapi.types import UserShort
77

8-
IG_USERNAME = ''
9-
IG_PASSWORD = ''
10-
IG_CREDENTIAL_PATH = './ig_settings.json'
11-
SLEEP_TIME = '600' # in seconds
8+
IG_USERNAME = ""
9+
IG_PASSWORD = ""
10+
IG_CREDENTIAL_PATH = "./ig_settings.json"
11+
SLEEP_TIME = "600" # in seconds
12+
1213

1314
class Bot:
1415
_cl = None
@@ -21,7 +22,7 @@ def __init__(self):
2122
else:
2223
self._cl.login(IG_USERNAME, IG_PASSWORD)
2324
self._cl.dump_settings(IG_CREDENTIAL_PATH)
24-
25+
2526
def follow_by_username(self, username) -> bool:
2627
"""
2728
Follow a user
@@ -55,7 +56,7 @@ def unfollow_by_username(self, username) -> bool:
5556
"""
5657
userid = self._cl.user_id_from_username(username)
5758
return self._cl.user_unfollow(userid)
58-
59+
5960
def get_followers(self, amount: int = 0) -> Dict[int, UserShort]:
6061
"""
6162
Get bot's followers
@@ -71,7 +72,7 @@ def get_followers(self, amount: int = 0) -> Dict[int, UserShort]:
7172
Dict of user_id and User object
7273
"""
7374
return self._cl.user_followers(self._cl.user_id, amount=amount)
74-
75+
7576
def get_followers_usernames(self, amount: int = 0) -> List[str]:
7677
"""
7778
Get bot's followers usernames
@@ -104,7 +105,7 @@ def get_following(self, amount: int = 0) -> Dict[int, UserShort]:
104105
Dict of user_id and User object
105106
"""
106107
return self._cl.user_following(self._cl.user_id, amount=amount)
107-
108+
108109
def get_following_usernames(self, amount: int = 0) -> List[str]:
109110
"""
110111
Get bot's followed usernames
@@ -121,21 +122,22 @@ def get_following_usernames(self, amount: int = 0) -> List[str]:
121122
"""
122123
following = self._cl.user_following(self._cl.user_id, amount=amount)
123124
return [user.username for user in following.values()]
124-
125+
125126
def update(self):
126127
"""
127128
Do something
128129
"""
129130
pass
130131

131-
if __name__ == '__main__':
132+
133+
if __name__ == "__main__":
132134
bot = Bot()
133135

134-
bot.follow_by_username('futbot__')
136+
bot.follow_by_username("futbot__")
135137

136138
while True:
137139
"""
138140
Infnit loop
139141
"""
140142
bot.update()
141-
sleep(SLEEP_TIME)
143+
sleep(SLEEP_TIME)

examples/challenge_resolvers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from instagrapi import Client
1010
from instagrapi.mixins.challenge import ChallengeChoice
1111

12-
CHALLENGE_EMAIL = ''
13-
CHALLENGE_PASSWORD = ''
12+
CHALLENGE_EMAIL = ""
13+
CHALLENGE_PASSWORD = ""
1414

15-
IG_USERNAME = ''
16-
IG_PASSWORD = ''
15+
IG_USERNAME = ""
16+
IG_PASSWORD = ""
1717

1818

1919
def get_code_from_email(username):
@@ -73,7 +73,7 @@ def change_password_handler(username):
7373
return password
7474

7575

76-
if __name__ == '__main__':
76+
if __name__ == "__main__":
7777
cl = Client()
7878
cl.challenge_code_handler = challenge_code_handler
7979
cl.change_password_handler = change_password_handler

examples/download_all_medias.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ def main(username: str, amount: int = 5) -> dict:
2424
if m.media_type == 1:
2525
# Photo
2626
paths.append(cl.photo_download(m.pk))
27-
elif m.media_type == 2 and m.product_type == 'feed':
27+
elif m.media_type == 2 and m.product_type == "feed":
2828
# Video
2929
paths.append(cl.video_download(m.pk))
30-
elif m.media_type == 2 and m.product_type == 'igtv':
30+
elif m.media_type == 2 and m.product_type == "igtv":
3131
# IGTV
3232
paths.append(cl.video_download(m.pk))
33-
elif m.media_type == 2 and m.product_type == 'clips':
33+
elif m.media_type == 2 and m.product_type == "clips":
3434
# Reels
3535
paths.append(cl.video_download(m.pk))
3636
elif m.media_type == 8:
3737
# Album
3838
for path in cl.album_download(m.pk):
3939
paths.append(path)
4040
result[m.pk] = paths
41-
print(f'http://instagram.com/p/{m.code}/', paths)
41+
print(f"http://instagram.com/p/{m.code}/", paths)
4242
i += 1
4343
return result
4444

4545

46-
if __name__ == '__main__':
47-
username = input('Enter username: ')
46+
if __name__ == "__main__":
47+
username = input("Enter username: ")
4848
while True:
49-
amount = input('How many posts to process (default: 5)? ').strip()
50-
if amount == '':
51-
amount = '5'
49+
amount = input("How many posts to process (default: 5)? ").strip()
50+
if amount == "":
51+
amount = "5"
5252
if amount.isdigit():
5353
break
5454
main(username, amount)

examples/handle_exception.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ def handle_exception(client, e):
4242
try:
4343
client.challenge_resolve(client.last_json)
4444
except ChallengeRequired as e:
45-
self.freeze('Manual Challenge Required', days=2)
45+
self.freeze("Manual Challenge Required", days=2)
4646
raise e
47-
except (ChallengeRequired, SelectContactPointRecoveryForm, RecaptchaChallengeForm) as e:
47+
except (
48+
ChallengeRequired,
49+
SelectContactPointRecoveryForm,
50+
RecaptchaChallengeForm,
51+
) as e:
4852
self.freeze(str(e), days=4)
4953
raise e
5054
self.update_client_settings(client.get_settings())

examples/medias.py

Lines changed: 66 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,103 @@
33
from instagrapi import Client
44
from instagrapi.types import Media
55

6-
HASHTAGS = ['instacool']
7-
IG_USERNAME = ''
8-
IG_PASSWORD = ''
9-
IG_CREDENTIAL_PATH = 'credential.json'
6+
HASHTAGS = ["instacool"]
7+
IG_USERNAME = ""
8+
IG_PASSWORD = ""
9+
IG_CREDENTIAL_PATH = "credential.json"
1010

1111

1212
def get_logger(name, **kwargs):
1313
import logging
14+
1415
logging.basicConfig(**kwargs)
1516
logger = logging.getLogger(name)
1617
logger.debug(f"start logging '{name}'")
1718
return logger
1819

1920

2021
def filter_medias(
21-
medias: List[Media],
22-
like_count_min=None,
23-
like_count_max=None,
24-
comment_count_min=None,
25-
comment_count_max=None,
26-
days_ago_max=None
22+
medias: List[Media],
23+
like_count_min=None,
24+
like_count_max=None,
25+
comment_count_min=None,
26+
comment_count_max=None,
27+
days_ago_max=None,
2728
):
2829
from datetime import datetime, timedelta
2930

3031
medias = list(
31-
filter(lambda x: True if like_count_min is None else x.like_count >= like_count_min, medias))
32+
filter(
33+
lambda x: True
34+
if like_count_min is None
35+
else x.like_count >= like_count_min,
36+
medias,
37+
)
38+
)
39+
medias = list(
40+
filter(
41+
lambda x: True
42+
if like_count_max is None
43+
else x.like_count <= like_count_max,
44+
medias,
45+
)
46+
)
3247
medias = list(
33-
filter(lambda x: True if like_count_max is None else x.like_count <= like_count_max, medias))
34-
medias = list(filter(lambda x: True if comment_count_min is None else x.comment_count >= comment_count_min,
35-
medias))
36-
medias = list(filter(lambda x: True if comment_count_max is None else x.comment_count <= comment_count_max,
37-
medias))
48+
filter(
49+
lambda x: True
50+
if comment_count_min is None
51+
else x.comment_count >= comment_count_min,
52+
medias,
53+
)
54+
)
55+
medias = list(
56+
filter(
57+
lambda x: True
58+
if comment_count_max is None
59+
else x.comment_count <= comment_count_max,
60+
medias,
61+
)
62+
)
3863
if days_ago_max is not None:
3964
days_back = datetime.now() - timedelta(days=days_ago_max)
40-
medias = list(filter(
41-
lambda x: days_ago_max is None or x.taken_at is None or x.taken_at > days_back.astimezone(
42-
x.taken_at.tzinfo),
43-
medias))
65+
medias = list(
66+
filter(
67+
lambda x: days_ago_max is None
68+
or x.taken_at is None
69+
or x.taken_at > days_back.astimezone(x.taken_at.tzinfo),
70+
medias,
71+
)
72+
)
4473

4574
return list(medias)
4675

4776

48-
def get_medias(hashtags,
49-
ht_type='top',
50-
amount=27,
51-
):
77+
def get_medias(
78+
hashtags,
79+
ht_type="top",
80+
amount=27,
81+
):
5282
ht_medias = []
5383
for hashtag in hashtags:
54-
if ht_type == 'top':
55-
ht_medias.extend(
56-
cl.hashtag_medias_top(
57-
name=hashtag,
58-
amount=amount if amount <= 9 else 9
59-
)
60-
)
61-
elif ht_type == 'recent':
84+
if ht_type == "top":
6285
ht_medias.extend(
63-
cl.hashtag_medias_recent(
64-
name=hashtag,
65-
amount=amount
66-
)
86+
cl.hashtag_medias_top(name=hashtag, amount=amount if amount <= 9 else 9)
6787
)
88+
elif ht_type == "recent":
89+
ht_medias.extend(cl.hashtag_medias_recent(name=hashtag, amount=amount))
6890
return list(dict([(media.pk, media) for media in ht_medias]).values())
6991

7092

71-
if __name__ == '__main__':
93+
if __name__ == "__main__":
7294
import os
7395

74-
log = get_logger("example_media", **{
75-
"level": "DEBUG",
76-
"format": "%(asctime)s %(levelname)s %(name)s: %(message)s"
77-
})
96+
log = get_logger(
97+
"example_media",
98+
**{
99+
"level": "DEBUG",
100+
"format": "%(asctime)s %(levelname)s %(name)s: %(message)s",
101+
},
102+
)
78103
cl = Client()
79104
if os.path.exists(IG_CREDENTIAL_PATH):
80105
cl.load_settings(IG_CREDENTIAL_PATH)

examples/next_proxy.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@
2222

2323

2424
def next_proxy():
25-
return random.choices([
26-
'http://username:[email protected]:412345',
27-
'http://username:[email protected]:412346',
28-
'http://username:[email protected]:412347'
29-
])
25+
return random.choices(
26+
[
27+
"http://username:[email protected]:412345",
28+
"http://username:[email protected]:412346",
29+
"http://username:[email protected]:412347",
30+
]
31+
)
32+
3033

3134
cl = Client(proxy=next_proxy())
3235

3336
try:
34-
cl.login('USERNAME', 'PASSWORD')
37+
cl.login("USERNAME", "PASSWORD")
3538
except (ProxyError, HTTPError, GenericRequestError, ClientConnectionError):
3639
# Network level
3740
cl.set_proxy(next_proxy())

instagrapi/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,25 @@ class Client(
8484
TOTPMixin,
8585
MultipleAccountsMixin,
8686
NoteMixin,
87-
FundraiserMixin
87+
FundraiserMixin,
8888
):
8989
proxy = None
9090

91-
def __init__(self,
92-
settings: dict = {},
93-
proxy: str = None,
94-
delay_range: list = None,
95-
logger=DEFAULT_LOGGER,
96-
**kwargs):
91+
def __init__(
92+
self,
93+
settings: dict = {},
94+
proxy: str = None,
95+
delay_range: list = None,
96+
logger=DEFAULT_LOGGER,
97+
**kwargs,
98+
):
9799

98100
super().__init__(**kwargs)
99101

100102
self.settings = settings
101103
self.logger = logger
102104
self.delay_range = delay_range
103-
105+
104106
self.set_proxy(proxy)
105107

106108
self.init()

instagrapi/config.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"{dpi}; {resolution}; {manufacturer}; "
1111
"{model}; {device}; {cpu}; {locale}; {version_code})"
1212
)
13-
#Instagram 76.0.0.15.395 (iPhone9,2; iOS 10_0_2; en_US; en-US; scale=2.61; 1080x1920) AppleWebKit/420+
13+
# Instagram 76.0.0.15.395 (iPhone9,2; iOS 10_0_2; en_US; en-US; scale=2.61; 1080x1920) AppleWebKit/420+
1414
# Instagram 208.0.0.32.135 (iPhone; iOS 14_7_1; en_US; en-US; scale=2.61; 1080x1920) AppleWebKit/605.1.15
1515

16-
SOFTWARE = "{model}-user+{android_release}+OPR1.170623.032+V10.2.3.0.OAGMIXM+release-keys"
16+
SOFTWARE = (
17+
"{model}-user+{android_release}+OPR1.170623.032+V10.2.3.0.OAGMIXM+release-keys"
18+
)
1719

1820
# QUERY_HASH_PROFILE = 'c9100bf9110dd6361671f113dd02e7d6'
1921
# QUERY_HASH_MEDIAS = '42323d64886122307be10013ad2dcc44'
@@ -32,9 +34,9 @@
3234
SUPPORTED_CAPABILITIES = [
3335
{
3436
"value": "119.0,120.0,121.0,122.0,123.0,124.0,125.0,126.0,127.0,128.0,129.0,130.0,131.0,132.0,133.0,134.0,135.0,136.0,137.0,138.0,139.0,140.0,141.0,142.0",
35-
"name": "SUPPORTED_SDK_VERSIONS"
37+
"name": "SUPPORTED_SDK_VERSIONS",
3638
},
3739
{"value": "14", "name": "FACE_TRACKER_VERSION"},
3840
{"value": "ETC2_COMPRESSION", "name": "COMPRESSION"},
39-
{"value": "gyroscope_enabled", "name": "gyroscope"}
41+
{"value": "gyroscope_enabled", "name": "gyroscope"},
4042
]

0 commit comments

Comments
 (0)