I just got started programming a year ago (on and off) and I am trying to save an attachment to a folder offline from my personal GMAIL account.
I was advised to use :
https://developers.google.com/gmail/api/quickstart/python
I set up the
I authenticated the my account and now am trying to get comfortable with this tool.
There are some initial questions that I have
What is User ID ?
is this my email ( tttt#xxxx.xxxx)
or someone else's email (ppppp#yyyy.yyy)
How do I get a email ID's ?
These questions stem from ...
GET https://www.googleapis.com/gmail/v1/users/userId/messages/messageId/attachments/id
from the page :
https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get
Again I am just learning from a beginner place..
Thanks
Just use "me" as the userId as it says in the doc.
To get a messageId first you have to search (list) messages, using something like:
resp = gmail.users().messages().list(userId="me", q="has:attachment subject:'foo bar' before:"2014-01-05").execute()
you can then iterate through the 'messages' in that resp and
gmail.users().messages().get(userId="me", id=message['id']).execute()
The Gmail API guides are quite helpful, take a look at them, for example:
https://developers.google.com/gmail/api/guides/filtering
Related
I'm trying to figure out how to authenticate and create an entry on quickbooks online through Python. Currently, when I try to click auth link in their API Explorer, I get 404 page.
What I'm trying to do is creating invoice through Python. However, it seems like their documentation is not complete. I contacted their support, and I haven't heard from them yet.
The python-quickbooks library is probably the correct choice now, as it is a "complete rework of quickbooks-python". It has pretty comprehensive instructions on getting and using the auth keys, though I wouldn't call it "simple", since the process is by definition somewhat complex. The instructions are "for Django", but the Django-specific code simply gets parameters out of a URL string.
We're using it to great effect, because the syntax is as easy as:
auth_client = AuthClient(
client_id = CLIENT_ID # from QB website
,client_secret = CLIENT_SECRET # from QB website
,environment = 'sandbox' # or 'production'
,redirect_uri = REDIRECT_URI
)
client = QuickBooks(
auth_client = auth_client
,refresh_token = REFRESH_TOKEN
,company_id = COMPANY_ID
)
account = Account.get(qbid, qb=client) # qbid can be retrieved from the AccountList
return account.CurrentBalance
This library will get the job done https://github.com/HaPsantran/quickbooks-python
It works in JSON so you would construct the Invoice based off of docs at https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice using the JSON examples.
The library doesn't support sandbox mode** so if you are going to use the development consumer key and secret than you would change this code.
base_url_v3 = "https://quickbooks.api.intuit.com/v3"
to
base_url_v3 = "https://sandbox-quickbooks.api.intuit.com/v3"
while in that mode.
** Sandbox mode only applies currently to U.S. QBO
Having written a lot of the module #Minimul mentions — with a very helpful start by simonv3, who figured out how to get it working first and then I just built on it — I am fairly confident that this will not support the oauth workflow of getting the request token, prompting the user to authenticate out of band, and then getting and storing the access token. It presumes you already have an access token.
Simon (or another Python developer) may be able to comment on how he gets the access token with Python, and if so, it'd be great if he (or they) could add it to the module for all to enjoy.
I had this same problem. I just figured it out and posed the step-by-step process here:
python with Quickbooks Online API v3
Hope this helps.
I looked at the existing python clients for quickbooks and found them to be either outdated or not having all the features. So i created a new python client for quickbooks which can be found at https://pypi.python.org/pypi/quickbooks-py
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Reading e-mails from Outlook with Python through MAPI
I am completely new to Python and have been given the task to write a program that connects to my Microsoft Outlook mailbox, goes through all the emails and if the subject has a certain word, then the details of the email time and subject will be saved in variables, as well as the email message body will be parsed and relevant information will be stored in variables. Then this information will be stored in an external server/database. It also needs to be able to monitor any new emails that comes to my mailbox and repeat the drill of checking the subject line and taking appropriate action.
I have written exactly the same kind of program in C# earlier using the Interop library, but now need to do this in Python. I can figure out the nitty-gritty details by readin gthe module documentations later on, but from a high level perspective what modules should I use. I have been doing my research and some modules that have been mentioned include email, procmail and imaplib, but what do the Python veterans here recommend for the kind of project I am overtaking?
Thanks in advance for any help you might be able to provide!
At one company I worked we have a mailbox for suggestion with websites that had 'adult' material and one mailbox for spam mail that should be blocked.
Once I began working I was in 'charge' of this 'gracious' jobs.
Checking it there was something like 2000 unread mails to block and 4000 spam mails to block too.
Of course that is a function to be automatized and I looked for a good solution for me.
What I did:
[1] Used python IMAP to connect to Exchange server
[2] Used beatifulsoup (python) to parse the href values inside the email
[3] After that send a email 'thanking' the user for its collaboration (very important)
Three days after my boss thanked me for the great effort I was doing answering all the e-mails and that we got compliments. Because NOW we are answering back the customers. (not me the script)
Ok. now lets do a plan
Check the imap python module [1], and after take one tutorial using ssl imap4 [4]
Decide What is best for YOUR problem? Download the emails (pop3) or search and browse it at server (IMAP).
CHECK if you can connect using the protocols IMAP4 or POP3 Before, exchange is buggy in this part please check this bug report too [3]
Ok, you are sure you can connect using IMAP4 or POP3, now fetch one message and parse it with beatiful soup or lxml. (my case I looked for href and 'mailto:')
Do a nice message using the field 'from:' the email making it personal
PROFIT
[1] google it imap python
[2] google it BeautifulSoup python
[3] http://support.microsoft.com/kb/296387
[4] http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/
Sorry but I had to give the google urls because of my low score.
I hope this answer give you some good pointers to your solution.
Of course you can make it more hax0r using lxml, sending the data to a DB.
But after you connect and start manipulating you can do anything :)
I am trying to work for sending sms from gmail using python.
I have tried many solutions but it didnt worked.
I tried to use libgmail but seems to be deprecated. Even I am not able to find how to send sms from gmail to jawwal where as actually gmail sends free sms to jawwal.
My code is:
import libgmail
from TextMessaging import *
sender = Sender(<username>, <password>)
txtM = TextMessage(subject, body)
receiver = Receiver("<phone no>", "Jawwal")
sender.sendMessage(receiver, txtM)
in this, on sender it gives error as expected string or buffer
and for reciever, i dont know whats carrier for jawwal like
CARRIERS = {"Alltel":"alltelmessage.com",
"ATT":"mobile.mycingular.com",
"Rogers":"pcs.rogers.com",
"Sprint":"messaging.sprintpcs.com",
"tMobile":"t-mobile.net",
"Telus":"msg.telus.com",
"Verizon":"vtext.com"}
Kindly give me on any information how to send sms to gmail using python script.
Thanks
Perhaps you would want to use one of these services:
[https://www.twilio.com/sms][1]
[http://www.clockworksms.com/][2]
They provide REST API options.
I know this is an old question, but just posting for someone searching for an answer.
"As of April 1, 2014, sending SMS messages to phone contacts through Google Chat in Gmail was
discontinued for all supported mobile operators."
https://support.google.com/chat/answer/112176?hl=en
I think the carrier's email address for your phone is as such:
jawwal.com.country_code
Replace country_code with the appropriate URL extension (.sa, .lb, etc.).
Here is what I want to achieve :
1) An email should be sent to using "email address & details" mentioned in a Google docs/excel file.
2) The email should also pick up some content from a web page .i.e Title, URL etc. & include in the email sent.
Do let me know, how or where do I begin?
Start reading this http://docs.python.org/library/email
You might want to start by writing something that just downloads the document and writes it to file. Python has a module for using most of its services: Youtube, gmail, docs, etc.
You could get the gdata client here: http://code.google.com/p/gdata-python-client/downloads/list
And a good place to start would be here: http://code.google.com/apis/documents/
I'm having problems to find a simple python twitter oauth example which shows how to post a user status on Twitter. Could you help me?
Check out Mike Knapp's library on GitHub.
Nice and simple, no install needed.
Here's an example that will get you authed with Twitter using rauth.
After that point all you'd have to do to update the authenticated user's status is:
r = session.post('statuses/update.json',
data={'status': 'Updating my status from the cmd line.'})
print r.json()
(You only need to care about the code up until you retrieve your authenticated session object, i.e. line 20.)
Hope this helps!
Edit
You will need to get your own consumer_key and consumer_secret for this to work because the rauth demo app does not have write permissions, for obvious reasons. So you'll end up with this response if you try to run the modified script without updating the credentials:
{u'request': u'/1/statuses/update.json', u'error': u'Read-only application cannot POST'}
Ensure your application is allowed to write and it should work as expected.
Take a look on tweepy: http://code.google.com/p/tweepy/
Have you checked out http://github.com/simplegeo/python-oauth2 ?
Matthew A. Russell has written an excellent book on this, Mining the social web. Take a look at his excample source for OAuth to twitter. The code is available here, and i recommend his book also, covering not only twitter, but facebook and linkedin aswell.
The code is found here: OAuth to twitter and collect friends id's
Good Luck
Here is a simple twitter oauth example I wrote as a blog sometime ago. Hope this helps.
If you're refering to http://code.google.com/p/python-twitter/ ..
On that page it is documented as
api = twitter.Api(consumer_key='consumer_key', consumer_secret='consumer_secret', access_token_key='access_token',
access_token_secret='access_token_secret')
To see if your credentials
are successful:
print api.VerifyCredentials() {"id": 16133, "location": "Philadelphia", "name": "bear"}
That works. Ofcourse, your consumer key should never be human-readable in your application. But it would work even if it was.
*-pike
I've written an extremely simple twitter client (which is just for tweeting).
The source isn't the cleanest around, but the entire thing (including UI) is under 200 lines, so you should be able to extract anything you need from it: