27 lines
595 B
Python
27 lines
595 B
Python
from dataclasses import dataclass
|
|
from pprint import pprint
|
|
from typing import List
|
|
|
|
import feedparser
|
|
|
|
|
|
@dataclass
|
|
class Tweet:
|
|
id: str
|
|
author: str
|
|
content: str
|
|
|
|
@classmethod
|
|
def from_rss_entry(cls, entry: feedparser.FeedParserDict):
|
|
return Tweet(
|
|
id=entry['id'],
|
|
author=entry['author'],
|
|
content=entry['summary'],
|
|
)
|
|
|
|
|
|
def get_tweets(username: str) -> List[Tweet]:
|
|
newsfeed = feedparser.parse(f"https://nitter.net/{username}/rss")
|
|
return [Tweet.from_rss_entry(t) for t in newsfeed.entries]
|
|
|