Skip to content

Commit a129be3

Browse files
author
mattew
committed
fixed tweet count
1 parent e2b70ea commit a129be3

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Get twpy current version :
5656

5757
```python
5858
tc.__version__
59-
# '1.2.2'
59+
# '1.2.3'
6060
```
6161

6262

twpy/config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "1.2.2"
1+
VERSION = "1.2.3"
22
BASE_URL = "https://twitter.com/"
33
MOBILE_URL = "https://mobile.twitter.com/"
44
TIMELINE_WITH_TOKEN_QUERY = "i/search/timeline?vertical=default&src=unkn&include_available_features=1&include_entities=1" \

twpy/utils/__init__.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,32 @@ def extract_profile(html: str) -> object:
157157
# get user id
158158
user_id = navbar.find('div', attrs={'class': 'ProfileNav'})["data-user-id"]
159159
# find tweets count
160-
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--tweets is-active'})
161-
tweet_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
160+
try:
161+
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--tweets is-active'})
162+
tweet_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
163+
except AttributeError:
164+
tweet_count = 0
165+
162166
# find followings
163-
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--following'})
164-
following_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
167+
try:
168+
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--following'})
169+
following_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
170+
except AttributeError:
171+
following_count = 0
172+
165173
# find followers
166-
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--followers'})
167-
follower_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
174+
try:
175+
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--followers'})
176+
follower_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
177+
except AttributeError:
178+
follower_count = 0
179+
168180
# find likes
169-
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--favorites'})
170-
like_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
181+
try:
182+
li_ = navbar.find('li', attrs={'class': 'ProfileNav-item ProfileNav-item--favorites'})
183+
like_count = li_.find('span', attrs={'class': 'ProfileNav-value'}).text.strip()
184+
except AttributeError:
185+
like_count = 0
171186
#
172187
result.append(Profile(
173188
name=name,

0 commit comments

Comments
 (0)