Can python format the emails it sends? - python

I have a script that runs at evening, it writes to a log file as it runs, and once the task completes, the text it writes is also emailed to me. Sometimes the task can fail, what I want to happen is when I get the email, the line with the error is red and bold.
So my question is, can Python format text to a certain font or color if certain conditions are met? If so, are there any good examples?
Thanks!

I think you could just add html tags to your email and send it as HTML. However it'll change the content of your text file as it'll write additional characters to change the styling.
EXAMPLE:
Sending HTML email using Python

Related

Python imaplib recover emails with \\Deleted flag and move to trash

I've been getting a lot of spam emails from various colleges. I wrote a simple Python program to go through my emails, and find all the ones whose sender ends in .edu.
Then, to delete it, I though I was supposed to add the \\Deleted flag to those emails using: Gmail.store(id, "+FLAGS", "\\Deleted"). This did not work, and some of them didn't even disappear from the inbox.
After more research, I found that instead I had to use Gmail.store(id, "+X-GM-LABELS", "\\Trash").
So I updated the program to use that, but now it doesn't see any of the emails that I previously added the \\Deleted flag to.
Is there any way I can reset all those emails and then trash them afterward?
They should be in your All Mail folder. Use the WebUI and search for them and trash them, or select the "[Gmail]\All Mail" folder (watch out for localization, this can change name for non-English users).

Need help understanding looping a program/ nested loops in Python

Working on a program to automate some daily functions that I do using Selenium to interact with a browser.
I have the script working exactly as I want it to with one email account, however I have several I would like to automate. I would like it to be able to choose one email, complete the entirety of the code, loop back to the beginning, and continue from the beginning, but with my next account in the variable.
For example, my login data is stored like this:
emails=('email1#email.com',
'email2#email.com',
'email3#email.com',
)
myPassword=('passwordtext')
And is called during the login process in this way, just for reference:
for email in emails:
emailid=driver.find_element_by_name('email')
emailid.send_keys('email') # this is the variable that would need to change each time
password=driver.find_element_by_name('password')
password.click()
password.send_keys(myPassword)
password.send_keys(Keys.ENTER)
# then, several more work functions are completed using Selenium
Obviously, this doesn't work and leads to all of the email addresses in the variable being cycled through, and then the code continues. What I would like is for one email address to be selected, the rest of the program is executed, and then it loops back to the beginning and continues with the next email address in the variable.
I'm pretty sure the solution is a nested loop here and that this is a pretty basic question, but I can't get my head around how to set that up. Again, the rest of the program works perfectly, I'm just trying to figure out a way to loop through the program, changing only the login information, until the end of the variable. I hope this makes sense.
Everything that you want to run for each email address needs to be indented under your for email in emails: line.
There is no need for a nested loop.
for email in emails:
stuff_that_runs_once_per_email_address
stuff_that_runs_independent_of_email_address

How can one create an open web interface to a Python script that accepts and returns text?

I have a Python script that accepts text from a user, interprets that text and then produces a text response for that user. I want to create a simple web interface to this Python script that is accessible to multiple people at once. By this I mean that person A can go to the website for the script and begin interacting with the script and, at the same time, person B can do the same. This would mean that the script is running in as many processes/sessions as desired.
What would be a good way to approach this?
Maybe you should try a python web framework like django or flask .etc
Make a simple website that offers a webpage that contians a form to input text ,and when people visit the url, put their text in the form and submit, your code can handle it and return a webpage to show the result.

AS3 Make user input safe for display in htmltext

I've been searching for a good hour or two for this but I haven't found anything to what I'm looking for.
I'm making a chat application( socket server made in Python ) and it's working fine. The main chat area where messages are stored use HTML, it just displays the username in bold along with their avatar and message. The problem I'm having is how do I stop the user from entering HTML and messing with the main chat? I'm currently using regex "/<.*?>/g" to remove HTML tags however I'd rather let the user send things like
<p>Hi everyone</p>
but instead of parsing what was sent as HTML just normal text?
For example, right now. While a user is typing I'm using regex to remove
<whatever>
tags as soon as they're typed. What I want is for the user to be able to type
<b>bold text</b>
and send but not display it as bold and show the b tags.
Here's what "mainChat" text box looks like http://prntscr.com/46hd4t, this stores all messages
Here's what "chatMessage" text box looks like http://prntscr.com/46hdc6, this is where the user writes their message
Sites such as reddit and Stack Overflow use a standard called markdown for editing text that takes care of these issues. Some popular options for markdown editors include WMD, markitup and Epic Editor. Just Google markdown there are many options to choose from.

telnetlib | read all message when I have to click space if do it mannually

As you know, sometimes, you have to click space to get the next page under telnet connections, unix. For instance, you 'more' a text file. You can't get all the content at one time. Using 'space' can get to the next page.
Here is the problem, what should I do when using telnetlib, python? I have to get all the information. Posting codes here would be better. Thanks!
Instead of using more(1) or less(1) to view a file, use cat(1). It will not perform any pagination tasks and will write all the content of the file to the terminal, raw.

Categories