tweepy-self 1.5.4__py3-none-any.whl → 1.6.0__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.5.4
3
+ Version: 1.6.0
4
4
  Summary: Twitter (selfbot) for Python!
5
5
  Author: Alen
6
6
  Author-email: alen.kimov@gmail.com
@@ -3,14 +3,14 @@ twitter/account.py,sha256=tHzBdc34pEJI2SRbjLcmKtwAzjhzUFsa4vIQqtXAc1s,3015
3
3
  twitter/base/__init__.py,sha256=x0EHKv4q_FI6xEq2nL4V9s8P6VWr6IaHTqdH9sXB5d8,133
4
4
  twitter/base/client.py,sha256=7byb0Psai-dvg_ww6Y7uyE2hV1pfTU653hFgVdRiqXo,478
5
5
  twitter/base/session.py,sha256=JFPS-9Qae1iY3NfNcywxvWWmRDijaU_Rjs3WaQ00iFA,2071
6
- twitter/client.py,sha256=6n-XUZA-6alpV2k3swHhIL84P7-5zKgzDnqW5sYP720,58728
6
+ twitter/client.py,sha256=qfIQrzGb-dju2lTaKX820zGDADv8PmsS5cIhEk9p8oE,60960
7
7
  twitter/enums.py,sha256=-OH6Ibxarq5qt4E2AhkProVawcEyIf5YG_h_G5xiV9Y,270
8
- twitter/errors.py,sha256=Y7Cn-jTBKcESNZfbwjy90kPmQwkyeRIZIVsW5kctGN0,4907
9
- twitter/models.py,sha256=9ZupMWy7nl7LFUNzLiRD0uDUbZCR6OwCbZt0VETCjns,2035
8
+ twitter/errors.py,sha256=PsvGP3hps1HNWdKbUPhEkuDqLUmmqzhpAkRtVrJr5jc,5007
9
+ twitter/models.py,sha256=ttSNuhY1knTdI-Yty54OCJF5YzARc8IaA11zKNHV9p0,2063
10
10
  twitter/utils/__init__.py,sha256=pyhQXwTdp0HFwV_UNF4dTyklLD9RtaefA16SrQXeNlg,589
11
11
  twitter/utils/file.py,sha256=Sz2KEF9DnL04aOP1XabuMYMMF4VR8dJ_KWMEVvQ666Y,1120
12
12
  twitter/utils/html.py,sha256=hVtIRFI2yRAdWEaShFNBG-_ZWxd16og8i8OVDnFy5Hc,1971
13
13
  twitter/utils/other.py,sha256=UnUxS3uDR4eggbNN16xiw96VC_MNt9tOgnBlNWvRBoY,559
14
- tweepy_self-1.5.4.dist-info/METADATA,sha256=LZMLxfYg3Ck9A6T8CAPztL6-Ow6RvZky7vOkWPFTi7U,9136
15
- tweepy_self-1.5.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
16
- tweepy_self-1.5.4.dist-info/RECORD,,
14
+ tweepy_self-1.6.0.dist-info/METADATA,sha256=v5tR7xSal8DNv3iwMStoxzc-jtLnSrHUX90pxDaN0Ik,9136
15
+ tweepy_self-1.6.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
16
+ tweepy_self-1.6.0.dist-info/RECORD,,
twitter/client.py CHANGED
@@ -11,6 +11,7 @@ from python3_capsolver.fun_captcha import FunCaptcha, FunCaptchaTypeEnm
11
11
 
12
12
  from .errors import (
13
13
  TwitterException,
14
+ FailedToFindDuplicatePost,
14
15
  HTTPException,
15
16
  BadRequest,
16
17
  Unauthorized,
@@ -24,7 +25,7 @@ from .errors import (
24
25
  ConsentLocked,
25
26
  Suspended,
26
27
  )
27
- from .utils import to_json
28
+ from .utils import to_json, tweet_url as create_tweet_url
28
29
  from .base import BaseClient
29
30
  from .account import Account, AccountStatus
30
31
  from .models import UserData, Tweet
@@ -520,7 +521,7 @@ class Client(BaseClient):
520
521
  media_id: int | str = None,
521
522
  tweet_id_to_reply: str | int = None,
522
523
  attachment_url: str = None,
523
- ) -> int:
524
+ ) -> Tweet:
524
525
  url, query_id = self._action_to_url("CreateTweet")
