tweepy-self 1.10.0b5__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.0b5
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=p5opgzbjmG8kD52BwLELVokXHFC_CQwtKeOUfJcPuMo,69935
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.0b5.dist-info/METADATA,sha256=y0MCWG3yt9HC5rjqFDI5w3VAMJ9iu3oIsFdfhE8kEaM,13153
22
- tweepy_self-1.10.0b5.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
23
- tweepy_self-1.10.0b5.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:
@@ -296,6 +295,7 @@ class Client(BaseHTTPClient):
296
295
  async def on_startup(self):
297
296
  if self._update_account_info_on_startup:
298
297
  await self.update_account_info()
298
+ await self.establish_status()
299
299
 
300
300
  async def _request_oauth2_auth_code(
301
301
  self,
@@ -1183,6 +1183,7 @@ class Client(BaseHTTPClient):
1183
1183
  url = "https://twitter.com/i/api/1.1/account/update_profile.json"
1184
1184
  try:
1185
1185
  await self.request("POST", url, auto_unlock=False, auto_relogin=False)
1186
+ self.account.status = AccountStatus.GOOD
1186
1187
  except BadAccount:
1187
1188
  pass
1188
1189
 
@@ -1421,6 +1422,11 @@ class Client(BaseHTTPClient):
1421
1422
 
1422
1423
  await self.establish_status()
1423
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
+
1424
1430
  async def _task(self, **kwargs):
1425
1431
  """
1426
1432
  :return: flow_token, subtasks
@@ -1516,8 +1522,8 @@ class Client(BaseHTTPClient):
1516
1522
  "key": "user_identifier",
1517
1523
  "response_data": {
1518
1524
  "text_data": {
1519
- "result": self.account.email
1520
- or self.account.username
1525
+ "result": self.account.username
1526
+ or self.account.email
1521
1527
  }
1522
1528
  },
1523
1529
  }
@@ -1549,18 +1555,27 @@ class Client(BaseHTTPClient):
1549
1555
  ]
1550
1556
  return await self._send_task(flow_token, subtask_inputs, auth=False)
1551
1557
 
1552
- async def _login_two_factor_auth_challenge(self, flow_token):
1553
- if not self.account.totp_secret:
1554
- raise TwitterException(
1555
- f"Failed to login. Task id: LoginTwoFactorAuthChallenge"
1556
- )
1557
-
1558
+ async def _login_two_factor_auth_challenge(self, flow_token, value: str):
1558
1559
  subtask_inputs = [
1559
1560
  {
1560
1561
  "subtask_id": "LoginTwoFactorAuthChallenge",
1561
1562
  "enter_text": {
1562
- "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": {
1563
1577
  "link": "next_link",
1578
+ "selected_choices": [str(choice) for choice in choices],
1564
1579
  },
1565
1580
  }
1566
1581
  ]
@@ -1600,7 +1615,9 @@ class Client(BaseHTTPClient):
1600
1615
  guest_token = re.search(r"gt\s?=\s?\d+", response.text)[0].split("=")[1]
1601
1616
  return guest_token
1602
1617
 
1603
- async def _login(self):
1618
+ async def _login(self) -> bool:
1619
+ update_backup_code = False
1620
+
1604
1621
  guest_token = await self._request_guest_token()
1605
1622
  self._session.headers["X-Guest-Token"] = guest_token
1606
1623
 
@@ -1610,6 +1627,13 @@ class Client(BaseHTTPClient):
1610
1627
  flow_token, subtasks = await self._request_login_tasks()
1611
1628
  for _ in range(2):
1612
1629
  flow_token, subtasks = await self._login_enter_user_identifier(flow_token)
1630
+
1631
+ subtask_ids = [subtask["subtask_id"] for subtask in subtasks]
1632
+
1633
+ if "LoginEnterAlternateIdentifierSubtask" in subtask_ids:
1634
+ if not self.account.username:
1635
+ raise TwitterException("Failed to login: no username to relogin")
1636
+
1613
1637
  flow_token, subtasks = await self._login_enter_password(flow_token)
1614
1638
  flow_token, subtasks = await self._account_duplication_check(flow_token)
1615
1639
 
@@ -1620,21 +1644,75 @@ class Client(BaseHTTPClient):
1620
1644
  raise TwitterException(f"Failed to login: email verification!")
1621
1645
 
1622
1646
  if "LoginTwoFactorAuthChallenge" in subtask_ids:
1623
- flow_token, subtasks = await self._login_two_factor_auth_challenge(
1624
- flow_token
1625
- )
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
1626
1688
 
1627
1689
  await self._finish_task(flow_token)
1690
+ return update_backup_code
1628
1691
 
1629
1692
  async def relogin(self):
1693
+ """
1694
+ Может вызвать следующую ошибку:
1695
+ twitter.errors.BadRequest: (response status: 400)
1696
+ (code 398) Can't complete your signup right now.
1697
+ Причина возникновения ошибки неизвестна. Не забудьте обработать ее.
1698
+ """
1630
1699
  if not self.account.email and not self.account.username:
1631
1700
  raise ValueError("No email or username")
1632
1701
 
1633
1702
  if not self.account.password:
1634
1703
  raise ValueError("No password")
1635
1704
 
1636
- await self._login()
1705
+ update_backup_code = await self._login()
1637
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
+
1638
1716
  await self.establish_status()
1639
1717
 
1640
1718
  async def login(self):