123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import curses
- from html.parser import HTMLParser
- from mastodon import Mastodon
-
- def newLine(ncwin, lines=1):
- cy, cx = ncwin.getyx()
- ncwin.move(cy + lines, 0)
-
-
- 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
- elif tag == 'br':
- newLine(self.win)
-
- def handle_endtag(self, tag):
- if tag == 'p':
- newLine(self.win, 2)
- 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()
- stdscr.clear()
- # stdscr.addstr("test")
- curses.halfdelay(10)
- my, mx = stdscr.getmaxyx()
- c1w = c2w = (mx - 1) // 2
- if (mx % 2) != 0:
- c2w = c2w - 1
- colw1 = curses.newwin(1, 1, my - 1, c1w)
- colw2 = curses.newwin(1, 1 + c1w + 1, my - 1, c2w)
- #colw1.border()
- #colw2.border()
- parser = PostParser(colw1, 0)
- colw1.move(0,0)
- try:
- for post in posts:
- colw1.addstr(post["account"]["acct"], curses.A_BOLD)
- colw1.addstr(':', curses.A_BOLD)
- newLine(colw1)
- parser.feed(post["content"])
- except:
- pass
- colw1.refresh()
- colw2.refresh()
- stdscr.refresh()
- i = 'c'
- q = 0
- con = True
- while con:
- i = stdscr.getch()
- con = (i != ord('q'))
-
- curses.wrapper(main)
|