Ver código fonte

Trying to get addstr working

Petra Lamborn 4 anos atrás
pai
commit
c4a24cc00f
1 arquivos alterados com 31 adições e 7 exclusões
  1. 31
    7
      fedicurses.py

+ 31
- 7
fedicurses.py Ver arquivo

3
 from mastodon import Mastodon
3
 from mastodon import Mastodon
4
 
4
 
5
 class PostParser(HTMLParser):
5
 class PostParser(HTMLParser):
6
+    def __init__(self, ncwin, defncatt):
7
+        HTMLParser.__init__(self)
8
+        self.win = ncwin,
9
+        self.defncatt = defncatt
10
+        self.curatt = defncatt
11
+
6
     def handle_starttag(self, tag, attrs):
12
     def handle_starttag(self, tag, attrs):
7
-        print(tag)
13
+        if tag == 'p':
14
+            self.curatt = self.defncatt
15
+        elif tag == 'strong':
16
+            self.curatt = self.curatt ^ curses.A_BOLD
17
+
18
+    def handle_endtag(self, tag, attrs):
19
+        if tag == 'p':
20
+            cy, cx = self.win.getyx()
21
+            self.win.move(cy + 2, 0)
22
+        elif tag == 'strong':
23
+            self.curatt = self.curatt ^ curses.A_BOLD
24
+
25
+    def handle_data(self, data):
26
+        self.win.addstr(data, self.curatt)
8
 
27
 
9
-mastodon = Mastodon(
10
-        access_token = 'd100.club_usercred.secret',
11
-        api_base_url = 'd100.club'
12
-)
13
 
28
 
14
-print(mastodon.timeline()[0]["content"])
29
+# print(mastodon.timeline()[0]["content"])
15
 
30
 
16
 
31
 
17
 def main(stdscr):
32
 def main(stdscr):
33
+    mastodon = Mastodon(
34
+            access_token = 'd100.club_usercred.secret',
35
+            api_base_url = 'd100.club'
36
+    )
37
+    posts = mastodon.timeline()
38
+    parser = PostParser(stdscr, 0)
18
     stdscr.clear()
39
     stdscr.clear()
40
+    stdscr.addstr("test")
41
+    stdscr.refresh()
19
     curses.halfdelay(10)
42
     curses.halfdelay(10)
43
+    # parser.feed(posts[0]["content"])
20
     i = 'c'
44
     i = 'c'
21
     q = 0
45
     q = 0
22
     con = True
46
     con = True
24
         i = stdscr.getch()
48
         i = stdscr.getch()
25
         con = (i != ord('q'))
49
         con = (i != ord('q'))
26
 
50
 
27
-#curses.wrapper(main)
51
+curses.wrapper(main)