123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import curses
- from html.parser import HTMLParser
- from mastodon import Mastodon
-
- class PostParser(HTMLParser):
- def __init__(self, ncwin, defncatt):
- HTMLParser.__init__(self)
- self.win = ncwin,
- self.defncatt = defncatt
- self.curatt = defncatt
-
- def handle_starttag(self, tag, attrs):
- if tag == 'p':
- self.curatt = self.defncatt
- elif tag == 'strong':
- self.curatt = self.curatt ^ curses.A_BOLD
-
- def handle_endtag(self, tag, attrs):
- if tag == 'p':
- cy, cx = self.win.getyx()
- self.win.move(cy + 2, 0)
- elif tag == 'strong':
- self.curatt = self.curatt ^ curses.A_BOLD
-
- def handle_data(self, data):
- self.win.addstr(data, self.curatt)
-
-
- # print(mastodon.timeline()[0]["content"])
-
-
- def main(stdscr):
- mastodon = Mastodon(
- access_token = 'd100.club_usercred.secret',
- api_base_url = 'd100.club'
- )
- posts = mastodon.timeline()
- parser = PostParser(stdscr, 0)
- stdscr.clear()
- stdscr.addstr("test")
- stdscr.refresh()
- curses.halfdelay(10)
- # parser.feed(posts[0]["content"])
- i = 'c'
- q = 0
- con = True
- while con:
- i = stdscr.getch()
- con = (i != ord('q'))
-
- curses.wrapper(main)
|