I am trying to read e-mails in a Lotus Notes database via python and com. (using pythonwin and win32com)
I can connect to the database and read NotesDocument items but
doc = folder.GetFirstDocument()
doc.GetItemValue('Body')
returns the plain text contents of the email. I can get the headers, subject, date, etc but body is plaintext. I'm trying to fetch the HTML source of the email which includes links and other formatting. I know the stuff is there because within Notes I can view-->show--> page source.
I've tried
doc.GetMIMEEntity('Body')
but this returns None.
Try adding this line right after where you get the session:
session.ConvertMIME = False
Update:
Barry commented that it worked this way:
doc.GetFirstItem("Body").GetMIMEEntity()
The body is a rich text item. You won't be able to access the HTML version of the body field, but you can navigate around the rich text item using the NotesRichText... classes.
The NotesRichTextNavigator class has an example to get you started. It is unfortunately not very easy to get around in that object.
Related
I am looking to parse the Wikipedia talk page (e.g., https://en.wikipedia.org/wiki/Talk:Elon_Musk). I would like to loop through texts by contributors/editors. Not sure how do I do it. For now, I have the following code:
import pywikibot as pw
wikiPage="elon_musk"
page = pw.Page(pw.Site('en'), wikiPage)
talkpage = page.toggleTalkPage()
s=talkpage.text
cs=talkpage.contributors()
It seems pretty hard to parse the text (i.e., s) and find the talk text made by each contributor. Not sure where the talk begins and ends for a contributor and what talk text is in response to a talk text made by others. Is there a way that talk page returns segments that I can loop through?
Many thanks for your help!
I don't know about pywikibot, but you can do this via the normal API. This will fetch the revisions: https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Talk:Elon%20Musk&rvlimit=500&rvprop=timestamp|user|comment|ids
Then you can pass the revision ids to get the change in each edit: e.g. https://en.wikipedia.org/w/api.php?action=compare&fromrev=944235185&torev=944237256
I'm looking for a python solution to create a static .html that can be sent out via email, either attached or embedded in the email (ignore this latter option if it requires a lot more work). I do not have requirements for what regards the layout of the .html. The focus here is in identifying the less painful solution for to generate an offline .html.
A potential solution could be along the lines of the following pseudo-code.
from some_unknown_pkg import StaticHTML
# Initialise instance
newsletter = StaticHTML()
# Append charts, tables and text to blank newsletter.
newsletter.append(text_here)
newsletter.append(interactive_chart_generated_with_plotly)
newsletter.append(more_text_here)
newsletter.append(a_png_file_loaded_from_local_pc)
# Save newsletter to .html, ready to be sent out.
newsletter.save_to_html('newsletter.html')
Where 'newsletter.html' can be opened in a whatever browser. Just to provide a bit more context, this .html is supposed to be sent out to a few selected people inside my company and contains sensible data. I'm using plotly to generate interactive charts to be inserted in the .html.
Possible solution here
Seems package in that answer is exactly you want. Docs: http://www.yattag.org/
Another pretty nice package here.
Start your python module with by importing sys module and redirect stdout to newsletter.html
import sys
sys.stdout = open('newsletter.html','w')
This will redirect any output generated to the html file. Now, just use the print command in python to transmit html tags to the file. For eg try:
print "<html>"
print "<p> This is my NewsLetter </p>"
print "</html>"`
This code snippet will create a basic HTML file. Now, you can open this file in any browser. For sending email you can use email and smtplib modules of python.
The Dominate package looks like it provides a simple and intuitive way to create HTML pages. https://www.yattag.org/
I'm trying to fetch all posts on specific page after certain time. I'm using this facebook-sdk for python. Last post on the page has been posted 30th may 2017. The problem with my query is that even if I try to limit the query with since='2017-06-06T09:00:00+00:00', it always returns my posts from the page.
My timestamp is in exact same format as I get it if I query it from the facebook.
Here's the code
facebook_api = facebook.GraphAPI(access_token='FACEBOOK_PAGE_ACCESS_TOKEN')
facebook_feed = facebook_api.get_object(
id=FACEBOOK_PAGE_ID,
fields='feed',
since='2017-06-06T09:00:00+0000'
)
I don't have a clue what kind of api query url facebook-sdk for python creates with this code and I don't know how to check that.
I also tried converting timestamp to unix timestamp with online tool, but it didn't work either.
get_object() will query the root node directly, not the non-root nodes. Use get_connections() instead.
Read more here about objects: https://developers.facebook.com/docs/graph-api/reference/
Try below code, it works for me.
import facebook
facebook_api = facebook.GraphAPI(access_token='YOUR_ACCESS_TOKEN')
facebook_feed = facebook_api.get_connections('YOUR_PAGE_ID', 'feed', since=1496707200)
print facebook_feed['data']
Absent<br>\r\n\t\t\tW - Withheld\r\n\t\t\t\r\n\t\t\t<b>Note:</b><br>\r\n\t\t\tThis Sheet is for general idea of marks you secured. This is not for official use. If any mistakes appear; record at NEB ledger will be referred.\r\n\t\t\r\n\r\n\t\t\r\n\t\t\r\n\r\n \t\t\r\n </br></br></br></br></br></td>\n</tr>\n</table> is not JSON serializable
This is the exact error I get when trying to access the handle passing all the values. The html content that can be seen there are what I exactly need.I have copied only few sections of it since it was large tags with table and rows. I was able to successfully to load this in web application but here I am working with API.
is not JSON serializable
I am scraping a site and from the site I am getting the html table content and trying to return that via my REST API build with flask-restful
marks=requests.post("somesitelinkhere",data=data_load2)
soup2=BeautifulSoup(marks.content,'html.parser')
#this is the heading to show what Result it is
headinghere=soup2.find('h2').text
markstable=soup2.find('table')
return {'marksheet':markstable}
Consider the above code I have successfully scraped the content and which in available in markstable variable.Now how do I return it so that it will be accessible when trying to access with the specific handle. What do I have to do to make it serializable or what is the best way to return such content in REST API.
markstable is a BeautifulSoup.Tag object. You can extract the content string from it using markstable.contents and send it over as the response.
I've been able to send emails using Lotus Notes and VBA and Python using the COM API like this:
Can I use Lotus Notes to send mail?
My question is how can I insert an image inline with the body text (not as an attachment) in a programmatic way (equivalent to the Edit | Paste Special)? I haven't been able to find any workable solutions from a few Google searches. Any solution using stock VBA or Python would be appreciated.
Thanks!
If you don't need to do anything specific to Notes, i.e. work with a specific form with #functions etc, then you are much better off constructing the message as a multipart mime message.
You need to set up the session so that when you create the document it is mime and you can then set up your message appropriately, see NotesSession.ConvertMIME. You will then use NotesMIMEEntity and NotesMIMEHeader objects to construct the mime message.
If you are unfamiliar with how mime messages are constructed then this is going to be a little tricky, so you may want to have a look at some raw mime messages to see what they look like. From there you should be able to work out how to use the api for the NotesMIMEEntity and NotesMIMEHeader classes to construct the message.
It should be possible to do this using the DXLImporter class, available from VBA through the COM interface. DXL is a Notes-specific XML, which you can generate to a temp file, then import into your database. There is sample code on this blog entry, which may be close to what you are looking for (this imports a rich-text body, including in-line image, and then attaches that rich text to a mail document).
http://www.cubetoon.com/2008/notes-rich-text-manipulation-using-dxl/
Other options you might consider are:
(1) using the C or C++ API's - definitely more effort, especially when working with rich-text, but would essentially have no limits. (http://www.ibm.com/developerworks/lotus/library/capi-nd/index.html)
(2) using the MIDAS Toolkit from Genii (http://www.geniisoft.com) - extends the Lotuscript API's and exposes much of what is in the C API.