From 386a80f11886adfc30761ed42b3df14bb84e050f Mon Sep 17 00:00:00 2001 From: pluja Date: Thu, 27 Aug 2020 23:25:08 +0200 Subject: [PATCH] Twitter quotations are now shown --- app/models.py | 8 +++- app/routes.py | 69 ++++++++++++++++++-------------- app/templates/_twitter_post.html | 25 +++++++++--- app/templates/video.html | 2 +- 4 files changed, 67 insertions(+), 37 deletions(-) diff --git a/app/models.py b/app/models.py index 13b0057..25d4d83 100644 --- a/app/models.py +++ b/app/models.py @@ -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' diff --git a/app/routes.py b/app/routes.py index 58763b1..487dc18 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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 diff --git a/app/templates/_twitter_post.html b/app/templates/_twitter_post.html index 9574cfb..6e924d7 100644 --- a/app/templates/_twitter_post.html +++ b/app/templates/_twitter_post.html @@ -2,12 +2,7 @@

{{post.content}}

+ {% if post.attachedImg != "" %} + + {% endif %} + {% if post.isReply %} +
+
+
{{post.replyingUser}}
+
{{post.replyingUser}}
+
+ {{post.replyingTweetContent}} + {% if post.replyAttachedImg != "" %} + + {% endif %} +
+
+
+ {% endif %} +