25 lines
675 B
Python
Executable file
25 lines
675 B
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import os
|
|
import sys
|
|
import pathlib
|
|
import subprocess
|
|
import time
|
|
import argparse
|
|
from apiclient import discovery, errors
|
|
from oauth2client import client, file
|
|
from httplib2 import ServerNotFoundError
|
|
|
|
DIR = os.path.dirname(os.path.realpath(__file__))
|
|
CREDENTIALS_PATH = os.path.join(DIR, 'credentials.json')
|
|
|
|
if not os.path.isfile(CREDENTIALS_PATH):
|
|
print(0)
|
|
else:
|
|
try:
|
|
gmail = discovery.build(
|
|
'gmail', 'v1', credentials=file.Storage(CREDENTIALS_PATH).get())
|
|
labels = gmail.users().labels().get(userId='me', id='INBOX').execute()
|
|
print(labels['messagesUnread'])
|
|
except Exception as e:
|
|
print(0)
|