hi everyone i am currently building a program which logs into an email, extracts information like the date, sender, subject, number of copies, and takes any attachments and puts them into a directory, than takes the number of pages of the pdf. i have already built a program which does all of this(below is the program).
now i am stuck i need to be able to put this information in to a spreadsheet for acounting in the following format.
job Date teacher copies pages
with the job number justing counting by 1's
the date which is already in the generated by the output
the teacher which is generated by the output
the number of copies which is generated by the output and
the number of pages which is also generated by the out put.
i am farly new to python programming, and really dont know how to create an spredsheet with this information. i tried doing a import xlwt but i wasnt able to install the module because it kept giving error when i tried to install the setup.py on my mac. is there any other script i can use to create the spreadsheet im looking for.
another question i have is since i am working with many different files and emails, and that my strings appear as many different names depending on the number of emails and pdfs i get, how can i input this information on a spreadsheet on different cells?
if anyone could help it would be greatly appreciated, just try to play around with my code and try to see if you could add script to it so that it can accomodate for the spreadsheet the way i want it to, thank you very much!!
import email, getpass, imaplib, os, string, re
from itertools import takewhile
from operator import methodcaller
detach_dir = '/Users/defaultuser/Desktop' # directory where to save attachments (default: current)
m = imaplib.IMAP4_SSL('imap.gmail.com')
m.login('********@*****.com', '*******')
m.list()
# Out: list of "folders" aka labels in gmail.
m.select("inbox") # connect to inbox.
resp, items = m.search(None, "ALL") # you could filter using the IMAP rules here (check http://www.example-code.com/csharp/imap-search-critera.asp)
items = items[0].split() # getting the mails id
for emailid in items:
resp, data = m.fetch(emailid, "(RFC822)") # fetching the mail, "`(RFC822)`" means "get the whole stuff", but you can ask for headers only, etc
email_body = data[0][1] # getting the mail content
mail = email.message_from_string(email_body) # parsing the mail content to get a mail object
#Check if any attachments at all
if mail.get_content_maintype() != 'multipart':
continue
teacher = mail["From"]
subject = mail["Subject"]
d = mail["date"]
date = d[0:16]