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 | |
""" | |
redis 分布式悲观锁,需要解决以下几个问题 | |
1、A获取锁后崩溃,需要能将锁释放 | |
2、A获取锁后处理时间过长,导致锁过期,被B获取,A处理完后错误的将B锁释放 | |
redis.Redis()会有些问题,连接最好使用redis.StrictRedis() | |
""" | |
import math |
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 -*- | |
import os | |
import threading | |
import requests | |
import tqdm | |
class Downloader(object): | |
def __init__(self, url, name="notitle", worker_num=8, resume=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 -*- | |
import heapq | |
import time | |
class DelayJobQueue(object): | |
""" | |
延迟执行任务队列 | |
q = DelayJobQueue() | |
q.add(task,at=time.time() + 10) | |
q.pop_ready() # None |
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 -*- | |
""" | |
给定一个pdf路径,以及一个列表,可修改pdf内容,删除所有符合条件的文字。 | |
""" | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
from PyPDF2.generic import TextStringObject, NameObject | |
from PyPDF2.pdf import ContentStream | |
from PyPDF2.utils import b_ |
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
下载m3u8格式视频的小组件,使用python3 asyncio | |
使用ffmpeg合并ts成mp4 | |
""" | |
import asyncio | |
import os | |
import shutil |
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
0,北京,province | |
1,北京,city,0 | |
2,东城区,area,1 | |
3,西城区,area,1 | |
4,崇文区,area,1 | |
5,宣武区,area,1 | |
6,朝阳区,area,1 | |
7,丰台区,area,1 | |
8,石景山区,area,1 | |
9,海淀区,area,1 |
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 -* | |
""" | |
把一个复杂对象转为一个字典 | |
""" | |
class ToDictMixin(object): | |
def to_dict(self): | |
return self._traverse_dict(self.__dict__) |
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 Singleton(type): | |
def __init__(cls, name, bases, dict): | |
super(Singleton, cls).__init__(name, bases, dict) | |
cls.instance = None | |
def __call__(cls, *args, **kw): | |
if cls.instance is None: | |
cls.instance = super(Singleton, cls).__call__(*args, **kw) | |
return cls.instance |
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 -*- | |
def ensure_unicode(s): | |
if not s: | |
return s | |
if isinstance(s, unicode): | |
return s | |
elif isinstance(s, str): | |
return s.decode('utf-8') | |
else: |
OlderNewer