Beispiel #1
0
 def lock(self):
     start_time = datetime.datetime.now()
     self.__file = sac.Communicate.create_file(
         self=sac.Communicate(),
         parent_folder_id=self.__semaphore_id,
         file_mimetype='text/txt',
         file_name=self.__user_id,
         file_content=self.__user_id)
     while True:
         first_file = self.get_first_created_file_name()
         cur_time = datetime.datetime.now()
         if str(first_file) == str(self.__file['title']):
             return True
         elif (cur_time -
               start_time).total_seconds() > self.__max_lock_time:
             first_file = self.get_first_created_file_name()
             first_file_id = sac.Communicate.get_file_id_by_name(
                 self=sac.Communicate(),
                 file_name=first_file,
                 root_folder_name=self.__semaphore_name)
             sac.Communicate.delete_item(self=sac.Communicate(),
                                         item_id=first_file_id)
             first_file = self.get_first_created_file_name()
             if str(first_file) == str(self.__file['title']):
                 return True
             else:
                 return False
         else:
             time.sleep(10)  # Sleep for 10 seconds
Beispiel #2
0
def test6():
    list_folders = Communicate.list_folders_in_drive_folder(
        Communicate(), '1I8weqrFj2PAqwaZ_s5PQOb6l7jWVqskQ')
    for folder in list_folders:
        cur_folder = Communicate.get_folder_id_by_name(Communicate(),
                                                       folder['name'])
        Communicate.delete_folder(Communicate(), cur_folder)
Beispiel #3
0
def test4():
    # Communicate.list_folders_and_files_in_drive_folder(Communicate(), '13cpeqI6mWm24elK3UCdfJhoRsKCOVxZv')
    item_id = Communicate.get_folder_id_by_name(
        Communicate(), 'StatisticsAnalyzerSharedFolder')
    print(item_id)
    Communicate.download_folder(Communicate(), item_id,
                                'C:\local_SA_GoogleDriveData')
Beispiel #4
0
def test5():
    folder = Communicate.create_folder(
        Communicate(),
        parent_folder_id='1I8weqrFj2PAqwaZ_s5PQOb6l7jWVqskQ',
        folder_name='TestPull1')
    Communicate.upload_excel(Communicate(), 'IsraelCases',
                             "C:\Git projects\SA_Files\Israel\Deaths.xlsx",
                             folder['id'])
Beispiel #5
0
def test2():
    # ROOT_DIR = os.path.abspath(os.pardir)
    # print(ROOT_DIR)
    d1 = datetime.date.now().strftime("%d/%m/%Y")
    d2 = datetime.datetime.now().strftime("%d/%m/%Y-%H:%M:%S")
    listFolders = Communicate.list_folders_and_files(
        Communicate(), '189ExmXs6CH9u1fgVf-Lrq8osHO94cnvz')
    # Communicate.upload_item(Communicate(), '189ExmXs6CH9u1fgVf-Lrq8osHO94cnvz')
    folder = Communicate.create_folder(Communicate(),
                                       '189ExmXs6CH9u1fgVf-Lrq8osHO94cnvz', d2)
    print('folder id is:', folder['id'])
    file = Communicate.create_file(Communicate(), folder['id'], 'text/csv',
                                   d1 + '.csv',
                                   'hello, world, I, am, first, file!')
    file = Communicate.create_file(Communicate(), folder['id'], 'text/txt',
                                   d1 + '.txt', 'hello world I am first file!')
    print('file id is: ', file['id'])
    Communicate.retrieve_created_datetime(Communicate(), file)
Beispiel #6
0
def test3():
    # Communicate.list_folders_and_files_in_drive_folder(Communicate(), '189ExmXs6CH9u1fgVf-Lrq8osHO94cnvz')
    folder = Communicate.create_folder(
        Communicate(),
        parent_folder_id='1I8weqrFj2PAqwaZ_s5PQOb6l7jWVqskQ',
        folder_name='StatisticsIsrael-11-18-2020')

    excelfile1 = Communicate.upload_excel(
        Communicate(), 'IsraelCases',
        "C:\local_SA_GoogleDriveData\StatisticsIsrael\IsraelCases.xlsx",
        folder['id'])
    excelfile2 = Communicate.upload_excel(
        Communicate(), 'IsraelDeaths',
        "C:\local_SA_GoogleDriveData\StatisticsIsrael\IsraelDeaths.xlsx",
        folder['id'])
    # excelfile3 = Communicate.upload_excel(Communicate(), 'IsraelReports', "C:\local_SA_GoogleDriveData\StatisticsIsrael\IsraelReports.xlsx", folder['id'])
    # excelfile4 = Communicate.upload_excel(Communicate(), 'IsraelCities', "C:\local_SA_GoogleDriveData\StatisticsIsrael\IsraelCities.xlsx", folder['id'])
    #
    Communicate.download_excel(Communicate(), excelfile1['id'], 'IsraelCases',
                               'Cases',
                               'C:\local_SA_GoogleDriveData\DOWNLOADED')
    Communicate.download_excel(Communicate(), excelfile1['id'], 'IsraelDeaths',
                               'Deaths',
                               'C:\local_SA_GoogleDriveData\DOWNLOADED')
Beispiel #7
0
    def get_first_created_file_name(self):
        files_data = {
        }  # {'uuid1': ['created_time'], 'uuid2': ['created_time']}
        files_list = sac.Communicate.list_files_in_drive_folder(
            self=sac.Communicate(), parent_id=self.__semaphore_id)
        if bool(files_list):
            for file in files_list:
                file_datetime = sac.Communicate.retrieve_created_datetime(
                    item=file)
                files_data[file['name']] = file_datetime

            files_data_sorted = dict(
                sorted(files_data.items(),
                       key=operator.itemgetter(1),
                       reverse=False))
            first_created_file = list(files_data_sorted.keys())[0]
        else:
            first_created_file = 'NULL'
        return first_created_file
Beispiel #8
0
def test7():
    Communicate.upload_excel(
        Communicate(),
        local_source_path="C:\\Git projects\\SA_FilesTest\\Greece")
Beispiel #9
0
def test1():
    print('starting upload')
    folder = Communicate.create_folder(
        Communicate(), '189ExmXs6CH9u1fgVf-Lrq8osHO94cnvz',
        datetime.datetime.now().strftime("%d/%m/%Y-%H:%M:%S"))
    Communicate.upload_item(Communicate(), folder['id'])
Beispiel #10
0
 def unlock(self):
     sac.Communicate.delete_item(self=sac.Communicate(),
                                 item_id=self.__file['id'])
     return