Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions crazyacking/0000/add_num.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr /bin/env python
# -*- coding: utf-8 -*-

"""
将你的 QQ 头像右上角加上红色的数字,类似于微信未读信息数量提示效果
Pillow:Python Imaging Library
PIL.ImageDraw.Draw.text(xy, text, fill=None, font=None, anchor=None)
"""
from PIL import Image, ImageDraw, ImageFont

class Image_unread_message:
def open(self,path):
self.im=Image.open(path)
return True
def __init__(self):
self.fnt=None
self.im=None

def setFont(self,font_path,size):
self.fnt=ImageFont.truetype(font_path,size)
return True
def draw_text(self,position,str,colour,fnSSt):
draw=ImageDraw.Draw(self.im)
draw.text(position,str,fill=colour,font=fnt)
self.im.show()
self.im.save(str+'num'+'.jpg')
return True


test=Image_unread_message()
test.open('test.jpg')
test.setFont('ahronbd.ttf',80)
test.draw_text((160,-20),'4',(255,0,0),test.fnt)
Binary file added crazyacking/0000/ahronbd.ttf
Binary file not shown.
Binary file added crazyacking/0000/simsunb.ttf
Binary file not shown.
7 changes: 7 additions & 0 deletions crazyacking/0001/0001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import uuid
"""
做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用**生成激活码**(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?
"""

for i in range(200):
print(str(uuid.uuid4()))
88 changes: 88 additions & 0 deletions crazyacking/0002/0002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#coding=utf-8

import uuid

import MySQLdb

"""
002, 将 0001 题生成的 200 个激活码(或者优惠券)保存到 **MySQL** 关系型数据库中
"""


class ActivationCode(object):
def __init__(self, code_count, database, username, host='localhost', port=3306, password=''):
self._host = host
self._username = username
self._password = password
self._database = database
self._port = port

self.codes = self._generate_activation_code(code_count)
#print self.codes


def _get_mysql_instance(self):
params = {
'host': self._host,
'user': self._username,
'passwd': self._password,
'db': self._database,
'port': self._port,
}
return MySQLdb.connect(**params)


def _generate_activation_code(self, count):
code_list = []
for i in xrange(count):
code = str(uuid.uuid4()).replace('-', '').upper()
if not code in code_list:
code_list.append(code)

return code_list


def store_to_mysql(self):
if self.codes:
conn = self._get_mysql_instance()

try:
cur = conn.cursor()

# clear old datas
cur.execute('delete from code')

# insert mutilple code
for code in self.codes:
cur.execute("insert into code(code) values('%s')" % code)

conn.commit()
cur.close()
conn.close()

return True
except MySQLdb.Error,e:
conn.rollback()
print "Mysql Error %d: %s" % (e.args[0], e.args[1])

return False


def print_activation_code(self):
conn = self._get_mysql_instance()

try:
cur = conn.cursor()
cur.execute('select code from code')

results = cur.fetchall()
for row in results:
print row[0]
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])


if __name__ == "__main__":
active_code = ActivationCode(200, database='Test', username='root')
if active_code.store_to_mysql():
active_code.print_activation_code()
200 changes: 200 additions & 0 deletions crazyacking/0003/Activation_code.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
xsdPh4f
8qoW07j
Tnj1HmB
zIT8qAB
FnDnNi0
3QpZj1O
KlkwRfE
wsdy8NQ
pvXSdlY
pp9LWSn
dS6zQnC
WbCHjJH
jAjJtli
38ykU8k
wMNCQ1m
X245rLW
UWizZgo
YkLduIF
v1GJSdz
BNMZuX5
yIjRDQu
GNvXIIF
DbWEtTD
F1W2jtg
54bWrUb
b2IEbzZ
xcaOsuG
uXOhegJ
TvKkKSN
KgSCoEJ
elrc80r
DOXohsE
KjdnEGw
ffqwUwX
xdRhBkT
ruceTaI
RZZTs0h
K5EKaNj
VqW5vfD
ownScnm
7rGnRPw
TiaUfFy
7YSMWr0
C9YkCdo
6ikBwSy
qiETLg6
aKDPWxE
b3cCXhY
MKA2OKu
9EdcKmD
0qeKaui
ejpFFlC
SmC9Nor
mCPyWEv
kSt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wfz0kk
9AlVldl
pQ8xzhi
5tPou1g
ahNqlgN
euCV2IH
tg9b7s8
Z4r2aA6
JYUijB2
k6tMe54
LJuhb7x
Z6VPjwe
U3qgd0G
a9RH5fF
13 changes: 13 additions & 0 deletions crazyacking/0003/store_redis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-

import redis

def store_redis(filepath):
r = redis.StrictRedis(host = 'localhost', port = 6379, db = 0)
f = open(filepath, 'rb')
for line in f.readlines():
code = line.strip()
r.lpush('code', code)

if __name__ == '__main__':
store_redis('Activation_code.txt')
15 changes: 15 additions & 0 deletions crazyacking/0005/changeResolution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小
'''
from PIL import Image

def change_img(path,size=(1136,640)):
im = Image.open(path)
size=(size[1],size[0]) if im.size[1]>im.size[0] else size
im.thumbnail(size,Image.ANTIALIAS) #Image.ANTIALIAS为滤镜参数
im.save('result-'+path)

change_img('1.jpg')