Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/file_automation_dev_python3_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python -m pip install --upgrade pip wheel
pip install -r dev_requirements.txt
- name: Dir Module Test
run: python ./tests/unit_test/dir/dir_test.py
run: python ./tests/unit_test/local/dir/dir_test.py
- name: File Module Test
run: python ./tests/unit_test/file/test_file.py
run: python ./tests/unit_test/local/file/test_file.py
- name: Zip Module Test
run: python ./tests/unit_test/zip/zip_test.py
run: python ./tests/unit_test/local/zip/zip_test.py
6 changes: 3 additions & 3 deletions .github/workflows/file_automation_dev_python3_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python -m pip install --upgrade pip wheel
pip install -r dev_requirements.txt
- name: Dir Module Test
run: python ./tests/unit_test/dir/dir_test.py
run: python ./tests/unit_test/local/dir/dir_test.py
- name: File Module Test
run: python ./tests/unit_test/file/test_file.py
run: python ./tests/unit_test/local/file/test_file.py
- name: Zip Module Test
run: python ./tests/unit_test/zip/zip_test.py
run: python ./tests/unit_test/local/zip/zip_test.py
6 changes: 3 additions & 3 deletions .github/workflows/file_automation_dev_python3_8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python -m pip install --upgrade pip wheel
pip install -r dev_requirements.txt
- name: Dir Module Test
run: python ./tests/unit_test/dir/dir_test.py
run: python ./tests/unit_test/local/dir/dir_test.py
- name: File Module Test
run: python ./tests/unit_test/file/test_file.py
run: python ./tests/unit_test/local/file/test_file.py
- name: Zip Module Test
run: python ./tests/unit_test/zip/zip_test.py
run: python ./tests/unit_test/local/zip/zip_test.py
6 changes: 3 additions & 3 deletions .github/workflows/file_automation_dev_python3_9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python -m pip install --upgrade pip wheel
pip install -r dev_requirements.txt
- name: Dir Module Test
run: python ./tests/unit_test/dir/dir_test.py
run: python ./tests/unit_test/local/dir/dir_test.py
- name: File Module Test
run: python ./tests/unit_test/file/test_file.py
run: python ./tests/unit_test/local/file/test_file.py
- name: Zip Module Test
run: python ./tests/unit_test/zip/zip_test.py
run: python ./tests/unit_test/local/zip/zip_test.py
6 changes: 3 additions & 3 deletions .github/workflows/file_automation_stable_python3_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
- name: Dir Module Test
run: python ./tests/unit_test/dir/dir_test.py
run: python ./tests/unit_test/local/dir/dir_test.py
- name: File Module Test
run: python ./tests/unit_test/file/test_file.py
run: python ./tests/unit_test/local/file/test_file.py
- name: Zip Module Test
run: python ./tests/unit_test/zip/zip_test.py
run: python ./tests/unit_test/local/zip/zip_test.py
6 changes: 3 additions & 3 deletions .github/workflows/file_automation_stable_python3_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
- name: Dir Module Test
run: python ./tests/unit_test/dir/dir_test.py
run: python ./tests/unit_test/local/dir/dir_test.py
- name: File Module Test
run: python ./tests/unit_test/file/test_file.py
run: python ./tests/unit_test/local/file/test_file.py
- name: Zip Module Test
run: python ./tests/unit_test/zip/zip_test.py
run: python ./tests/unit_test/local/zip/zip_test.py
6 changes: 3 additions & 3 deletions .github/workflows/file_automation_stable_python3_8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
- name: Dir Module Test
run: python ./tests/unit_test/dir/dir_test.py
run: python ./tests/unit_test/local/dir/dir_test.py
- name: File Module Test
run: python ./tests/unit_test/file/test_file.py
run: python ./tests/unit_test/local/file/test_file.py
- name: Zip Module Test
run: python ./tests/unit_test/zip/zip_test.py
run: python ./tests/unit_test/local/zip/zip_test.py
6 changes: 3 additions & 3 deletions .github/workflows/file_automation_stable_python3_9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
python -m pip install --upgrade pip wheel
pip install -r requirements.txt
- name: Dir Module Test
run: python ./tests/unit_test/dir/dir_test.py
run: python ./tests/unit_test/local/dir/dir_test.py
- name: File Module Test
run: python ./tests/unit_test/file/test_file.py
run: python ./tests/unit_test/local/file/test_file.py
- name: Zip Module Test
run: python ./tests/unit_test/zip/zip_test.py
run: python ./tests/unit_test/local/zip/zip_test.py
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@ cython_debug/
.idea/

