How to get google ID from email - python

I'm using google ID as the datastore id for my user objects.
Sometimes I want to find a user by email. The gmail address can appear with dots or without, capital letters and other variations. How can I retrieve the user id from the given email?

First of all you should store the email property always in lowercase since the case is not relevant. Now if you also want to take into the account the dot or the plus symbols and being able to query on them, you should then store in another (hidden) property the stripped out version of the email and execute your queries on this one.

Google+ seems to have an API for this
https://developers.google.com/+/api/latest/people/search

Related

pywin32 - restrict, filtering by a list of potential senders

I need to iterate through every email within my project. I have more than 20000 mails. Therefore i read I need to use the restrict function. I found examples how to restrict to one specific domain
messages = messages.Restrict("#SQL=(urn:schemas:httpmail:SenderEmailAddress LIKE '%#domain.com')")
What do I need to use if have more than 100 domains or multiple (more than 100) Senders I want to use? Would it be a huge restrict function with logical OR connectors with all of the domains or can I input somehow a list into the restrict statement?
EDIT:
and i realized if i run a restrict function with this code, it just shows me with the len(messages) function that there are 0 emails while i can see a bunch of emails in outlook with used domain in the filter. what am i doing wrong?
Typically you would need to use the logical OR operator in the search string. Read more about that in the Filtering Items Using a String Comparison article. Also you may find the following articles helpful:
How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
How To: Use Restrict method to retrieve Outlook mail items from a folder
But I would recommend handling each domain separately, so you will get Outlook running without freezes and will be able to process items in a logical bunch, especially when you have a hundred of domain names to search for.
If you want to filter out internal senders and only process the senders outside your organization, check the SenderEmailType property - it will be "EX" for the internal senders (assuming you are using Exchange Server) and "SMTP" for the external senders.

Django: How to query terms with punctuation (ie: !.;’) insensitivity?

I am creating an application that needs to find facebook usernames that I’ve stored in the database, but facebook usernames are both case insensitive and insensitive to periods. For example, the username Johnsmith.55 is the same as johnsmith55 or even j…O.hn.sMiTh.5.5. when sending facebook API requests.
Obviously, I am using the _iexact query command to remedy the case insensitivity, but what can I use to remedy the insensitivity to periods? I know a cop out method is simply to save all usernames to the database after stripping them of periods and also stripping the username that’s being searched of its periods and then querying, but I want to save and display people’s username’s the way that they really appear in their facebook URL (which includes periods) even though facebook API requests technically are insensitive to periods.
Any ideas for a simple method of doing this? Thanks in advance for any help
You can store two user names in your DB, one to query against and one to display.
However, if you don't want to have to do that, it's simple matter of cleaning the string from the characters Facebook ignores before querying:
# ... import 're' and pull username from DB
normalized_username = re.sub('[,.]', '', real_username)
# query using the normalized username
Note: This example ignores dots and commas, Facebook may ignore more than that.
You'll need to store two versions of the username: one for querying against, and one for display.
You can also implement your own querying loguc with custom lookups in Django 1.7 or later.

Use python to detect outlook auto-responder before sending message

