Configuration modifcation and parser photo saver
This commit is contained in:
@@ -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):
|
||||
|
Reference in New Issue
Block a user