-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
109 lines (85 loc) · 2.31 KB
/
Copy pathclient.py
File metadata and controls
109 lines (85 loc) · 2.31 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#coding: utf-8
import zmq
usage =\
"""\
Запросы:
Добавить категорию:
<request type = "add_topic">
<topic id = "[id]">
<title>[title]</title>
<concepts>
<concept name = "[name]"\>
...
</concpts>
</topic>
</request>
Показать подкатегории:
<request type = "show_children">
<topic id = "[id]"/>
</request>
Показать документы категории:
<request type = "show_docs">
<topic id = "[id]"/>
</request>
Количество документов в категории:
<request type = "doc_num">
<topic id = "[id]"/>
</request>
Добавить документ:
<request type = "add_doc">
<doc url = "[url]">
<topic id ] = "[id]"/>
...
</docum>
</request>"""
addres = "tcp://localhost:5554"
add_doc_wiki = """\
<request type = "add_doc">
<doc url = "http://ru.wikipedia.org">
<topic id = "000.000.000"/>
</doc>
</request>
"""
show_generic_children = """\
<request type = "show_children">
<topic id = "000.000.000"/>
</request>
"""
show_010_children = """\
<request type = "show_children">
<topic id = "010.000.000"/>
</request>
"""
show_010_010_children = """\
<request type = "show_children">
<topic id = "010.010.000"/>
</request>
"""
show_010_010_010_children = """\
<request type = "show_children">
<topic id = "010.010.010"/>
</request>
"""
show_generic_docs = """\
<request type = "show_docs">
<topic id = "000.000.000"/>
</request>
"""
tests = [add_doc_wiki, show_generic_children, show_010_children, show_010_010_children, show_010_010_010_children, show_generic_docs]
def client_start():
context = zmq.Context()
print "usage\n", usage
print ">>> Connectiong to Topic Storage..."
socket = context.socket(zmq.REQ)
socket.connect(addres)
while(True):
for test in tests:
raw_input("Нажмите Enter, чтобы отправить новый запрос:")
print ">>> Sending request:\n ", test, "\n..."
socket.send(test)
reply = socket.recv()
print ">>> Recived reply:\n", reply
def main():
client_start()
if (__name__ == "__main__"):
main()