Пример #1
0
import presentation_writer
import spreadsheet_writer
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import client
from oauth2client import file as oauth_file
from oauth2client import tools

SCOPES = ['https://www.googleapis.com/auth/drive']
store = oauth_file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
    creds = tools.run_flow(flow, store)

slides_service = build('slides', 'v1', http=creds.authorize(Http()))
sheets_service = build('sheets', 'v4', http=creds.authorize(Http()))
drive_service = build('drive', 'v3', http=creds.authorize(Http()))


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        'command',
        help='The command to run',
        choices=['create_sheet', 'create_presentations', 'add_customers'])
    parser.add_argument('--spreadsheet_id', help='The spreadsheet to use')
    parser.add_argument('--template_id',
                        help='The presentation to use as a template')
    parser.add_argument('--customer_ids',
                        nargs='+',
Пример #2
0
import numpy as np
import datetime
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from schedule_scraper import Schedule_Scraper
import os

# Setup the Calendar API
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
default_calendar = 'primary'
dir_name = os.getcwd() + "/schedules"
year = '2018'  # TODO: Revisar aquesta bullshit
scraper = Schedule_Scraper(dir_name)
week_info = scraper.load_classes_from_files()
month = week_info[0]
classes = week_info[1]

# Call the Calendar API
now = datetime.datetime.utcnow().isoformat() + 'Z'  # 'Z' indicates UTC time

i = 0
for classe in enumerate(classes):
    #print(classe[1])
    if i < len(classes) - 1:
Пример #3
0
for temp_folder in glob.glob("OCR*"):
    shutil.rmtree(temp_folder, ignore_errors=True)

logger.info("Running pdf2text.py " + version)

SCOPES = 'https://www.googleapis.com/auth/drive.file'
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
    flags = tools.argparser.parse_args([])
    #flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
    #flags=tools.argparser.parse_args(args=[])
    flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
    creds = tools.run_flow(flow, store, flags)
service = build('drive', 'v3', http=creds.authorize(Http()))

file_metadata = {
    'name': 'ocr_files_shrini',
    'mimeType': 'application/vnd.google-apps.folder'
}
folder = service.files().create(body=file_metadata, fields='id').execute()
new_folder_id = folder.get('id')

# Read the config file

#input_filename = config.get("settings", "file_name")
input_folder = config.get("settings", "input_folder_name")
output_folder = config.get("settings", "output_folder_name")
columns = config.get("settings", "columns")
#working_directory = config.get("settings", "working_directory")
Пример #4
0
from httplib2 import Http

h = Http()

resp, content = h.request("http://localhost:8889/a/message/new", "POST", "up")
import time
import dateutil.parser as parser
from datetime import datetime
import datetime
import csv

flag = False

# Creating a storage.JSON file with authentication details
SCOPES = 'https://www.googleapis.com/auth/gmail.modify'  # we are using modify and not readonly, as we will be marking the messages Read
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
    creds = tools.run_flow(flow, store)
GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))

user_id = 'me'
label_id_one = 'INBOX'
label_id_two = 'UNREAD'
emailFrom = "akash tyagi <*****@*****.**>"

# Getting all the unread messages from Inbox
# labelIds can be changed accordingly
unread_msgs = GMAIL.users().messages().list(
    userId='me', labelIds=[label_id_one, label_id_two]).execute()

# We get a dictonary. Now reading values for the key 'messages'
mssg_list = unread_msgs['messages']

print("Total unread messages in inbox: ", str(len(mssg_list)))
Пример #6
0
def main():
    """Shows basic usage of the Google Calendar API.
    Prints the start and name of the next 10 events on the user's calendar.
    """
    store = file.Storage('token.json')
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
        creds = tools.run_flow(flow, store)
    service = build('calendar', 'v3', http=creds.authorize(Http()))

    #DATE

    dt = datetime.now()
    start = dt - timedelta(days=dt.weekday())
    end = start + timedelta(days=6)
    start = start - timedelta(hours=dt.hour)
    print('start: ', start)
    print('end: ', end)

    print('Getting the upcoming 10 events')
    events_result = service.events().list(
        calendarId=
        '*****@*****.**',  # Work OKE 
        timeMin=str(start.isoformat()) + "Z",
        timeMax=str(end.isoformat()) + "Z",
        maxResults=100,
        singleEvents=True,
        orderBy='startTime').execute()
    events = events_result.get('items', [])

    dates = {}
    if not events:
        print('No upcoming events found.')
    for event in events:
        try:
            if ("You" in event['summary']):
                print(event['summary'])
                print()
                #print(date.year, date.month, date.day, date.hour, date.minute )
                date = parse(event['start']['dateTime'])

                if (date.day not in dates):
                    dates[date.day] = []

                if (date.day in dates):
                    if ("entered" in event['summary']):
                        dates[date.day].append(('S', date.hour, date.minute))
                    else:
                        dates[date.day].append(('E', date.hour, date.minute))
        except:
            pass

    print(dates)
    days = []
    for date, value in dates.items():
        try:
            start = [x for x in value if x[0] == 'S'][0]
            end = [x for x in value if x[0] == 'E'][0]
            span = timedelta(hours=end[1], minutes=end[2]) - timedelta(
                hours=start[1], minutes=start[2])
            days.append(span)
            print(date, span)
        except:
            pass

    worktime = timedelta()
    for each in days:
        worktime += each

    worked = worktime.days * 24 + worktime.seconds / 3600
    print(worked)
