Exemple #1
0
def test_backup():
    print('setup_function: Retrieve OAuth2.0 credentials.')
    creds = sheetsync.ia_credentials_helper(
        CLIENT_ID,
        CLIENT_SECRET,
        credentials_cache_file='credentials.json',
        cache_key='default')

    print('Open a spreadsheet, back it up to named file.')
    target = sheetsync.Sheet(credentials=creds,
                             document_key=SHEET_TO_BE_BACKED_UP,
                             worksheet_name='Simpsons',
                             key_column_headers=['Character'],
                             header_row_ix=1)

    backup_name = 'backup test: %s' % int(time.time())
    backup_key = target.backup(backup_name, folder_name="sheetsync backups")

    backup_sheet = sheetsync.Sheet(credentials=creds,
                                   document_key=backup_key,
                                   worksheet_name='Simpsons',
                                   key_column_headers=['Character'],
                                   header_row_ix=1)

    backup_data = backup_sheet.data()
    assert "Bart Simpson" in backup_data
    assert backup_data["Bart Simpson"]["Voice actor"] == "Nancy Cartwright"

    print('teardown_function Delete test spreadsheet')
    backup_sheet.drive_service.files().delete(
        fileId=backup_sheet.document_key).execute()
Exemple #2
0
 def __init__(self, document_name=None, credential_cache_file=None):
     self.DOCUMENT_NAME = document_name or self.DOCUMENT_NAME
     self.CLIENT_ID = os.getenv('GOOGLE_API_CLIENT_ID')
     self.CLIENT_SECRET = os.getenv('GOOGLE_API_CLIENT_SECRET')
     self.CREDENTIAL_CACHE = os.getenv('GOOGLE_API_CREDENTIAL_CACHE')
     self.credential_cache_file = credential_cache_file or 'cred_cache.json'
     if self.CREDENTIAL_CACHE is not None and not os.path.exists(self.credential_cache_file):
         with open(self.credential_cache_file, 'w') as f:
             f.write(self.CREDENTIAL_CACHE)
     self.credentials = ia_credentials_helper(
             self.CLIENT_ID,
             self.CLIENT_SECRET,
             credentials_cache_file=self.credential_cache_file)
     try:
         self.wbk = Sheet(credentials=self.credentials, document_name=self.DOCUMENT_NAME)
     except ConnectionError:
         time.sleep(EuroCupBracketWorkbook._RETRY_BACKOFF)
         EuroCupBracketWorkbook._RETRY_BACKOFF **= 2
         self.__init__(document_name, credential_cache_file)
     self.sheets = self.wbk.sheet.worksheets()
     self.data_api_client = SeasonClient(season_id='424')
     self.scoring_sheet = EuroCupBracketScoringSheet(self)
     self.participant_sheets = [EuroCupBracketGroupStagePicksSheet(i, self) for i in
             self.scoring_sheet.participants]
     self._worker_pool = ThreadPool(10)
Exemple #3
0
def test_backup():
    print ('setup_function: Retrieve OAuth2.0 credentials.')
    creds = sheetsync.ia_credentials_helper(CLIENT_ID, CLIENT_SECRET, 
                    credentials_cache_file='credentials.json',
                    cache_key='default')


    print ('Open a spreadsheet, back it up to named file.')
    target = sheetsync.Sheet(credentials=creds,
                             document_key = SHEET_TO_BE_BACKED_UP,
                             worksheet_name = 'Simpsons',
                             key_column_headers = ['Character'],
                             header_row_ix=1)

    backup_name = 'backup test: %s' % int(time.time())
    backup_key = target.backup(backup_name, folder_name="sheetsync backups")

    backup_sheet = sheetsync.Sheet(credentials=creds,
                                   document_key = backup_key,
                                   worksheet_name = 'Simpsons',
                                   key_column_headers = ['Character'],
                                   header_row_ix=1)

    backup_data = backup_sheet.data() 
    assert "Bart Simpson" in backup_data
    assert backup_data["Bart Simpson"]["Voice actor"] == "Nancy Cartwright"

    print ('teardown_function Delete test spreadsheet')
    backup_sheet.drive_service.files().delete(fileId=backup_sheet.document_key).execute()
