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
from django.db import models | |
class AbstractTimeModel(models.Model): | |
""" | |
Simple abstract base class. | |
provide the general created time, update time fields. | |
可以将 公用的字段抽取出来. | |
""" | |
created_at = models.DateTimeField( |
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
def md5_for_file(path): | |
path = path.encode('utf-8') | |
md = hashlib.md5() | |
block_size = 128 * md.block_size | |
with open(path, 'rb') as f: | |
for chunk in iter(lambda: f.read(block_size), b''): | |
md.update(chunk) | |
return md.hexdigest() |
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
class BasicModel(db.Model): | |
__abstract__ = True | |
created_at = db.Column(db.DateTime, default=db.func.now()) | |
updated_at = db.Column(db.DateTime, default=db.func.now(), onupdate=db.func.now()) | |
class User(BasicModel): | |
__tablename__ = 'users' | |
id = db.Column(db.Integer, primary_key=True, autoincrement=True) |
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
# coding=utf-8 | |
from app.ext.token_gainer import twitter_api | |
from TwitterAPI.TwitterError import TwitterConnectionError, TwitterRequestError | |
def call_request(url, params, retries=3, api=None): | |
""" | |
:param url: twitter api | |
:param params: api param conmmon dict(t) |
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
""" | |
pip install PyMuPDF==1.14.3 | |
""" | |
import fitz | |
def convert_pdf_to_png(filename): | |
doc = fitz.open(filename=filename) | |
for pg in range(doc.pageCount): |
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
import cv2 | |
video_url = 'https://scontent.xx.fbcdn.net/v/t50.2886-16/39483744_2088298591194407_5257741205319450624_n.mp4?_nc_cat=109&oh=807b4ef98367893cacb969323f47048b&oe=5C4D7231' | |
vidcap = cv2.VideoCapture(video_url) | |
vidcap.set(cv2.CAP_PROP_POS_MSEC, 1000) | |
success, image = vidcap.read() | |
if success: | |
cv2.imwrite('frame.jpg', image) |
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
# coding=utf-8 | |
CONSTANT_BEGIN = 201416920417 | |
CONSTANT_CHAR = 'JTXD9hz6SBqpINCrx5Memk1LO2ylcPYjFnwbd4tv3VW0aiRK8oGE7fuQgsAUHZ' | |
CONSTANT_LENGTH = len(CONSTANT_CHAR) | |
def encode_b64(num): | |
if not isinstance(num, (int, long)): | |
raise TypeError('Must int num') | |
if num <= 0: |
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
# add remote upstream source | |
git remote add upstream https://github.com/encode/requests-async.git | |
# check the remote status | |
git remote -v | |
# fetch the upstream lastest update | |
git fetch upstream | |
# change current branch to master |
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
filename = './xxx.pdf' | |
with open(GUIDO, 'rb') as g_f: | |
guido = MIMEApplication(g_f.read(), _subtype='pdf') | |
guido.add_header('Content-Disposition', 'attachment', filename=filename) | |
msg.attach(guido) | |
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
# run a simple mongo server | |
docker run --rm --name mymongo -p 27017:27017 -d mongo | |
# run mongo web | |
docker run --rm --name mymongo-express --link mymongo:mongo -p 8081:8081 -d mongo-express |
OlderNewer