tweepy-self 1.10.0b6__tar.gz → 1.10.0b7__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/PKG-INFO +1 -1
  2. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/pyproject.toml +1 -1
  3. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/client.py +78 -14
  4. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/README.md +0 -0
  5. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/__init__.py +0 -0
  6. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/_capsolver/__init__.py +0 -0
  7. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/_capsolver/core/__init__.py +0 -0
  8. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/_capsolver/core/base.py +0 -0
  9. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/_capsolver/core/config.py +0 -0
  10. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/_capsolver/core/enum.py +0 -0
  11. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/_capsolver/core/serializer.py +0 -0
  12. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/_capsolver/fun_captcha.py +0 -0
  13. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/account.py +0 -0
  14. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/base/__init__.py +0 -0
  15. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/base/client.py +0 -0
  16. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/base/session.py +0 -0
  17. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/enums.py +0 -0
  18. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/errors.py +0 -0
  19. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/models.py +0 -0
  20. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/utils/__init__.py +0 -0
  21. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/utils/file.py +0 -0
  22. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/utils/html.py +0 -0
  23. {tweepy_self-1.10.0b6 → tweepy_self-1.10.0b7}/twitter/utils/other.py +0 -0
@@ -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
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "tweepy-self"
3
- version = "1.10.0.b6"
3
+ version = "1.10.0.b7"
4
4
  description = "Twitter (selfbot) for Python!"
5
5
  authors = ["Alen <alen.kimov@gmail.com>"]
6
6
  readme = "README.md"
@@ -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):
File without changes