Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit eb05c5a

Browse files
committed
New version 1.2.3
Changing some messages Return error message in case of not be successfully in request
1 parent 3e1755c commit eb05c5a

2 files changed

Lines changed: 28 additions & 26 deletions

File tree

ItsAGramLive/ItsAGramLive.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def login(self, force=False):
118118
return False
119119

120120
def two_factor(self):
121-
print("Two factor required")
122121
# verification_method': 0 works for sms and TOTP. why? ¯\_ಠ_ಠ_/¯
123122
verification_code = input('Enter verification code: ')
124123
data = {
@@ -131,8 +130,7 @@ def two_factor(self):
131130
'device_id': self.device_id,
132131
'guid': self.uuid,
133132
}
134-
if self.send_request('accounts/two_factor_login/', self.generate_signature(json.dumps(data)),
135-
login=True):
133+
if self.send_request('accounts/two_factor_login/', self.generate_signature(json.dumps(data)), login=True):
136134
return True
137135
else:
138136
return False
@@ -153,27 +151,29 @@ def send_request(self, endpoint, post=None, login=False):
153151
while True:
154152
try:
155153
if post is not None:
156-
response = self.s.post(self.API_URL + endpoint, data=post, verify=verify)
154+
self.LastResponse = self.s.post(self.API_URL + endpoint, data=post, verify=verify)
157155
else:
158-
response = self.s.get(self.API_URL + endpoint, verify=verify)
156+
self.LastResponse = self.s.get(self.API_URL + endpoint, verify=verify)
157+
158+
self.LastJson = json.loads(self.LastResponse.text)
159+
159160
break
160161
except Exception as e:
161-
print('Except on SendRequest (wait 60 sec and resend): {}'.format(str(e)))
162+
print('* Except on SendRequest (wait 60 sec and resend): {}'.format(str(e)))
162163
time.sleep(60)
163164

164-
if response.status_code in [200, 400]:
165-
self.LastResponse = response
166-
self.LastJson = json.loads(response.text)
165+
if self.LastResponse.status_code == 200:
167166
return True
167+
elif 'two_factor_required' in self.LastJson and self.LastResponse.status_code == 400:
168+
# even the status code isn't 200 return True if the 2FA is required
169+
if self.LastJson['two_factor_required']:
170+
print("Two factor required")
171+
return True
168172
else:
169-
print("Request return " + str(response.status_code) + " error!")
170-
# for debugging
171-
try:
172-
self.LastResponse = response
173-
self.LastJson = json.loads(response.text)
174-
print(self.LastJson)
175-
except:
176-
pass
173+
error_message = " - "
174+
if "message" in self.LastJson:
175+
error_message = self.LastJson['message']
176+
print('* ERROR({}): {}'.format(self.LastResponse.status_code, error_message))
177177
return False
178178

179179
def set_proxy(self, proxy=None):
@@ -193,16 +193,18 @@ def generate_signature(self, data, skip_quote=False):
193193
self.IG_SIG_KEY.encode('utf-8'), data.encode('utf-8'), hashlib.sha256).hexdigest() + '.' + parsed_data
194194

195195
def start(self):
196-
print('logging in...')
196+
print("Let's do it!")
197197
if self.login():
198-
print('logged in!!')
199-
print('Generating stream upload_url and keys...\n')
198+
print("You'r logged in")
199+
200200
if self.create_broadcast():
201-
print("Broadcast ID: {}".format(self.broadcast_id))
202-
print("Server URL: {}".format(self.stream_server))
203-
print("Server Key: {}".format(self.stream_key))
201+
print("Broadcast ID: {}")
202+
print("* Broadcast ID: {}".format(self.broadcast_id))
203+
print("* Server URL: {}".format(self.stream_server))
204+
print("* Server Key: {}".format(self.stream_key))
205+
print("The stream key was automatically copied to your clipboard")
204206

205-
input('Press Enter after your setting your streaming software.')
207+
print("Press Enter after your setting your streaming software.")
206208
if self.start_broadcast():
207209
self.is_running = True
208210

@@ -396,4 +398,4 @@ def stop(self):
396398
def get_comments(self):
397399
if self.send_request("live/{}/get_comment/".format(self.broadcast_id)):
398400
for comment in self.LastJson['comments']:
399-
print(f"{comment['user']['username']} has posted a new comment: {comment['text']}")
401+
print(f"{comment['user']['username']} has posted a new comment: {comment['text']}")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setuptools.setup(
1212
name='ItsAGramLive',
13-
version='1.2.2',
13+
version='1.2.3',
1414
packages=setuptools.find_packages(),
1515
url='https://github.com/harrypython/itsagramlive',
1616
license='GPL-3.0',

0 commit comments

Comments
 (0)