I have a pandas dataframe that I am sending to myself via email.
I am able to control the font size of the heading and body, however the dataframe itself is its default size which is a bit small for me.
How do I increase the font size of the table that is being sent?
Here is the html part of code I am using:
html = """\
<html>
<head></head>
<h1 style="color:red;font-size:25px;">This is My Header</h1>
<p style="width:50px;height:50px;">
<body>
{0}
</body>
</p>
</html>
""".format(df3.to_html())
consumptions = MIMEText(html, 'html')
msg.attach(consumptions)
Any suggestions?
Related
I want to generate a PDF with a specific background from three simple input-fields.
A title, a message and a signature as shown in the picture below.
Example of desired result
I have some experience with creating web-sites with Python Flask, but I struggle with how to tackle this challenge.
create a h1 containing the title, a h2 containing the message and a bottom text with some css
.bottom{
position:fixed;
bottom:0;
}
put the background-image tag on the body to have your own custom image
it would be something like this
<html>
<head>
<style>
.bottom{
position:fixed;
bottom:0;
}
</style>
</head>
<body style="background-image:url('mypicture.png'); text-align: center">
<h1>my title</h1>
<h2>my subtitle</h2>
<h2 class="bottom">bottom text</h2>
</body>
</html>
I hope someone will be able to help me form following issue that I am facing.
I just would like to insert a html from result of pandas into an entire html as below,
...
df_add_html=df_add.to_html()
template="""<html>
<head></head>
<body>
Pandas : left-only<br>
I want to insert df_add_html here
</body>
</html>"""
part1=MIMEText(template. 'html')
msg.attach(part1)
...
The purpose is that I want to merge many results from pandas to a html and I will send a email with the html.
I hope I would get some advice from you.
Thanks.
You can use standard format()
template = "text {} text".format(df_add_html)
or f-string
template = f"text {df_add_html} text"
template = """<html>
<head></head>
<body>
Pandas : left-only<br>
{}
</body>
</html>""".format(df_add_html)
or
template = f"""<html>
<head></head>
<body>
Pandas : left-only<br>
{df_add_html}
</body>
</html>"""
BTW: http://pyformat.info
If you need more complex templates (ie. with for-loop or if/else) then you can use jinja which is used to generate HTML in Flask (but you can generate any text file)
I am making a get request to https://racing.appledaily.com.hk/race-day/race-position?raceDay=1865&race=15632 with a chrome's developer page, i can see a full html page. However when i make a get request, python only returns part of the html.
HTML:
<html class="gr__racinng_applledaily_com_hk" style='overflow: initial;">
<head> ... </head>
<body data-gr-c-s-loaded="true">
<!-- Google Tag Mananger (noscript) -->
<noscript> ...</noscript>
<!-- End Google Tag Mananger (noscript) -->
<div data-v-6223d6a8 id="app" class="web"> ... </div>
</body>
</html>
the <div data-v-6223d6a8 id="app" class="web"> ... </div> part is missing
Code Used :
content = request.get('https://racing.appledaily.com.hk/race-day/race-position?raceDay=1865&race=15632')
Request gets the HTML from the source. When you use the inspector you see the full HTML because your browser renders the rest of the HTML. To get the full HTML look into Scrapy Splash or Selenium.
<html>
<body>
<h2>HTML Iframes</h2>
<p>You can use the height and width attributes to specify the size of the iframe:</p>
<iframe src="https://www.google.com/maps/embed/v1/place?key=AIzaSyAPi0wzs7IlNc4nlL3atU7iCd-A9QXfuHs&q=4.5596%2C-76.2801&zoom=18&maptype=satellite" height="200" width="300"></iframe>
</body>
</html>
So have this html file created on my computer, now i need to change what goes after src to a new string, example this -
https://www.google.com/maps/embed/v1/place?key=AIzaSyAPi0wzs7IlNc4nlL3atU7iCd-A9QXfuHs&q=25.5596%2C-7.2801&zoom=18&maptype=satellite
So how can i add that example line into a html file after src=?
from bs4 import BeautifulSoup
htmlstr = '''
<html>
<body>
<h2>HTML Iframes</h2>
<p>You can use the height and width attributes to specify the size of the iframe:</p>
<iframe src="https://www.google.com/maps/embed/v1/place?key=AIzaSyAPi0wzs7IlNc4nlL3atU7iCd-A9QXfuHs&q=4.5596%2C-76.2801&zoom=18&maptype=satellite" height="200" width="300"></iframe>
</body>
</html>
'''
soup = BeautifulSoup(htmlstr)
iframe = soup.find('iframe')
iframe["src"] = "test"
print(soup)
this should be the solution you're looking for. replace the iframe["src"] = "test" with the link you want to provide and save the result back to the html file.
I want to map resource tags in content to resources received from evernote.
Resources -
I am able to see all resources fetched from evernote,
eg:
for r in resources:
file_content = r.data.body
file_type = r.mime
filename = r.attributes.fileName
hashvalue = r.data.bodyHash
//i want this resource to bind to its image tag
HTML -
<html>
<body>
<div>ddkfmdk</div>
<div>
<br/>
</div>
<br/>
<img class="attach_img" src="/images/ef89ec799076f38a6f50b2acd58a5f4f.png"/>
br/>
<img class="attach_img" src="/images/ef011616fa96b4550dae7267ecee68fd.png"/>
</body>
</html>
We receive list of resources from evernote, but how would I bind these resources to particular image tags