update
This commit is contained in:
@@ -1,45 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#########################################################
|
||||
import os, traceback, io, re, json, codecs
|
||||
import codecs
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import traceback
|
||||
|
||||
from . import logger
|
||||
|
||||
|
||||
class ToolBaseFile(object):
|
||||
|
||||
@classmethod
|
||||
def read(cls, filepath, mode='r'):
|
||||
try:
|
||||
import codecs
|
||||
ifp = codecs.open(filepath, mode, encoding='utf8')
|
||||
data = ifp.read()
|
||||
ifp.close()
|
||||
if isinstance(data, bytes):
|
||||
data = data.decode('utf-8')
|
||||
return data
|
||||
except Exception as exception:
|
||||
logger.error('Exception:%s', exception)
|
||||
logger.error(traceback.format_exc())
|
||||
|
||||
|
||||
@classmethod
|
||||
def download(cls, url, filepath):
|
||||
try:
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
|
||||
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
|
||||
'Accept-Language' : 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7',
|
||||
'Connection': 'Keep-Alive',
|
||||
}
|
||||
|
||||
import requests
|
||||
with open(filepath, "wb") as file_is: # open in binary mode
|
||||
response = requests.get(url, headers=headers) # get request
|
||||
file_is.write(response.content) # write to file
|
||||
return True
|
||||
except Exception as exception:
|
||||
logger.debug('Exception:%s', exception)
|
||||
logger.debug(traceback.format_exc())
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def write(cls, data, filepath, mode='w'):
|
||||
@@ -80,7 +53,8 @@ class ToolBaseFile(object):
|
||||
@classmethod
|
||||
def file_move(cls, source_path, target_dir, target_filename):
|
||||
try:
|
||||
import time, shutil
|
||||
import shutil
|
||||
import time
|
||||
if os.path.exists(target_dir) == False:
|
||||
os.makedirs(target_dir)
|
||||
target_path = os.path.join(target_dir, target_filename)
|
||||
@@ -196,7 +170,8 @@ class ToolBaseFile(object):
|
||||
|
||||
@classmethod
|
||||
def makezip_simple(cls, zip_path, zip_extension='cbz', remove_zip_path=True):
|
||||
import zipfile, shutil
|
||||
import shutil
|
||||
import zipfile
|
||||
try:
|
||||
if os.path.exists(zip_path) == False:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user