-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddceba9
commit aa93d0b
Showing
16 changed files
with
1,437 additions
and
596 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,26 @@ | ||
from django.test import TestCase | ||
import django | ||
import os | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings") | ||
|
||
django.setup() | ||
|
||
# Create your tests here. | ||
from article.models import Cover | ||
# Cover | ||
# | ||
# class TestCase(TestCase): | ||
# # 测试函数执行前执行 | ||
# def setUp(self): | ||
# print("======in setUp") | ||
# | ||
# # 需要测试的内容 | ||
# def test_add(self): | ||
# pass | ||
# | ||
# # 需要测试的内容 | ||
# | ||
# # 测试函数执行后执行 | ||
# def tearDown(self): | ||
# print("======in tearDown") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from PIL import Image, ImageDraw, ImageFont | ||
from io import BytesIO | ||
import requests | ||
import os | ||
from shortid import short_id | ||
from oss2 import * | ||
from models.models import Config | ||
|
||
|
||
def __get_db_config(group): | ||
dict = {} | ||
|
||
datas = Config.objects.filter(group=group).values('key', 'value') | ||
|
||
for i in datas: | ||
dict[i.get('key')] = i.get('value') | ||
return dict | ||
|
||
|
||
# 初始化 oss | ||
def get_oss_bucket(): | ||
config = __get_db_config('oss') | ||
|
||
access_key_id = config.get('key') | ||
access_key_secret = config.get('secret') | ||
endpoint = config.get('endpoint') | ||
bucket_name = config.get('bucket') | ||
auth = Auth(access_key_id, access_key_secret) | ||
cname = config.get('cname') | ||
return { | ||
"bucket": Bucket(auth, endpoint, bucket_name), | ||
"cname": cname | ||
} | ||
|
||
|
||
def draw(text='', url=None, x=0, y=0, font_size=24, color='#FFF'): | ||
font = ImageFont.truetype(os.path.abspath(os.path.dirname(__file__)) + "/pingfang.ttf", font_size) | ||
|
||
r = requests.get(url, verify=False) | ||
# r = requests.get('https://oss.88cto.com/4y6MS8Rs.png') | ||
stream = BytesIO() | ||
stream.write(r.content) | ||
|
||
img1 = Image.open(stream) | ||
|
||
d = ImageDraw.Draw(img1) | ||
d.text((x, y), text, color, font=font) | ||
io_obj = BytesIO() | ||
# img1.save('/Users/panjing/Downloads/{}.png'.format(name)) | ||
img1.save(io_obj, 'png') | ||
filename = short_id.get_short_id() + ".png" | ||
result = get_oss_bucket().get('bucket').put_object(filename, io_obj.getvalue()) | ||
print(result) | ||
|
||
return get_oss_bucket().get('cname') + "/" + filename | ||
|
||
|
||
if __name__ == '__main__': | ||
draw() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,29 @@ | ||
import os, sys, django | ||
|
||
dicts={ | ||
'name':123 | ||
} | ||
from django.test import TestCase | ||
|
||
print(dicts.get('name1')) | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myblog.settings") | ||
django.setup() | ||
|
||
from draw import draw | ||
from article.models import Cover, Article | ||
import random | ||
from django.db import models | ||
|
||
all = Article.objects.all() | ||
|
||
total = Cover.objects.count() | ||
|
||
for item in all: | ||
# if item.image != '': | ||
# continue | ||
c = Cover.objects.all()[random.randint(0, total - 1)] | ||
url = draw.draw(text=item.title, url=c.image.url, font_size=c.font_size, color=c.color, x=c.x, y=c.y) | ||
item.image.name = url | ||
print(url) | ||
item.save() | ||
|
||
# all = Cover.objects.all() | ||
# for index, item in enumerate(all): | ||
# draw.draw(item, name=index, font_size=item.font_size, color=item.color, x=item.x, y=item.y) | ||
# print(item, index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Django==2.2.1 | ||
django-simpleui | ||
pytz==2019.1 | ||
shortid8==1.0 | ||
sqlparse==0.3.0 | ||
Pillow | ||
markdown | ||
django-haystack | ||
django-compressor | ||
mysqlclient | ||
redis | ||
oss2 | ||
jieba | ||
Whoosh |
Oops, something went wrong.