Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Add Config.StripeTweetText #1365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions twint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ class Config:
Bearer_token: str = None
Guest_token: str = None
deleted: list = None
StripeTweetText: bool = True
7 changes: 4 additions & 3 deletions twint/tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ def _get_reply_to(tw):
return reply_to


def getText(tw):
def getText(tw, config):
"""Replace some text
"""
logme.debug(__name__ + ':getText')
text = tw['full_text']
text = text.replace("http", " http")
text = text.replace("pic.twitter", " pic.twitter")
text = text.replace("\n", " ")
if config.StripeTweetText:
text = text.replace("\n", " ")

return text

Expand Down Expand Up @@ -115,7 +116,7 @@ def Tweet(tw, config):
t.thumbnail = tw['extended_entities']['media'][0]['media_url_https']
except KeyError:
t.thumbnail = ''
t.tweet = getText(tw)
t.tweet = getText(tw, config)
t.lang = tw['lang']
try:
t.hashtags = [hashtag['text'] for hashtag in tw['entities']['hashtags']]
Expand Down
52 changes: 29 additions & 23 deletions twint/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,35 @@ def User(ur):
raise KeyError(msg)
_usr = user()
_usr.id = ur['data']['user']['rest_id']
_usr.name = ur['data']['user']['legacy']['name']
_usr.username = ur['data']['user']['legacy']['screen_name']
_usr.bio = ur['data']['user']['legacy']['description']
_usr.location = ur['data']['user']['legacy']['location']
_usr.url = ur['data']['user']['legacy']['url']
# parsing date to user-friendly format
_dt = ur['data']['user']['legacy']['created_at']
_dt = datetime.datetime.strptime(_dt, '%a %b %d %H:%M:%S %z %Y')
# date is of the format year,
_usr.join_date = _dt.strftime(User_formats['join_date'])
_usr.join_time = _dt.strftime(User_formats['join_time'])

# :type `int`
_usr.tweets = int(ur['data']['user']['legacy']['statuses_count'])
_usr.following = int(ur['data']['user']['legacy']['friends_count'])
_usr.followers = int(ur['data']['user']['legacy']['followers_count'])
_usr.likes = int(ur['data']['user']['legacy']['favourites_count'])
_usr.media_count = int(ur['data']['user']['legacy']['media_count'])

_usr.is_private = ur['data']['user']['legacy']['protected']
_usr.is_verified = ur['data']['user']['legacy']['verified']
_usr.avatar = ur['data']['user']['legacy']['profile_image_url_https']
_usr.background_image = ur['data']['user']['legacy']['profile_banner_url']

if ur['data']['user'].get('legacy'):
_usr.name = ur['data']['user']['legacy'].get('name', '')
_usr.username = ur['data']['user']['legacy'].get('screen_name', '')
_usr.bio = ur['data']['user']['legacy'].get('description', '')
_usr.location = ur['data']['user']['legacy'].get('location', '')
_usr.url = ur['data']['user']['legacy'].get('url', '')
# parsing date to user-friendly format
_dt = ur['data']['user']['legacy'].get('created_at')
if _dt:
_dt = datetime.datetime.strptime(_dt, '%a %b %d %H:%M:%S %z %Y')
# date is of the format year,
_usr.join_date = _dt.strftime(User_formats['join_date'])
_usr.join_time = _dt.strftime(User_formats['join_time'])

# :type `int`
_usr.tweets = int(ur['data']['user']['legacy'].get('statuses_count', 0))
_usr.following = int(ur['data']['user']['legacy'].get('friends_count', 0))
_usr.followers = int(ur['data']['user']['legacy'].get('followers_count', 0))
_usr.likes = int(ur['data']['user']['legacy'].get('favourites_count', 0))
_usr.media_count = int(ur['data']['user']['legacy'].get('media_count', 0))
_usr.listed_count = int(ur['data']['user']['legacy'].get('listed_count', 0))

_usr.is_private = ur['data']['user']['legacy'].get('protected')
_usr.is_verified = ur['data']['user']['legacy'].get('verified')
_usr.avatar = ur['data']['user']['legacy'].get('profile_image_url_https', '')
_usr.background_image = ur['data']['user']['legacy'].get('profile_banner_url')
_usr.entities = ur['data']['user']['legacy'].get('entities')

# TODO : future implementation
# legacy_extended_profile is also available in some cases which can be used to get DOB of user
return _usr