Exemple #4
0
def test_the_kartik_test():
    # The most basic usage of creating a new sheet and adding data to it.
    # From April, Google defaults to using new-style sheets which requires
    # workarounds right now.
    creds = sheetsync.ia_credentials_helper(CLIENT_ID, CLIENT_SECRET, 
                    credentials_cache_file='credentials.json',
                    cache_key='default')

    new_doc_name = '%s-%s-%s' % (__name__, sys._getframe().f_code.co_name, int(time.time()))
    target = sheetsync.Sheet(credentials=creds,
                             document_name = new_doc_name)
    # Check we can sync data to the newly created sheet.
    data = {"1" : {"name" : "Gordon", "color" : "Green"},
            "2" : {"name" : "Thomas", "color" : "Blue" } }
    target.sync(data)
    
    retrieved_data = target.data()
    assert "1" in retrieved_data
    assert retrieved_data["1"]["name"] == "Gordon"
    assert "2" in retrieved_data
    assert retrieved_data["2"]["color"] == "Blue"
    assert retrieved_data["2"]["Key"] == "2"

    # Try opening the doc with a new instance (thereby guessing key columns)
    test_read = sheetsync.Sheet(credentials=creds,
                                document_name = new_doc_name)
    retrieved_data_2 = test_read.data()
    assert "1" in retrieved_data_2
    assert "2" in retrieved_data_2
    assert retrieved_data["2"]["color"] == "Blue"

    # Delete the doc
    target.drive_service.files().delete(fileId=target.document_key).execute()
Exemple #5
0
def test_move_to_folder_by_name():
    creds = sheetsync.ia_credentials_helper(CLIENT_ID, CLIENT_SECRET, 
                    credentials_cache_file='credentials.json',
                    cache_key='default')

    new_doc_name = '%s-%s-%s' % (__name__, sys._getframe().f_code.co_name, int(time.time()))
    target = sheetsync.Sheet(credentials=creds,
                             document_name = new_doc_name,
                             worksheet_name = 'Sheet1',
                             folder_name = TESTS_FOLDER_NAME)
    # Delete the doc
    target.drive_service.files().delete(fileId=target.document_key).execute()
Exemple #6
0
def test_move_to_folder_by_name():
    creds = sheetsync.ia_credentials_helper(
        CLIENT_ID,
        CLIENT_SECRET,
        credentials_cache_file='credentials.json',
        cache_key='default')

    new_doc_name = '%s-%s-%s' % (__name__, sys._getframe().f_code.co_name,
                                 int(time.time()))
    target = sheetsync.Sheet(credentials=creds,
                             document_name=new_doc_name,
                             worksheet_name='Sheet1',
                             folder_name=TESTS_FOLDER_NAME)
    # Delete the doc
    target.drive_service.files().delete(fileId=target.document_key).execute()
Exemple #7
0
def test_move_to_new_folder_by_name():
    creds = sheetsync.ia_credentials_helper(CLIENT_ID, CLIENT_SECRET, 
                    credentials_cache_file='credentials.json',
                    cache_key='default')

    new_doc_name = '%s-%s-%s' % (__name__, sys._getframe().f_code.co_name, int(time.time()))
    new_folder_name = 'sheetsync testrun %s' % int(time.time())
    target = sheetsync.Sheet(credentials=creds,
                             document_name = new_doc_name,
                             worksheet_name = 'Sheet1',
                             folder_name = new_folder_name)
    # Delete the doc
    target.drive_service.files().delete(fileId=target.document_key).execute()

    # Delete the new folder too..
    assert new_folder_name == target.folder['title']
    target.drive_service.files().delete(fileId=target.folder['id']).execute()
Exemple #8
0
def test_the_kartik_test():
    # The most basic usage of creating a new sheet and adding data to it.
    # From April, Google defaults to using new-style sheets which requires
    # workarounds right now.
    creds = sheetsync.ia_credentials_helper(
        CLIENT_ID,
        CLIENT_SECRET,
        credentials_cache_file='credentials.json',
        cache_key='default')

    new_doc_name = '%s-%s-%s' % (__name__, sys._getframe().f_code.co_name,
                                 int(time.time()))
    target = sheetsync.Sheet(credentials=creds, document_name=new_doc_name)
    # Check we can sync data to the newly created sheet.
    data = {
        "1": {
            "name": "Gordon",
            "color": "Green"
        },
        "2": {
            "name": "Thomas",
            "color": "Blue"
        }
    }
    target.sync(data)

    retrieved_data = target.data()
    assert "1" in retrieved_data
    assert retrieved_data["1"]["name"] == "Gordon"
    assert "2" in retrieved_data
    assert retrieved_data["2"]["color"] == "Blue"
    assert retrieved_data["2"]["Key"] == "2"

    # Try opening the doc with a new instance (thereby guessing key columns)
    test_read = sheetsync.Sheet(credentials=creds, document_name=new_doc_name)
    retrieved_data_2 = test_read.data()
    assert "1" in retrieved_data_2
    assert "2" in retrieved_data_2
    assert retrieved_data["2"]["color"] == "Blue"

    # Delete the doc
    target.drive_service.files().delete(fileId=target.document_key).execute()
Exemple #9
0
def test_move_to_new_folder_by_name():
    creds = sheetsync.ia_credentials_helper(
        CLIENT_ID,
        CLIENT_SECRET,
        credentials_cache_file='credentials.json',
        cache_key='default')

    new_doc_name = '%s-%s-%s' % (__name__, sys._getframe().f_code.co_name,
                                 int(time.time()))
    new_folder_name = 'sheetsync testrun %s' % int(time.time())
    target = sheetsync.Sheet(credentials=creds,
                             document_name=new_doc_name,
                             worksheet_name='Sheet1',
                             folder_name=new_folder_name)
    # Delete the doc
    target.drive_service.files().delete(fileId=target.document_key).execute()

    # Delete the new folder too..
    assert new_folder_name == target.folder['title']
    target.drive_service.files().delete(fileId=target.folder['id']).execute()
