This repository has been archived on 2022-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
Yotter/nitter/feed.py

49 lines
1.4 KiB
Python
Raw Normal View History

from requests_futures.sessions import FuturesSession
from multiprocessing import Process
from werkzeug.datastructures import Headers
from concurrent.futures import as_completed
from numerize import numerize
from bs4 import BeautifulSoup
from operator import itemgetter, attrgetter
from re import findall
from nitter import user
import time, datetime
import requests
import bleach
import urllib
import json
import re
config = json.load(open('yotter-config.json'))
def get_feed(usernames, daysMaxOld=10, includeRT=True):
'''
Returns feed tweets given a set of usernames
'''
feedTweets = []
with FuturesSession() as session:
2021-01-07 13:22:13 +05:30
futures = [session.get(f'{config["nitterInstance"]}{u}') for u in usernames]
for future in as_completed(futures):
res = future.result().content.decode('utf-8')
html = BeautifulSoup(res, "html.parser")
feedPosts = user.get_feed_tweets(html)
feedTweets.append(feedPosts)
2021-01-07 13:22:13 +05:30
userFeed = []
for feed in feedTweets:
if not includeRT:
for tweet in feed:
if tweet['isRT']:
continue
else:
userFeed.append(tweet)
else:
2020-11-10 19:04:48 +05:30
userFeed+=feed
2021-02-01 14:58:05 +05:30
for uf in userFeed:
if uf == 'emptyFeed':
userFeed.remove(uf)
userFeed.sort(key=lambda item:item['timeStamp'], reverse=True)
2021-01-07 13:22:13 +05:30
return userFeed