tweepy-self 1.10.0b6__py3-none-any.whl → 1.10.0b7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tweepy-self
3
- Version: 1.10.0b6
3
+ Version: 1.10.0b7
4
4
  Summary: Twitter (selfbot) for Python!
5
5
  Home-page: https://github.com/alenkimov/tweepy-self
6
6
  Author: Alen
@@ -10,7 +10,7 @@ twitter/account.py,sha256=joAB5Zw-Le5E3kOZ-1nb4DPGlTqWYv2Vs6gJ3cwu7is,3175
10
10
  twitter/base/__init__.py,sha256=Q2ko0HeOS5tiBnDVKxxaZYetwRR3YXJ67ujL3oThGd4,141
11
11
  twitter/base/client.py,sha256=J_iL4ZGfwTbZ2gpjtFCbBxNgt7weJ55EeMGzYsLtjf4,500
12
12
  twitter/base/session.py,sha256=JFPS-9Qae1iY3NfNcywxvWWmRDijaU_Rjs3WaQ00iFA,2071
13
- twitter/client.py,sha256=zcW31OYf4Y9NvfgH2V5rnmdHXSa6tRFdxVuKvy_JyEw,70579
13
+ twitter/client.py,sha256=69QQb-ZnbjqpIhhozxsboruuy3MeJDUGM7nPEH-cBdg,73559
14
14
  twitter/enums.py,sha256=-OH6Ibxarq5qt4E2AhkProVawcEyIf5YG_h_G5xiV9Y,270
15
15
  twitter/errors.py,sha256=oNa0Neos80ZK4-0FBzqgxXonH564qFnoN-kavHalfR4,5274
16
16
  twitter/models.py,sha256=7yObMPUUEwJEbraHzFwmUKd91UhR2-zyfJTm4xIqrSQ,4834
@@ -18,6 +18,6 @@ twitter/utils/__init__.py,sha256=usxpfcRQ7zxTTgZ-i425tT7hIz73Pwh9FDj4t6O3dYg,663
18
18
  twitter/utils/file.py,sha256=Sz2KEF9DnL04aOP1XabuMYMMF4VR8dJ_KWMEVvQ666Y,1120
19
19
  twitter/utils/html.py,sha256=nrOJw0vUKfBaHgFaQSQIdXfvfZ8mdu84MU_s46kJTJ4,2087
20
20
  twitter/utils/other.py,sha256=9RIYF2AMdmNKIwClG3jBP7zlvxZPEgYfuHaIiOhURzM,1061
21
- tweepy_self-1.10.0b6.dist-info/METADATA,sha256=9RkGszuiywuEgKLozQNVo_usGEgJ3ismzwnsVGqZkc4,13153
22
- tweepy_self-1.10.0b6.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
23
- tweepy_self-1.10.0b6.dist-info/RECORD,,
21
+ tweepy_self-1.10.0b7.dist-info/METADATA,sha256=NpC2w-frRkmdX851z52xcAnsXX33NJ49pNuo21TIFUY,13153
22
+ tweepy_self-1.10.0b7.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
23
+ tweepy_self-1.10.0b7.dist-info/RECORD,,
twitter/client.py CHANGED
@@ -190,7 +190,6 @@ class Client(BaseHTTPClient):
190
190
  raise Locked(exc, self.account)
191
191
  raise exc
192
192
 
193
- self.account.status = AccountStatus.GOOD
194
193
  return response, data
195
194
 
196
195
  if response.status_code == 400:
@@ -1184,6 +1183,7 @@ class Client(BaseHTTPClient):
1184
1183
  url = "https://twitter.com/i/api/1.1/account/update_profile.json"
1185
1184
  try:
1186
1185
  await self.request("POST", url, auto_unlock=False, auto_relogin=False)
1186
+ self.account.status = AccountStatus.GOOD
1187
1187
  except BadAccount:
1188
1188
  pass
1189
1189
 
@@ -1422,6 +1422,11 @@ class Client(BaseHTTPClient):
1422
1422
 
1423
1423
  await self.establish_status()
1424
1424
 
1425
+ async def update_backup_code(self):
1426
+ url = "https://api.twitter.com/1.1/account/backup_code.json"
1427
+ response, response_json = await self.request("GET", url)
1428
+ self.account.backup_code = response_json["codes"][0]
1429
+
1425
1430
  async def _task(self, **kwargs):
