-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
74 lines (63 loc) · 2.17 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from config import FORUM_LIST_KEY, URL_FORUM_LIST, URL_THREAD_LIST, RE_OPT
from forum import Forum
from stage1st import Stage1stClient
from util import colored
class Index(Stage1stClient):
def __init__(self, sid=0, page=1):
super().__init__(sid=sid, page=page)
self.data = {}
def _build_url(self):
return URL_FORUM_LIST
def forums_list(self):
return self.content.get(FORUM_LIST_KEY, [])
def forums(self):
forums_list = sorted(self.forums_list(), key=lambda x: -int(x["todayposts"]))
for i, forum in enumerate(forums_list, start=1):
self.data[str(i)] = forum["fid"]
fobj = Forum(
forum["fid"],
name=forum["name"],
description=forum.get("description", ""),
threads_count=forum["threads"],
posts=forum["posts"],
todayposts=forum["todayposts"],
)
print(f"「{colored(i, 'red', attrs=['bold'])}」\t{fobj}")
def terminal(self):
self.forums()
while True:
ipt = input("论坛 $ ")
if ipt:
opt, args = RE_OPT.match(ipt).groups()
if opt == "q":
break
elif opt == "f":
self.refresh()
self.forums()
elif opt == "e" or opt == "exit":
sys.exit(0)
elif opt == "h" or opt == "help":
self.help()
elif opt == "" and args:
fid = self.data.get(args)
if fid:
f = Forum(fid)
f.termianl()
def help(self):
print(
"""
<operate> [args]
<q> 返回上一级
<e> 退出
<h> 帮助信息
<f> 刷新
[Forum Index] 进入相应论坛
<s> 搜索
"""
)
if __name__ == "__main__":
s = Index()
s.terminal()