I have found many resources on inspecting the headers in an email to detect whether or not the message was sent using an auto-responder. I'm looking to detect that an auto-responder is configured before any contact is made.
Why I think this is possible: In outlook, if you add a recipient from the address book it will show their auto-responder message above the "To:" line before even clicking send.
Goal: I would like to pass a list of employees to a function and return a binary list of whether or not they are in the office based on auto-responder on/off status.
Some bad psuedo-code (please excuse the mixing of classes and lists, it's just for a simple example).
list = ['Ted Jones', 'Michael Brickman', 'This name', 'That name']
for employee in list:
if employee.autoresponse != '':
employee.inoffice = 0
output = [0,1,1,1] #-- So, Ted Jones is out of the office
I'm certainly not stuck on this style of output, just trying to be specific. I need some sort of ordered list or something to tie Name -> In/Out of office
I would like to stay in Python if possible, but am interested to hear other solutions.
Is there anyway to do this? Maybe using win32com or pyad? If a resource for this information exists please let me know... I was unable to find it among the 'check the headers' muck.
You will have to either use Outlook's automation interface, or do the same thing Outlook does (presumably via MAPI or AD), or do the equivalent with some other API.
You can use win32com for the first of the three.
When you add a recipient to the To list in Outlook, it's getting a Recipient object, which has an AutoResponse property, which Outlook will show you.
The easiest (if maybe not the cleanest) way to get a Recipient object through the OOM is to do the exact same thing: create a dummy message, add a recipient, then look at its properties. Items have Recipients objects, which have an Add method that takes an identifier and returns a Recipient (and adds it to the item's recipients, of course).
So, the code should look something like this (untested because I don't have a Windows/Outlook box connected to Exchange here):
session = win32com.client.Dispatch("Mapi.Session")
session.Logon(MY_PROFILE)
outlook = win32com.client.Dispatch("Outlook.Application")
message = outlook.CreateItem(0) # olMailItem
autoresponses = {}
for name in names:
recipient = message.Recipients.Add(name)
autoresponses[name] = recipient.AutoResponse
You can of course combine that into a one-liner dict comprehension, but I thought this might be clearer. Also, you probably want to discard the message so Outlook doesn't end up sticking your leftover garbage in Drafts or something, and you probably want some error handling, and you may need to use a separate message for each recipient to make it easier to recover from errors and move on, and so on… But this, together with the MSDN and win32com docs, should be enough to get you going.
Of course this only works if name resolves to a server mailbox; if you give a local-only name or address, or external-only address, you'll just let a local address book entry or a bare email entry, neither of which have an AutoResponse. But that's exactly the same as in Outlook, so presumably it's expected.
Also note that the first time your script does anything that tries to access the Address Book, unless the user has deliberately turned off the default safety features, he will get a popup like "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?"

weird Twitter API behaviour

I know sure is it me or everyone, I have a following code
http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=barbara_volkwyn
http://api.twitter.com/1/statuses/user_timeline.xml?user_id=248623669
Apparently according to Twitter api, user with screen_name = "barbara_volkwyn" has the user id = 248623669, however, when I run the above API call I get totally different result, one thing that's even weirder is if I try to run the second API call, the users object contain in the returned result is not even the same user.
I wonder anyone has the same problem, feel free to give it a try.
Regards,
Andy.
your userID of barbara_volkwyn isn't valid. It should be: 264882189
You can fetch userID's trough the api or with https://tweeterid.com/
The user_ids reported by the Search API aren't the same as the user_ids used in the Twitter REST API -- unsure if that's where you found the user_id 248623669 or not though.
A timeline contains tweets which in turn contain embedded (but cached) user objects, usually reflecting the state of the user at the time the Tweet was published. Sometimes users change their screen_names, so a user by the name of #barbara_volkwyn might be user_id 1234 one day and user_id 5678 the next day, while the tweets that belonged to user_id 1234 will always belong to user_id 1234, regardless of the screen_name.
The user_id for #babara_volkwyn according to the REST API is 264882189. It's entirely possible that someone held the same screen name but a different user_id at another time. The only way to ever be certain about the identity of a Twitter user is to refer to them by their REST API user_id -- screen_names are transitory and can be modified by the end-user at any time.
As I mentioned, cached user objects used within statuses can become stale -- the most reliable source for up-to-date information about a single user account is the user/show API method. The most reliable source for up-to-date information on recent Tweets by an account is the statuses/user_timeline method.
The embedded objects work for most scenarios, but if you're looking for maximum accuracy, the distinct resources are best.
Thanks, Taylor.

Comparing user's facebook/twitter friends to site's users in Python/Django

I'm wondering if someone could help guide the approach to this fairly common problem:
I'm building a simple site which a user connects their twitter account to sign up. I'd like to create an interface which shows them which of their twitter friends are already using the site.
So I can get a list the user's twitter friends, and a list of the site's users (which all have the twitter screen name as username, but I'm wondering the most efficient method to compare these lists and create a variable with the commonalities.
As an aside, given the Twitter API returns IDs, should I save the twitter user's ID (in addition to their username) when they create an account?
Thanks in advance!
Create Sets out of them, and use the intersection method:
intersection_set = set(list_a).intersection(list_b)
You should store the twitter user's ID because the username can change at any time, but the id will always be the same. You should be comparing the id's, not the usernames in the intersection_set that Ofri recommends.

Categories

Resources