Пример #7
0
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

CRED_FILE = os.path.join(BASE_DIR, 'credentials', 'credentials_gmail.json')
SCOPES = [
    'https://www.googleapis.com/auth/gmail.readonly',
    'https://www.googleapis.com/auth/drive'
]

store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('{}'.format(CRED_FILE), SCOPES)
    creds = tools.run_flow(flow, store)

GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
""" Drive API
"""

CRED_FILE = os.path.join(BASE_DIR, 'credentials', 'credentials_gmail.json')
SCOPES = ['https://www.googleapis.com/auth/drive']

store = file.Storage('storage1.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('{}'.format(CRED_FILE), SCOPES)
    creds = tools.run_flow(flow, store)

DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))

CRED_FILE = os.path.join(BASE_DIR, 'credentials', 'client_secret_sheets.json')
Пример #8
0
    'leg-07': '7',
    'leg-08': '8',
    'leg-09': '9',
    'leg-10': '10',
    'leg-11': '11',
}

# Google Sheets API access
SCOPES = 'https://www.googleapis.com/auth/spreadsheets'
store = file.Storage(USER_DIR + '/work/vor/etc/passwords/storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets(
        USER_DIR + '/work/vor/etc/passwords/client_id.json', SCOPES)
    creds = tools.run_flow(flow, store)
SHEETS = discovery.build('sheets', 'v4', http=creds.authorize(Http()))


def main():
    all_videos = read_full_spreadsheet()
    seen = {}
    for item in all_videos:
        seen_key = get_seen_key(item)
        seen[seen_key] = True

    # Get metadata from vor's json files. They now break it up by day, so try to
    # get the last JSON_DAYS days' worth of json data.
    # http://www.volvooceanrace.com/en/raw_days/yyyy-mm-dd.json
    raw_json_items = []
    now = datetime.datetime.utcnow()
    for i in range(JSON_DAYS):
Пример #9
0
    f.write('Coordinates: RA = ' + str(ra) + ' Dec = ' + str(dec))
    f.write('\n')
    f.close()
    # Send out email alert
    os.system("mail -s \"Triggering ATCA: " + subject +
              "\" [email protected]  < Email.txt")


# Setup the Gmail API
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = build('gmail', 'v1', http=creds.authorize(Http()))

dates = []
hess_email = []
hess_trig_sent = []

while True:
    try:
        # Read the email in a loop
        results = service.users().messages().list(userId='me',
                                                  maxResults=1).execute()
        # get the message id from the results object
        message_id = results['messages'][0]['id']
        # use the message id to get the actual message, including any attachments
        message = service.users().messages().get(userId='me',
                                                 id=message_id).execute()
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import scrapy
import logging
import scrapy_proxies

SCOPES = 'https://www.googleapis.com/auth/spreadsheets'
store = file.Storage('credentials.json')
creds = store.get()

if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_secret_1.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = build('sheets', 'v4', http=creds.authorize(Http()))

		
SPREADSHEET_ID = '1zXLFsLIdMEOsgy4fPK4kL9_4cOjGL1Y3s3Sfuz7EwyA'

class firstscrapy(scrapy.Spider):
	name = "spider"
	allowed_domains = ["google.com"]
	index = 2
	#indicator in case of an error
	flag = 1
	def start_requests(self):
		SS_RANGE = 'AppTestingSheet!F2:F'
		result = service.spreadsheets().values().get(spreadsheetId=SPREADSHEET_ID,range=SS_RANGE).execute()
		values = result.get('values',[])
		#The cell value from which the current execution of the script would run
Пример #11
0
from sys import argv

script, filename = argv

print("We're going to erase {}.".format(filename))

target = open(filename, 'w', encoding="utf-8")
target.truncate()

SCOPES = 'https://www.googleapis.com/auth/drive.readonly.metadata'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
    creds = tools.run_flow(flow, store)
DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))

# Auto-iterate through all files that matches this query
files = DRIVE.files().list(
    q="'0B8K5jq5Aw7evLUJXdDBsclg3czA' in parents and trashed=false").execute(
    ).get('files', [])
for f in files:
    print(f['name'], f['mimeType'])
    cleanline = f['name'].encode('utf-8', 'ignore')
    cleanline = cleanline.decode('utf-8', 'ignore')
    target.write('name: %s, mime: %s' % (cleanline, f['mimeType']))
    target.write('\n')

print('Done')
target.close()