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
urlToPost = ""
validPost = True
content = "El gato siguió a la liebre. Esto es un texto de ejemplo."
content = ""
profilePic = "url"
timeStamp = "error"
userProfilePic = "1.png"
isReply = False
replyingUrl = "#"
replyingUser = "@nobody"
replyingTweetContent = ""
attachedImg = ""
replyAttachedImg = ""
class ytPost():
channelName = 'Error'

View File

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

View File

@ -2,12 +2,7 @@
<div class="content">
<div class="extra content">
<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 }}">
{%endif%}
</div>
<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>
{%endif%}
{% 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%}
</div>
<div class="description break-word">
<p>{{post.content}}</p>
</div>
<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>
<form class="ui form" action="{{ url_for('savePost', url=post.url.replace('/', '~')) }}" method="post">
<button type="submit" class="ui icon button">

View File

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