Exemple #10
0
def setup_function(function):
    global target
    print('setup_function: Retrieve OAuth2.0 credentials.')
    creds = sheetsync.ia_credentials_helper(
        CLIENT_ID,
        CLIENT_SECRET,
        credentials_cache_file='credentials.json',
        cache_key='default')

    print('setup_function: Create test spreadsheet.')
    # Copy the template spreadsheet into the prescribed folder.
    new_doc_name = '%s %s' % (__name__, int(time.time()))
    target = sheetsync.Sheet(creds,
                             document_name=new_doc_name,
                             worksheet_name="Arsenal",
                             folder_key=TESTS_FOLDER,
                             template_key=TEMPLATE_DOC,
                             key_column_headers=["No."],
                             header_row_ix=2,
                             formula_ref_row_ix=1)
Exemple #11
0
import logging, os

from sheetsync import Sheet, ia_credentials_helper

logging.getLogger('sheetsync').setLevel(logging.DEBUG)
logging.basicConfig()

CLIENT_ID = os.environ['SHEETSYNC_CLIENT_ID']  
CLIENT_SECRET = os.environ['SHEETSYNC_CLIENT_SECRET']  

creds = ia_credentials_helper(CLIENT_ID, CLIENT_SECRET, 
                    credentials_cache_file='credentials.json',
                    cache_key='default')

data = { "Kermit": {"Color" : "Green", "Performer" : "Jim Henson"},
         "Miss Piggy" : {"Color" : "Pink", "Performer" : "Frank Oz"}
        }

target = Sheet(credentials=creds, document_name="sheetsync quicktest")

target.inject(data)

print "Spreadsheet created here: %s" % target.document_href
Exemple #12
0
import logging, os

from sheetsync import Sheet, ia_credentials_helper

logging.getLogger('sheetsync').setLevel(logging.DEBUG)
logging.basicConfig()

CLIENT_ID = os.environ['SHEETSYNC_CLIENT_ID']
CLIENT_SECRET = os.environ['SHEETSYNC_CLIENT_SECRET']

creds = ia_credentials_helper(CLIENT_ID,
                              CLIENT_SECRET,
                              credentials_cache_file='credentials.json',
                              cache_key='default')

data = {
    "Kermit": {
        "Color": "Green",
        "Performer": "Jim Henson"
    },
    "Miss Piggy": {
        "Color": "Pink",
        "Performer": "Frank Oz"
    }
}

target = Sheet(credentials=creds, document_name="sheetsync quicktest")

target.inject(data)

print "Spreadsheet created here: %s" % target.document_href
Exemple #13
0
from ConfigParser import SafeConfigParser

my_gd_creds_file = "/home/rtran/bin/otrs2gs.ini"

parser = SafeConfigParser()
if (not os.path.isfile(my_gd_creds_file)):
    print("Error: Google Drive creds not found\n")
else:
    parser.read(my_gd_creds_file)

#print 'OTRS_CLIENT_ID:', parser.get('otrs2gs_client', 'OTRS2GS_CLIENT_ID')
#print 'OTRS_CLIENT_SECRET:', parser.get('otrs2gs_client', 'OTRS2GS_CLIENT_SECRET')
otrs2gs_client_id = parser.get('otrs2gs_client', 'OTRS2GS_CLIENT_ID')
otrs2gs_client_secret = parser.get('otrs2gs_client', 'OTRS2GS_CLIENT_SECRET')
creds = ia_credentials_helper(otrs2gs_client_id,
                              otrs2gs_client_secret,
                              credentials_cache_file='cred_cache.json')

#data = { "Kermit": {"Color" : "Green", "Performer" : "Jim Henson"},
#         "Miss Piggy" : {"Color" : "Pink", "Performer" : "Frank Oz"},
#         "Captain Kangaroo" : {"Color" : "Gray", "Performer" : "Ray Tran"},
#        }

# Read in OTRS ticket
my_path = "/home/rtran/otrs_reports"
my_daily_report_file = "/home/rtran/otrs_reports/Daily_Open_Ticket_report"
tickets_list = {}

with open(my_daily_report_file) as my_incoming_data:
    next(my_incoming_data, None)
    next(my_incoming_data, None)
Exemple #14
0
def credentials():
    logger.debug('Retrieving OAuth2.0 credentials')
    creds = sheetsync.ia_credentials_helper(CLIENT_ID, CLIENT_SECRET, 
                    credentials_cache_file='credentials.json')
    logger.debug('Retrieved OAuth2.0 credentials')
    return creds