Skip to content

Commit

Permalink
fixed tweet count
Browse files Browse the repository at this point in the history
  • Loading branch information
mattew committed Jan 4, 2020
1 parent e2b70ea commit a129be3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Get twpy current version :

```python
tc.__version__
# '1.2.2'
# '1.2.3'
```


Expand Down
2 changes: 1 addition & 1 deletion twpy/config/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "1.2.2"
VERSION = "1.2.3"
BASE_URL = "https://twitter.com/"
MOBILE_URL = "https://mobile.twitter.com/"
TIMELINE_WITH_TOKEN_QUERY = "i/search/timeline?vertical=default&src=unkn&include_available_features=1&include_entities=1" \
Expand Down
31 changes: 23 additions & 8 deletions twpy/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,32 @@ def extract_profile(html: str) -> object:
# get user id
user_id = navbar.find('div', attrs={'class': 'ProfileNav'})["data-user-id"]
# find tweets count
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--tweets is-active'})
tweet_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
try:
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--tweets is-active'})
tweet_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
except AttributeError:
tweet_count = 0

# find followings
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--following'})
following_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
try:
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--following'})
following_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
except AttributeError:
following_count = 0

# find followers
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--followers'})
follower_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
try:
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--followers'})
follower_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
except AttributeError:
follower_count = 0

# find likes
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--favorites'})
like_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
try:
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--favorites'})
like_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
except AttributeError:
like_count = 0
#
result.append(Profile(
name=name,
Expand Down

0 comments on commit a129be3

Please sign in to comment.