File tree Expand file tree Collapse file tree 3 files changed +254
-0
lines changed
Expand file tree Collapse file tree 3 files changed +254
-0
lines changed Original file line number Diff line number Diff line change 1+ #!bin/env python
2+ # -*- coding: utf-8 -*-
3+
4+ #这是另一种方案
5+
6+ #未完成,想法是直接将返回的字典存入redis数据库,感觉这样都是键值对,看上去舒服点,性能上会怎么样,不清楚
7+ #还需要补习面向对象方面的python知识,文档还不能完全看懂
8+
9+ from redisco import models
10+
11+ def file_read (filename ):
12+ with open (filename ,'r' ) as f :
13+ lines = f .readlines ()
14+ for n in range (0 ,200 ):
15+ lines [n ] = lines [n ].strip ()
16+ num = range (1 ,201 )
17+ d = dict (zip (num ,lines ))
18+ print d
19+
20+ def redis_write (dictionary ):
21+
22+
23+
24+
25+ if __name__ == '__main__' :
26+ file_read ('result.txt' )
Original file line number Diff line number Diff line change 1+ #!bin/env python
2+ # -*- coding: utf-8 -*-
3+
4+ #导入库
5+ import redis
6+
7+ #打开文件,取出激活码
8+ def file_read (filename ):
9+ with open (filename ,'r' ) as f :
10+ lines = f .readlines ()
11+ for n in range (0 ,200 ):
12+ lines [n ] = lines [n ].strip ()
13+ return lines
14+
15+ #存入数据库
16+ def redis_write ():
17+ lines = file_read ('result.txt' )
18+ r = redis .StrictRedis (host = 'localhost' , port = 6379 , db = 0 )
19+ for n in range (0 ,200 ):
20+ key = str (n + 1 )
21+ value = str (lines [n ])
22+ r .set (key , value )
23+ r .save ()
24+ print 'finish'
25+
26+ #执行主函数
27+ if __name__ == '__main__' :
28+ redis_write ()
Original file line number Diff line number Diff line change 1+ 06221205
2+ 85531344
3+ 10747373
4+ 40887544
5+ 61712875
6+ 83813324
7+ 43648825
8+ 30840323
9+ 36832211
10+ 01105618
11+ 13410375
12+ 65468385
13+ 55683113
14+ 68867155
15+ 24545317
16+ 64626102
17+ 20728343
18+ 06812487
19+ 46831163
20+ 43211742
21+ 74116167
22+ 84722574
23+ 42777526
24+ 06821521
25+ 46006164
26+ 75747227
27+ 01811788
28+ 25124141
29+ 88402648
30+ 27814287
31+ 71176283
32+ 34852241
33+ 13232158
34+ 55172318
35+ 76560208
36+ 34562718
37+ 14470566
38+ 66472235
39+ 43043486
40+ 82587857
41+ 31165481
42+ 61282076
43+ 51888112
44+ 63434568
45+ 00332440
46+ 16208350
47+ 82726762
48+ 76348604
49+ 67626647
50+ 40874847
51+ 32004853
52+ 23201687
53+ 76141208
54+ 76652005
55+ 43027814
56+ 70487088
57+ 51100542
58+ 75636082
59+ 11274755
60+ 68062563
61+ 47757087
62+ 88845773
63+ 27218807
64+ 02881740
65+ 80688110
66+ 62527342
67+ 88376682
68+ 52136864
69+ 32768130
70+ 64831121
71+ 01660656
72+ 68284636
73+ 03844432
74+ 53287038
75+ 33517722
76+ 78753670
77+ 72513462
78+ 80243861
79+ 80740322
80+ 32666043
81+ 14767271
82+ 31362170
83+ 54722211
84+ 67673546
85+ 71530765
86+ 30244212
87+ 77576738
88+ 86657202
89+ 84444178
90+ 88468247
91+ 54184117
92+ 56661765
93+ 84005730
94+ 08121831
95+ 27275157
96+ 57340616
97+ 10544260
98+ 22873056
99+ 78722771
100+ 11734138
101+ 73146352
102+ 20243567
103+ 10067846
104+ 18647840
105+ 36105120
106+ 10127745
107+ 34721127
108+ 78540741
109+ 50541616
110+ 32316886
111+ 17477764
112+ 68557540
113+ 61833782
114+ 14836884
115+ 13205258
116+ 30135127
117+ 06784272
118+ 06035717
119+ 57765256
120+ 16304861
121+ 35258452
122+ 06857838
123+ 65270618
124+ 81846635
125+ 81831780
126+ 37150676
127+ 83437771
128+ 52254508
129+ 42765761
130+ 13213803
131+ 58634373
132+ 80018333
133+ 80162586
134+ 34380717
135+ 65865270
136+ 08286300
137+ 24416804
138+ 44766425
139+ 21210230
140+ 16060305
141+ 55578384
142+ 01312373
143+ 41407715
144+ 76451227
145+ 47103278
146+ 60401033
147+ 33811504
148+ 58456258
149+ 03256286
150+ 08403105
151+ 64435036
152+ 51277430
153+ 74503246
154+ 40023773
155+ 24817724
156+ 88612034
157+ 07788457
158+ 86656864
159+ 72513618
160+ 05212708
161+ 25161048
162+ 18440578
163+ 28626680
164+ 21455352
165+ 18247878
166+ 56710751
167+ 40024360
168+ 02676631
169+ 71176541
170+ 45347211
171+ 72637627
172+ 30713084
173+ 71061801
174+ 54546710
175+ 73405660
176+ 70303522
177+ 26720541
178+ 62457276
179+ 43350522
180+ 66346162
181+ 36376106
182+ 86125656
183+ 22880566
184+ 16325646
185+ 88307733
186+ 08081038
187+ 48314863
188+ 40044423
189+ 87133380
190+ 88580362
191+ 84376574
192+ 41720582
193+ 53641143
194+ 55035648
195+ 72176747
196+ 32600634
197+ 57622861
198+ 46441808
199+ 51540837
200+ 65628570
You can’t perform that action at this time.
0 commit comments