Bladeren bron

Handle links

theenglishway (time) 7 jaren geleden
bovenliggende
commit
d70c8254a4
2 gewijzigde bestanden met toevoegingen van 13 en 7 verwijderingen
  1. 3 1
      tests/conftest.py
  2. 10 6
      twhatter/parser/tweet.py

+ 3 - 1
tests/conftest.py

@@ -42,6 +42,7 @@ class TweetInfo(NamedTuple):
     retweet_id: int = None
     reacted_id: int = None
     reacted_user_id: int = None
+    link_to: str = None
 
 @pytest.fixture(scope="session")
 def tweet_collection():
@@ -69,7 +70,8 @@ def tweet_collection():
             screen_name="the_english_way",
             user_id=943804775942033408,
             timestamp=datetime.utcfromtimestamp(1545732331),
-            permalink="/the_english_way/status/1077505613079429120"
+            permalink="/the_english_way/status/1077505613079429120",
+            link_to="https://t.co/el5VJucLRz"
         ),
         'retweet': TweetInfo(
             id=1055037291108974592,

+ 10 - 6
twhatter/parser/tweet.py

@@ -35,6 +35,9 @@ class Tweet:
     #: Id of the user that the tweet is in reaction to
     reacted_user_id: int = None
 
+    #: Link contained within the tweet
+    link_to: str = None
+
     #: The soup extracted from the raw HTML
     soup: InitVar[BeautifulSoup] = None
 
@@ -100,6 +103,13 @@ class Tweet:
         except TypeError:
             return None
 
+    @classmethod
+    def extract_link_to(cls, soup):
+        try:
+            return cls._extract_from_div(soup, 'card-type-summary', 'card-url')
+        except TypeError:
+            return None
+
     @staticmethod
     def extract_timestamp(soup):
         return datetime.utcfromtimestamp(
@@ -142,12 +152,6 @@ class Tweet:
     def extract_text(soup):
         return soup.find('p', 'tweet-text').text
 
-    @staticmethod
-    def extract_quoted_tweet(soup):
-        return int(soup.find(
-            'span', 'QuoteTweet-innerContainer').find(
-                'span', 'ProfileTweet-actionCount')['data-tweet-stat-count']),
-
     @staticmethod
     def extract_soup(soup):
         return soup