Twitter quotations are now shown

This commit is contained in:
pluja 2020-08-27 23:25:08 +02:00
parent 6b1ea94078
commit 386a80f118
4 changed files with 67 additions and 37 deletions

View File

@ -111,10 +111,16 @@ class twitterPost():
isRT = True isRT = True
urlToPost = "" urlToPost = ""
validPost = True validPost = True
content = "El gato siguió a la liebre. Esto es un texto de ejemplo." content = ""
profilePic = "url" profilePic = "url"
timeStamp = "error" timeStamp = "error"
userProfilePic = "1.png" userProfilePic = "1.png"
isReply = False
replyingUrl = "#"
replyingUser = "@nobody"
replyingTweetContent = ""
attachedImg = ""
replyAttachedImg = ""
class ytPost(): class ytPost():
channelName = 'Error' channelName = 'Error'

View File

@ -522,44 +522,55 @@ def getTwitterUserInfo(username):
return user return user
def getFeed(urls): def getFeed(urls):
avatarPath = "img/avatars/{}.png".format(str(random.randint(1,12)))
feedPosts = [] feedPosts = []
with FuturesSession() as session: with FuturesSession() as session:
futures = [session.get('{instance}{user}/rss'.format(instance=nitterInstance, user=u.username)) for u in urls] futures = [session.get('{instance}{user}'.format(instance=nitterInstance, user=u.username)) for u in urls]
for future in as_completed(futures): for future in as_completed(futures):
resp = future.result() res = future.result().content.decode('utf-8')
rssFeed=feedparser.parse(resp.content) html = BeautifulSoup(res, "html.parser")
if rssFeed.entries != []: userFeed = html.find_all('div', attrs={'class':'timeline-item'})
for post in rssFeed.entries: if userFeed != []:
time = datetime.datetime.now() - datetime.datetime(*post.published_parsed[:6]) for post in userFeed[:-1]:
if time.days >= 15: if post.find('div', attrs={'class':'pinned'}):
if post.find('div', attrs={'class':'pinned'}).find('span', attrs={'icon-pin'}):
continue
date_time_str = post.find('span', attrs={'class':'tweet-date'}).find('a')['title'].replace(",","")
time = datetime.datetime.now() - datetime.datetime.strptime(date_time_str, '%d/%m/%Y %H:%M:%S')
if time.days >= 14:
continue continue
newPost = twitterPost() newPost = twitterPost()
newPost.username = rssFeed.feed.title.split("/")[1].replace(" ", "") newPost.op = post.find('a', attrs={'class':'username'}).text
newPost.twitterName = rssFeed.feed.title.split("/")[0] newPost.twitterName = post.find('a', attrs={'class':'fullname'}).text
newPost.date = getTimeDiff(post.published_parsed) newPost.timeStamp = datetime.datetime.strptime(date_time_str, '%d/%m/%Y %H:%M:%S')
newPost.timeStamp = datetime.datetime(*post.published_parsed[:6]) newPost.date = post.find('span', attrs={'class':'tweet-date'}).find('a').text
newPost.op = post.author newPost.content = Markup(post.find('div', attrs={'class':'tweet-content'}))
try: if post.find('div', attrs={'class':'retweet-header'}):
newPost.userProfilePic = rssFeed.channel.image.url newPost.username = post.find('div', attrs={'class':'retweet-header'}).find('div', attrs={'class':'icon-container'}).text
except:
newPost.profilePicture = ""
newPost.url = post.link
newPost.content = Markup(post.description)
if "Pinned" in post.title.split(":")[0]:
newPost.isPinned = True
if "RT by" in post.title:
newPost.isRT = True newPost.isRT = True
newPost.profilePic = ""
else: else:
newPost.username = newPost.op
newPost.isRT = False newPost.isRT = False
try:
newPost.profilePic = rssFeed.channel.image.url newPost.profilePic = nitterInstance+post.find('a', attrs={'class':'tweet-avatar'}).find('img')['src'][1:]
except: newPost.url = nitterInstance + post.find('a', attrs={'class':'tweet-link'})['href'][1:]
newPost.profilePic = avatarPath if post.find('div', attrs={'class':'quote'}):
newPost.isReply = True
quote = post.find('div', attrs={'class':'quote'})
if quote.find('div', attrs={'class':'quote-text'}):
newPost.replyingTweetContent = Markup(quote.find('div', attrs={'class':'quote-text'}))
if quote.find('a', attrs={'class':'still-image'}):
newPost.replyAttachedImg = nitterInstance+quote.find('a', attrs={'class':'still-image'})['href'][1:]
newPost.replyingUser=quote.find('a', attrs={'class':'username'}).text
post.find('div', attrs={'class':'quote'}).decompose()
if post.find('div', attrs={'class':'attachments'}):
if not post.find(class_='quote'):
if post.find('div', attrs={'class':'attachments'}).find('a', attrs={'class':'still-image'}):
newPost.attachedImg = nitterInstance + post.find('div', attrs={'class':'attachments'}).find('a')['href'][1:]
feedPosts.append(newPost) feedPosts.append(newPost)
return feedPosts return feedPosts

