Przeglądaj źródła

Fix a bug with "ghost" tweets

theenglishway (time) 7 lat temu
rodzic
commit
6242f756b6
3 zmienionych plików z 16 dodań i 12 usunięć
  1. 1 4
      twhatter/__main__.py
  2. 10 6
      twhatter/cli.py
  3. 5 2
      twhatter/parser/tweet.py

+ 1 - 4
twhatter/__main__.py

@@ -6,8 +6,5 @@ from twhatter.output import Print
 user="the_english_way"
 a = ApiUser(user)
 
-for t in a.iter_own_tweets():
-    Print(t)()
-
-for t in a.iter_all_tweets():
+for t in a.iter_tweets():
     Print(t)()

+ 10 - 6
twhatter/cli.py

@@ -1,3 +1,4 @@
+#!/usr/bin/env python
 # coding: utf-8
 
 """Console script for twhatter."""
@@ -6,12 +7,15 @@ import click
 from twhatter.api import ApiUser
 
 
-@click.command()
-@click.option('--user', prompt='User name to check',
-              help='The person to greet.')
-@click.option('-r', '--replies', is_flag=True)
-def main(user, replies):
-    """Console script for twhatter."""
+@click.group()
+def main():
+    pass
+
+
+@main.command()
+@click.argument('user')
+def own(user):
+    """Get all the user's own publications"""
     a = ApiUser(user)
 
     for t in a.iter_tweets():

+ 5 - 2
twhatter/parser/tweet.py

@@ -37,7 +37,7 @@ class Tweet:
     @staticmethod
     def extract_timestamp(soup):
         return datetime.utcfromtimestamp(
-            int(soup.find('span', '_timestamp')['data-time'])
+            int(soup.find('span', attrs={'data-time': True})['data-time'])
         )
 
     @staticmethod
@@ -104,7 +104,10 @@ class TweetList:
 
     def __iter__(self):
         for tweet in self.raw_tweets:
-            yield Tweet.extract(tweet)
+            # Don't know what this u-dir stuff is about but if it's in there,
+            # it's not a tweet !
+            if not tweet.find_all('p', class_="u-dir"):
+                yield Tweet.extract(tweet)
 
     def __len__(self):
         return len(self.raw_tweets)