Skip to content

Commit 1134c37

Browse files
committed
Merge pull request Show-Me-the-Code#83 from razzl/master
razzl
2 parents 969d3db + 26933d3 commit 1134c37

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

razzl/0000/0000.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
Draw a number on the image
5+
'''
6+
7+
try:
8+
from PIL import Image
9+
from PIL import ImageDraw
10+
from PIL import ImageFont
11+
except ImportError:
12+
import Image,ImageFont,ImageDraw
13+
14+
def draw_number(path = '/root/Desktop/1.jpg',num = 4):
15+
im = Image.open(path)#open the picture
16+
size = im.size#get the size of the picture
17+
fontsize = size[0]/4
18+
draw = ImageDraw.Draw(im)#the ImageDraw.Draw will rerturn a object then you can draw it
19+
font = ImageFont.truetype('/usr/share/fonts/dejavu/DejVuSans.ttf',fontsize)#define the font and size of the number
20+
draw.text((3*fontsize,0),str(num),(255, 0, 0),font)#draw it
21+
im.save('/root/Desktop/2.jpg')#save
22+
draw_number()

razzl/0001/0001.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
It can generate the activation code
5+
'''
6+
7+
import random
8+
#import string
9+
10+
f = open('C:\Users\zzl\Desktop\2.txt','w')
11+
for x in range(200):
12+
words = [chr(a) for a in range(65,91)]+[chr(a) for a in range(97,122)]+[str(a) for a in range(0,11)]
13+
# It is equal to string.ascii_letters + string.digits
14+
slice = random.sample(words,10)
15+
temp = str(words)
16+
f.write(temp)
17+
f.close()

razzl/0002/0002.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
It can save the contents of the file to the mysql database.
5+
'''
6+
7+
import os
8+
import random
9+
import MySQLdb
10+
#import string
11+
12+
f = open(os.getcwd()+'\\2','w')
13+
for x in range(200):
14+
words = [chr(a) for a in range(65,91)]+[chr(a) for a in range(97,122)]+[str(a) for a in range(0,11)]
15+
# It is equal to string.ascii_letters + string.digits
16+
slices = random.sample(words,10)
17+
#temp = str(slices)
18+
temp = "".join(slices)+'\n'
19+
#print temp
20+
f.write(temp)
21+
f.close()
22+
23+
f = open(os.getcwd()+'\\2','r')
24+
words = f.readlines()
25+
try:
26+
conn = MySQLdb.connect(host = 'localhost', user = 'root', passwd = '******', port = 3306)#connet to your local database of mysql
27+
28+
cur = conn.cursor()
29+
30+
conn.select_db('python')
31+
32+
count = cur.executemany('insert into test(name) values(%s)',words)#executemant need two parameters sql statement and list
33+
34+
conn.commit()#commit the implementation results
35+
cur.close()#close the cursor
36+
conn.close()# close the connect
37+
except MySQLdb.Error,e:
38+
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
39+

0 commit comments

Comments
 (0)