View File

@ -2,12 +2,7 @@
<div class="content"> <div class="content">
<div class="extra content"> <div class="extra content">
<div class="left floated author"> <div class="left floated author">
{% if post.isRT %}
<img class="ui avatar image" src="{{ url_for('static',filename='img/avatars/')}}{{range(1, 12) | random}}.png">
{%else%}
<img class="ui avatar image" src="{{ post.profilePic }}"> <img class="ui avatar image" src="{{ post.profilePic }}">
{%endif%}
</div> </div>
<a href="{{post.url}}"><span class="right floated star"> <a href="{{post.url}}"><span class="right floated star">
@ -21,13 +16,31 @@
<span class="category" id="time"><i class="map pin icon"></i> Pinned </span> <span class="category" id="time"><i class="map pin icon"></i> Pinned </span>
{%endif%} {%endif%}
{% if post.isRT %} {% if post.isRT %}
<span class="category"><i class="retweet icon"></i> {{post.username}} retwitted</span> <span class="category"><i class="retweet icon"></i> {{post.username}}</span>
{%endif%} {%endif%}
</div> </div>
<div class="description break-word"> <div class="description break-word">
<p>{{post.content}}</p> <p>{{post.content}}</p>
</div> </div>
<div class="extra content"> <div class="extra content">
{% if post.attachedImg != "" %}
<img class="ui centered medium image" src="{{post.attachedImg}}">
{% endif %}
{% if post.isReply %}
<div class="ui card">
<div class="content">
<div class="header">{{post.replyingUser}}</div>
<div class="meta">{{post.replyingUser}}</div>
<div class="description break-word">
{{post.replyingTweetContent}}
{% if post.replyAttachedImg != "" %}
<img class="ui centered medium image" src="{{post.replyAttachedImg}}">
{% endif %}
</div>
</div>
</div>
{% endif %}
<p> <p>
<form class="ui form" action="{{ url_for('savePost', url=post.url.replace('/', '~')) }}" method="post"> <form class="ui form" action="{{ url_for('savePost', url=post.url.replace('/', '~')) }}" method="post">
<button type="submit" class="ui icon button"> <button type="submit" class="ui icon button">

View File

@ -6,7 +6,7 @@
<div class="ui text container"> <div class="ui text container">
<video class="video-js vjs-default-skin" <video class="video-js vjs-default-skin"
data-setup='{ "playbackRates": [0.5, 1, 1.25,1.5, 2] }' data-setup='{ "playbackRates": [0.5, 1, 1.25,1.5, 2] }'
width="720" height="420" width="72%"
controls controls
preload="auto"> preload="auto">
<source src="/stream?v={{video.id}}" type="video/mp4"> <source src="/stream?v={{video.id}}" type="video/mp4">