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 calculate(last_time, current_time): | |
time_delta = \ | |
datetime.datetime.strptime(current_time, '%M:%S.%f') -\ | |
datetime.datetime.strptime(last_time, '%M:%S.%f') | |
return str(time_delta)[2:-4] |
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
[mail] | |
smtp_server = smtp.your-service.com | |
to_addr = target@email.com | |
from_addr = your@email.com | |
nickname = nick-name | |
password = your-password | |
prefix = subject-prefix | |
port = 25 |
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 sys | |
def get_cur_info(): | |
_ = sys._getframe() | |
return (_.f_code.co_name, _.f_back.f_lineno) # funcname, lineno |
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 os import listdir | |
from os.path import splitext, basename, isfile, isdir, join | |
def GetFileList(dir, fileList): | |
newDir = dir | |
if isfile(dir): | |
fileList.append(dir.decode('utf-8')) | |
elif isdir(dir): | |
for s in listdir(dir): | |
# 如果需要忽略某些文件夹,使用以下代码 |
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 os.path import exists | |
if exists(r'/home/test.txt'): | |
shutil.copyfile(r'/home/test.txt', r'/home/root/') | |
else: | |
pass |
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 uuid import getnode as get_mac, UUID | |
macaddr=UUID(int=get_mac()).hex[-12:].upper() # FFFFFFFFFFFF | |
return(":".join([macaddr[e:e+2] for e in range(0,11,2)])) |
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 mmap | |
import urllib2 | |
def Upload(fname, url): | |
f = open(fname, 'rb') | |
mmapped_file_as_string = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) | |
# Do the request |
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 pycurl | |
def Upload(file_name, url): | |
pc = pycurl.Curl() | |
pc.setopt(pycurl.URL, url) # URL | |
pc.setopt(pycurl.HTTPPOST, | |
[('logfile', (pc.FORM_FILE, file_name,))]) # {'logfile': xxx} | |
pc.perform() |
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 sys,os,linecache | |
def trace(f): | |
def globaltrace(frame, why, arg): | |
if why == "call": | |
return localtrace | |
return None | |
def localtrace(frame, why, arg): | |
if why == "line": | |
# record the file name and line number of every trace | |
filename = frame.f_code.co_filename |
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 signal,functools | |
class TimeoutError(Exception): | |
pass #定义一个Exception,后面超时抛出 | |
def timeout(seconds, error_message = 'Function call timed out'): | |
def decorated(func): def _handle_timeout(signum, frame): | |
raise TimeoutError(error_message) | |
def wrapper(*args, **kwargs): | |
signal.signal(signal.SIGALRM, _handle_timeout) |
OlderNewer