525
526
  payload = {
526
527
  "variables": {
@@ -564,32 +565,103 @@ class Client(BaseClient):
564
565
  )
565
566
 
566
567
  response, response_json = await self.request("POST", url, json=payload)
567
- tweet_id = response_json["data"]["create_tweet"]["tweet_results"]["result"][
568
- "rest_id"
569
- ]
570
- return tweet_id
568
+ tweet = Tweet.from_raw_data(
569
+ response_json["data"]["create_tweet"]["tweet_results"]["result"]
570
+ )
571
+ return tweet
571
572
 
572
- async def tweet(self, text: str, *, media_id: int | str = None) -> int:
573
- """
574
- :return: Tweet ID
575
- """
576
- return await self._tweet(text, media_id=media_id)
573
+ async def _tweet_or_search_duplicate(
574
+ self,
575
+ text: str = None,
576
+ *,
577
+ media_id: int | str = None,
578
+ tweet_id_to_reply: str | int = None,
579
+ attachment_url: str = None,
580
+ search_duplicate: bool = True,
581
+ with_tweet_url: bool = True,
582
+ ) -> Tweet:
583
+ try:
584
+ tweet = await self._tweet(
585
+ text,
586
+ media_id=media_id,
587
+ tweet_id_to_reply=tweet_id_to_reply,
588
+ attachment_url=attachment_url,
589
+ )
590
+ except HTTPException as exc:
591
+ if (
592
+ search_duplicate
593
+ and 187 in exc.api_codes # duplicate tweet (Status is a duplicate)
594
+ ):
595
+ tweets = await self.request_tweets(self.account.id)
596
+ duplicate_tweet = None
597
+ for tweet_ in tweets:
598
+ if tweet_.full_text == text:
599
+ duplicate_tweet = tweet_
600
+
601
+ if not duplicate_tweet:
602
+ raise FailedToFindDuplicatePost(
603
+ f"Couldn't find a post duplicate in the next 20 posts"
604
+ )
605
+ tweet = duplicate_tweet
606
+
607
+ else:
608
+ raise
609
+
610
+ if with_tweet_url:
611
+ if not self.account.username:
612
+ await self.request_user_data()
613
+ tweet.url = create_tweet_url(self.account.username, tweet.id)
614
+
615
+ return tweet
616
+
617
+ async def tweet(
618
+ self,
619
+ text: str,
620
+ *,
621
+ media_id: int | str = None,
622
+ search_duplicate: bool = True,
623
+ with_tweet_url: bool = True,
624
+ ) -> Tweet:
625
+ return await self._tweet_or_search_duplicate(
626
+ text,
627
+ media_id=media_id,
628
+ search_duplicate=search_duplicate,
629
+ with_tweet_url=with_tweet_url,
630
+ )
577
631
 
578
632
  async def reply(
579
- self, tweet_id: str | int, text: str, *, media_id: int | str = None
580
- ) -> int:
581
- """
582
- :return: Tweet ID
583
- """
584
- return await self._tweet(text, media_id=media_id, tweet_id_to_reply=tweet_id)
633
+ self,
634
+ tweet_id: str | int,
635
+ text: str,
636
+ *,
637
+ media_id: int | str = None,
638
+ search_duplicate: bool = True,
639
+ with_tweet_url: bool = True,
640
+ ) -> Tweet:
641
+ return await self._tweet_or_search_duplicate(
642
+ text,
643
+ media_id=media_id,
644
+ tweet_id_to_reply=tweet_id,
645
+ search_duplicate=search_duplicate,
646
+ with_tweet_url=with_tweet_url,
647
+ )
585
648
 
586
649
  async def quote(
587
- self, tweet_url: str, text: str, *, media_id: int | str = None
588
- ) -> int:
589
- """
590
- :return: Tweet ID
591
- """
592
- return await self._tweet(text, media_id=media_id, attachment_url=tweet_url)
650
+ self,
651
+ tweet_url: str,
652
+ text: str,
653
+ *,
654
+ media_id: int | str = None,
655
+ search_duplicate: bool = True,
656
+ with_tweet_url: bool = True,
657
+ ) -> Tweet:
658
+ return await self._tweet_or_search_duplicate(
659
+ text,
660
+ media_id=media_id,
661
+ attachment_url=tweet_url,
662
+ search_duplicate=search_duplicate,
663
+ with_tweet_url=with_tweet_url,
664
+ )
593
665
 
594
666
  async def vote(
595
667
  self, tweet_id: int | str, card_id: int | str, choice_number: int
twitter/errors.py CHANGED
@@ -4,6 +4,7 @@ from .account import Account
4
4
 
5
5
  __all__ = [
6
6
  "TwitterException",
7
+ "FailedToFindDuplicatePost",
7
8
  "HTTPException",
8
9
  "BadRequest",
9
10
  "Unauthorized",
@@ -23,6 +24,10 @@ class TwitterException(Exception):
23
24
  pass
24
25
 
25
26
 
27
+ class FailedToFindDuplicatePost(TwitterException):
28
+ pass
29
+
30
+
26
31
  def _http_exception_message(
27
32
  response: requests.Response,
28
33
  api_errors: list[dict],
twitter/models.py CHANGED
@@ -47,6 +47,7 @@ class Tweet(BaseModel):
47
47
  retweet_count: int
48
48
  retweeted: bool
49
49
  raw_data: dict
50
+ url: str | None = None
50
51
 
51
52
  def __str__(self):
52
53
  short_text = (