示例#1
0
 def add_account(self):
     self.num_accounts += 1
     service = get_service("account" + str(self.num_accounts))
     data = service.about().get(fields="user").execute()
     email = data['user']['emailAddress']
     root_dir = service.files().get(fileId='root', fields='id').execute()['id']
     acc = account(self.num_accounts, service, email, root_dir)
     self.accounts.append(acc)
     self.accounts_info.append({ 'email': email, 'root': root_dir})
     pickle.dump(self.accounts_info, open(ACCOUNTS_INFO_FILE, "wb"))
     self.switch_account(email)
示例#2
0
    def __init__(self):
        self.current = 0
        self.num_accounts = 0
        self.mode= 'myfiles'
        self.accounts = []
        self.accounts_info = []
        try:
            self.accounts_info = pickle.load(open(ACCOUNTS_INFO_FILE, "rb"))
            self.num_accounts = len(self.accounts_info)
            for i in range(1, self.num_accounts + 1):
                service = get_service('account' + str(i))
                email = self.accounts_info[i-1]['email']
                root_dir = self.accounts_info[i-1]['root']
                a = account(i, service, email, root_dir)
                self.accounts.append(a)
        except:
            print(sys.exc_info()[0])
            self.add_account()

        acc = self.accounts[self.current]
        set_root_dir(self.accounts_info[self.current]['root'])
        acc.cache = cache_handler.build_cache(acc.service, self.current+1)
示例#3
0
build dict of label ids, 
names for status labels 
to reduce API calls
"""
import csv
from auth.auth import get_service
from msg.label import agencies, lookup_label
from att.drive import check_if_drive

### START CONFIG ###
outfile_path = 'report/reports/response.csv'
outfile_headers = ['agency', 'status', 'threads']
sheet_filename = 'agency_response_log'
statuses = ['SENT', '*responded', '*attachment', '*done', '*NA']
### END CONFIG ###
service = get_service()
drive_service = get_service(type='drive')
sheets_service = get_service(type='sheets')


def init(report_agencies=None):
    """
    starts response report
    """
    if not report_agencies: report_agencies = agencies  #for debugging
    outfile, outcsv = setup_outfile()
    roll_thru(report_agencies, outcsv)
    outfile.close()


def setup_outfile():
示例#4
0
"""
handles uploading files to Drive
"""
from __future__ import print_function
from apiclient.http import MediaFileUpload
from auth.auth import get_service
from config import config

buffer_path = config.data["att"]["buffer_path"]
atts_drive_folder_name = config.data["att"]["drive"]["atts_drive_folder_name"]

drive_service = get_service(type='drive')


def get_or_create_atts_folder():
    """
    gets or creates the base attachment directory
    (where the agency folders will go)
    """
    atts_drive_folder_q = drive_service.files().list(
        q="name='" + atts_drive_folder_name + "'").execute().get('files')
    if atts_drive_folder_q:
        print('found', atts_drive_folder_name)
        return atts_drive_folder_q[0]
    else:
        print('creating', atts_drive_folder_name)
        return drive_service.files().create(
            body={
                'name': atts_drive_folder_name,
                'mimeType': 'application/vnd.google-apps.folder'
            }).execute()
示例#5
0
import base64
import os
import traceback

from auth.auth import get_service
from msg.label import agencies, get_atts
from msg.utils import error_info
from report.response import get_threads, get_status
from att.drive import (get_or_create_atts_folder, check_if_drive,
                       make_drive_folder, upload_to_drive)
from config import config

buffer_path = config.data["att"]["buffer_path"]

gmail_service = get_service(type='gmail')


def roll_thru():
    """
    controller function rolls through each agency:
    - checks if already filed in Drive
    - checks if labeled done
    ... if neither:
    - makes Drive folder
    - downloads buffer file to this server
    - uploads file to Drive folder
    - deleteds buffer file

    TODO: optimize by check_if_drive first before getting threads
    """
示例#6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from auth import auth
import logs
from datetime import datetime
from datetime import date
import logging
from googleapiclient.errors import HttpError

#аутентификация
service = auth.get_service()

#инициализация логгинга
logger = logs.logger_init()


def get_course(courseId):
    return service.courses().get(id=courseId).execute()


def get_courses(studentId=None):
    """
    Принимает: -
    Вовзращает: список курсов, к которым есть доступ с используемым токеном
                пользователя.
    """
    if studentId == None:
        courses = service.courses().list().execute().get('courses', [])
        if courses == []:
            logger.log(logging.INFO, 'нет курсов')
        else:
示例#7
0
from config import config

infile_path = config.data["contacts"]["infile_path"]
test_infile_path = config.data["contacts"]["test_infile_path"]
test = config.data["contacts"]["test"]

# test allows you to send sample FOIAs to test email addresses
# ********
# WARNING! google contacts API will cache contacts ...
# ********
# make sure to verify test contacts are deleted when prepping for production
# https://github.com/mattkiefer/foiamail/issues/29
if test:
    infile_path = test_infile_path

people_service = auth.get_service(type="people").people()


def load_contacts():
    """
    loads contacts via api
    """
    user_input('about to create contacts. press enter to continue...')
    for contact in import_contacts():
        try:
            sleep(1)
            body = {
                "names": [{
                    "givenName": contact["Name"]
                }],
                "emailAddresses": [{