features #16
@ -1,15 +1,25 @@
|
||||
from configparser import ConfigParser
|
||||
from easydict import EasyDict as edict
|
||||
from typing import Any
|
||||
|
||||
|
||||
CONFIG_FILE = 'config.ini'
|
||||
|
||||
|
||||
class Configure:
|
||||
class Cfg:
|
||||
def __getattr__(self, name: str) -> Any:
|
||||
for key in self.data.keys():
|
||||
if name not in self.data[key]:
|
||||
continue
|
||||
return self.data[key][name]
|
||||
raise NameError("Config options not found!")
|
||||
|
||||
|
||||
class Configure(Cfg):
|
||||
|
||||
def __init__(self):
|
||||
config = ConfigParser()
|
||||
config.read(CONFIG_FILE)
|
||||
self.config = config
|
||||
self.data = dict()
|
||||
|
||||
for section in config.sections():
|
||||
@ -18,17 +28,20 @@ class Configure:
|
||||
for key, value in config.items(section):
|
||||
self.data[section][key] = value
|
||||
|
||||
config_folder = config.get("Docs_Settings", "Config_folder").rstrip("/")
|
||||
self.data["documentid"] = config.get("Docs_Settings", 'Document_ID')
|
||||
self.data["data_file"] = config_folder + "/" + config.get("Docs_Settings", "data_file")
|
||||
self.data["credentials_file"] = config_folder + "/" + config.get("Docs_Settings", "credentials_file")
|
||||
self.data["token_file"] = self.config_folder + "/" + self.data['Docs_Settings']['token_file']
|
||||
self.config_folder = config.get("Docs_Settings", "Config_folder").rstrip("/")
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name in ["documentid", "data_file", "credentials_file", "token_file"]:
|
||||
return self.data[name]
|
||||
for key in self.data.keys():
|
||||
if name not in self.data[key]:
|
||||
continue
|
||||
return self.data[key][name]
|
||||
# raise NameError("Config options not found!")
|
||||
@property
|
||||
def documentid(self):
|
||||
return self.config.get("Docs_Settings", 'Document_ID')
|
||||
|
||||
@property
|
||||
def data_file(self):
|
||||
return self.config_folder + "/" + self.config.get("Docs_Settings", "data_file")
|
||||
|
||||
@property
|
||||
def credentials_file(self):
|
||||
return self.config_folder + "/" + self.config.get("Docs_Settings", "credentials_file")
|
||||
|
||||
@property
|
||||
def token_file(self):
|
||||
return self.config_folder + "/" + self.data['Docs_Settings']['token_file']
|
@ -45,6 +45,9 @@ def docs_parse() -> None:
|
||||
document = service.documents().get(documentId=config.documentid).execute()
|
||||
if os.path.exists(config.data_file):
|
||||
os.remove(config.data_file)
|
||||
|
||||
with open("configs/temp.file", 'w') as f:
|
||||
f.write("1")
|
||||
|
||||
with open(config.data_file, 'w') as f:
|
||||
json.dump(document, f, ensure_ascii=False)
|
||||
|
@ -193,13 +193,22 @@ class Helper():
|
||||
|
||||
@classmethod
|
||||
def get_link_and_download(cls, id_doc, document):
|
||||
with open("configs/temp.file") as f:
|
||||
data = f.read()
|
||||
if data == "0":
|
||||
return open("configs/photo.base64", 'rb').read()
|
||||
if "inlineObjects" in document:
|
||||
if id_doc in document['inlineObjects']:
|
||||
link = (document
|
||||
['inlineObjects'][id_doc]['inlineObjectProperties']
|
||||
['embeddedObject']['imageProperties']['contentUri'])
|
||||
r = requests.get(link, stream=True)
|
||||
return base64.b64encode(r.content).decode('utf-8')
|
||||
photo = base64.b64encode(r.content).decode('utf-8')
|
||||
with open("configs/photo.base64", 'w') as f:
|
||||
f.write(photo)
|
||||
with open("configs/temp.file", 'w') as f:
|
||||
f.write("0")
|
||||
return photo
|
||||
|
||||
@classmethod
|
||||
def find_image(cls, document):
|
||||
|
Loading…
Reference in New Issue
Block a user