Rebase
This commit is contained in:
@@ -68,7 +68,6 @@ def get_about_replacements() -> dict:
|
||||
count = document['body']["content"][element]["table"]["rows"]
|
||||
except (IndexError, KeyError):
|
||||
image, image_bytes = helper.find_image(document)
|
||||
print(image)
|
||||
if not image:
|
||||
element = helper.find_with_table(document)
|
||||
if element:
|
||||
|
@@ -32,14 +32,6 @@ self.months = {
|
||||
}
|
||||
'''
|
||||
|
||||
headers = {
|
||||
'user-agent':(
|
||||
"Mozilla/5.0 (Windows NT 10.0; WOW64) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/62.0.3202.9 Safari/537.36"
|
||||
)
|
||||
}
|
||||
|
||||
class Helper():
|
||||
|
||||
def __init__(self):
|
||||
@@ -199,13 +191,23 @@ class Helper():
|
||||
element += 1
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_link_and_download(cls, id_doc, document):
|
||||
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')
|
||||
|
||||
@classmethod
|
||||
def find_image(cls, document):
|
||||
for i in document['body']["content"]:
|
||||
if ("paragraph" in i) and ("elements" in i["paragraph"]):
|
||||
if "inlineObjectElement" in i["paragraph"]["elements"][0]:
|
||||
import base64
|
||||
return True, base64.b64encode(open("photo.png", 'rb').read()).decode('utf-8')
|
||||
if "inlineObjectElement" in i["paragraph"]["elements"]:
|
||||
return True, cls.get_link_and_download(
|
||||
i["paragraph"]["elements"]
|
||||
['inlineObjectElement']['inlineObjectId'], document)
|
||||
return False, None
|
||||
|
||||
|
Reference in New Issue
Block a user