1426
1431
  """
1427
1432
  :return: flow_token, subtasks
@@ -1550,18 +1555,27 @@ class Client(BaseHTTPClient):
1550
1555
  ]
1551
1556
  return await self._send_task(flow_token, subtask_inputs, auth=False)
1552
1557
 
1553
- async def _login_two_factor_auth_challenge(self, flow_token):
1554
- if not self.account.totp_secret:
1555
- raise TwitterException(
1556
- f"Failed to login. Task id: LoginTwoFactorAuthChallenge"
1557
- )
1558
-
1558
+ async def _login_two_factor_auth_challenge(self, flow_token, value: str):
1559
1559
  subtask_inputs = [
1560
1560
  {
1561
1561
  "subtask_id": "LoginTwoFactorAuthChallenge",
1562
1562
  "enter_text": {
1563
- "text": self.account.get_totp_code(),
1563
+ "text": value,
1564
+ "link": "next_link",
1565
+ },
1566
+ }
1567
+ ]
1568
+ return await self._send_task(flow_token, subtask_inputs, auth=False)
1569
+
1570
+ async def _login_two_factor_auth_choose_method(
1571
+ self, flow_token: str, choices: Iterable[int] = (0,)
1572
+ ):
1573
+ subtask_inputs = [
1574
+ {
1575
+ "subtask_id": "LoginTwoFactorAuthChooseMethod",
1576
+ "choice_selection": {
1564
1577
  "link": "next_link",
1578
+ "selected_choices": [str(choice) for choice in choices],
1565
1579
  },
1566
1580
  }
1567
1581
  ]
@@ -1601,7 +1615,9 @@ class Client(BaseHTTPClient):
1601
1615
  guest_token = re.search(r"gt\s?=\s?\d+", response.text)[0].split("=")[1]
1602
1616
  return guest_token
1603
1617
 
1604
- async def _login(self):
1618
+ async def _login(self) -> bool:
1619
+ update_backup_code = False
1620
+
1605
1621
  guest_token = await self._request_guest_token()
1606
1622
  self._session.headers["X-Guest-Token"] = guest_token
1607
1623
 
@@ -1616,7 +1632,7 @@ class Client(BaseHTTPClient):
1616
1632
 
1617
1633
  if "LoginEnterAlternateIdentifierSubtask" in subtask_ids:
1618
1634
  if not self.account.username:
1619
- raise ValueError("No username to relogin")
1635
+ raise TwitterException("Failed to login: no username to relogin")
1620
1636
 
1621
1637
  flow_token, subtasks = await self._login_enter_password(flow_token)
1622
1638
  flow_token, subtasks = await self._account_duplication_check(flow_token)
@@ -1628,11 +1644,50 @@ class Client(BaseHTTPClient):
1628
1644
  raise TwitterException(f"Failed to login: email verification!")
1629
1645
 
1630
1646
  if "LoginTwoFactorAuthChallenge" in subtask_ids:
1631
- flow_token, subtasks = await self._login_two_factor_auth_challenge(
1632
- flow_token
1633
- )
1647
+ if not self.account.totp_secret:
1648
+ raise TwitterException(
1649
+ f"Failed to login. Task id: LoginTwoFactorAuthChallenge. No totp_secret!"
1650
+ )
1651
+
1652
+ try:
1653
+ # fmt: off
1654
+ flow_token, subtasks = await self._login_two_factor_auth_challenge(flow_token, self.account.get_totp_code())
1655
+ # fmt: on
1656
+ except HTTPException as exc:
1657
+ if 399 in exc.api_codes:
1658
+ logger.warning(
1659
+ f"(auth_token={self.account.hidden_auth_token}, id={self.account.id}, username={self.account.username})"
1660
+ f" Bad TOTP secret!"
1661
+ )
1662
+ if not self.account.backup_code:
1663
+ raise TwitterException(
1664
+ f"Failed to login. Task id: LoginTwoFactorAuthChallenge. No backup code!"
1665
+ )
1666
+
1667
+ # Enter backup code
1668
+ # fmt: off
1669
+ flow_token, subtasks = await self._login_two_factor_auth_choose_method(flow_token)
1670
+ try:
1671
+ flow_token, subtasks = await self._login_two_factor_auth_challenge(flow_token, self.account.backup_code)
1672
+ except HTTPException as exc:
1673
+ if 399 in exc.api_codes:
1674
+ logger.warning(
1675
+ f"(auth_token={self.account.hidden_auth_token}, id={self.account.id}, username={self.account.username})"
1676
+ f" Bad backup code!"
1677
+ )
1678
+ raise TwitterException(
1679
+ f"Failed to login. Task id: LoginTwoFactorAuthChallenge. Bad backup_code!"
1680
+ )
1681
+ else:
1682
+ raise
1683
+
1684
+ update_backup_code = True
1685
+ # fmt: on
1686
+ else:
1687
+ raise
1634
1688
 
1635
1689
  await self._finish_task(flow_token)
1690
+ return update_backup_code
1636
1691
 
1637
1692
  async def relogin(self):
1638
1693
  """
@@ -1647,8 +1702,17 @@ class Client(BaseHTTPClient):
1647
1702
  if not self.account.password:
1648
1703
  raise ValueError("No password")
1649
1704
 
1650
- await self._login()
1705
+ update_backup_code = await self._login()
1651
1706
  await self._viewer()
1707
+
1708
+ if update_backup_code:
1709
+ await self.update_backup_code()
1710
+ logger.warning(
1711
+ f"(auth_token={self.account.hidden_auth_token}, id={self.account.id}, username={self.account.username})"
1712
+ f" Requested new backup code!"
1713
+ )
1714
+ # TODO Также обновлять totp_secret
1715
+
1652
1716
  await self.establish_status()
1653
1717
 
1654
1718
  async def login(self):