# Google Drive API token
file_automation/remote/google_drive/credentials.json
tests/unit_test/remote/google_drive/credentials.json
token.json
4 changes: 3 additions & 1 deletion file_automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from file_automation.local.zip.zip_process import zip_dir, zip_file, zip_info, zip_file_info, set_zip_password, \
read_zip_file, unzip_file, unzip_all

from file_automation.remote.google_drive.driver_instance import driver_instance

__all__ = [
"copy_file", "rename_file", "remove_file", "copy_all_file_to_dir", "copy_specify_extension_file",
"copy_dir", "create_dir", "copy_specify_extension_file", "remove_dir_tree",
"zip_dir", "zip_file", "zip_info", "zip_file_info", "set_zip_password", "unzip_file", "read_zip_file",
"unzip_all"
"unzip_all", "driver_instance",
]
23 changes: 23 additions & 0 deletions file_automation/remote/google_drive/download/download_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import io

from googleapiclient.errors import HttpError
from googleapiclient.http import MediaIoBaseDownload

from file_automation.remote.google_drive.driver_instance import driver_instance


def download_file(file_id: str, file_name: str):
try:
request = driver_instance.service.files().get_media(fileId=file_id)
file = io.BytesIO()
downloader = MediaIoBaseDownload(file, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print(F'Download {int(status.progress() * 100)}.')
except HttpError as error:
print(F'An error occurred: {error}')
file = None
with open(file_name, "wb") as output_file:
output_file.write(file.getbuffer())
return file
2 changes: 1 addition & 1 deletion file_automation/remote/google_drive/driver_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def __init__(self, token_path: str, credentials_path: str):
print(f'An error occurred: {error}')


GoogleDrive(str(Path(Path.cwd(), "token.json")), str(Path(Path.cwd(), "credentials.json")))
driver_instance = GoogleDrive(str(Path(Path.cwd(), "token.json")), str(Path(Path.cwd(), "credentials.json")))
26 changes: 26 additions & 0 deletions file_automation/remote/google_drive/search/search_drive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from file_automation.remote.google_drive.driver_instance import driver_instance


def search_all_file():
item = dict()
response = driver_instance.service.files().list().execute()
for file in response.get("files", []):
item.update({file.get("name"): file.get("id")})
return item


def search_file_mimetype(mime_type: str):
files = dict()
page_token = None
while True:
# pylint: disable=maybe-no-member
response = driver_instance.service.files().list(
q=f"mimeType='{mime_type}'",
fields="nextPageToken, files(id, name)",
pageToken=page_token).execute()
for file in response.get("files", []):
files.update({file.get("name"): file.get("id")})
page_token = response.get('nextPageToken', None)
if page_token is None:
break
return files
25 changes: 25 additions & 0 deletions file_automation/remote/google_drive/upload/upload_to_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pathlib import Path

from googleapiclient.http import MediaFileUpload

from file_automation.remote.google_drive.driver_instance import driver_instance


def upload_to_drive(file_name: str, file_path: str):
if Path(file_path).is_file():
file_metadata = {
"name": file_name,
"mimeType": "*/*"
}
media = MediaFileUpload(
file_path,
mimetype="*/*",
resumable=True
)
file_id = driver_instance.service.files().create(
body=file_metadata,
media_body=media,
fields="id"
).execute()
return file_id
return False
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/unit_test/remote/google_drive/quick_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from file_automation.remote.google_drive.download.download_file import download_file

print(download_file("1s4cHS_ZSqMMikf8HV2vb1rYahbtoJvbC", "test.py"))