Skip to content

Commit 8379ff2

Browse files
author
ymc
committed
complete problem 0002
1 parent 7243418 commit 8379ff2

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎messyidea/0002/0002.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
import uuid
3+
import MySQLdb
4+
5+
def gen( num):
6+
assert isinstance(num, int) == True
7+
assert num > 0
8+
rst = []
9+
while True:
10+
temp = str(uuid.uuid1()).replace('-', '')
11+
if temp not in rst:
12+
rst.append(temp)
13+
num = num - 1
14+
if num == 0:
15+
break
16+
return rst
17+
18+
rst = gen(200)
19+
for i in rst:
20+
print i
21+
22+
try:
23+
conn=MySQLdb.connect(host='localhost',user='root',passwd='root',port=3306)
24+
cur=conn.cursor()
25+
26+
cur.execute('create database if not exists Activation_code')
27+
conn.select_db('Activation_code')
28+
cur.execute('create table code(id int,uuid varchar(50))')
29+
30+
for i in range(len(rst)):
31+
cur.execute('insert into code values(%s,%s)',(i ,rst[i]))
32+
33+
conn.commit()
34+
cur.close()
35+
conn.close()
36+
37+
except MySQLdb.Error,e:
38+
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
39+
40+

0 commit comments

Comments
 (0)