imageum 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
imageum-1.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Asinerum Conlang Project
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
imageum-1.0.1/PKG-INFO ADDED
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.4
2
+ Name: imageum
3
+ Version: 1.0.1
4
+ Summary: Google Drive and Blogger Image Tool
5
+ Home-page: https://github.com/asinerum/imageum
6
+ Author: Asinerum Conlang Project
7
+ Author-email: asinerum.com@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: pillow>=12.3.0
16
+ Requires-Dist: requests>=2.34.2
17
+ Requires-Dist: google-auth>=2.48.0
18
+ Requires-Dist: google-auth-oauthlib>=1.4.0
19
+ Requires-Dist: google-api-python-client>=2.187.0
20
+ Requires-Dist: tagrepo>=1.0.14
21
+ Dynamic: license-file
22
+
23
+ # Google Drive and Blogger Image Tool
24
+
25
+ ## Installation
26
+ ```bash
27
+ pip install imageum
28
+ ```
29
+
30
+ ## Sample Usage [Nov 18, 2026]
31
+ ```bash
32
+ ## nano im.sh
33
+ export SCOPES="https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/blogger"
34
+ export TOKEN_FILE="token.json"
35
+ imageum
36
+ ## chmod +x im.sh
37
+ ## ./im.sh
38
+ ```
39
+
40
+ Detailed tips, tricks, and examples, can be found at project's repository
41
+ https://github.com/asinerum/imageum
42
+
43
+ (C)2026 Asinerum Conlang Project
@@ -0,0 +1,21 @@
1
+ # Google Drive and Blogger Image Tool
2
+
3
+ ## Installation
4
+ ```bash
5
+ pip install imageum
6
+ ```
7
+
8
+ ## Sample Usage [Nov 18, 2026]
9
+ ```bash
10
+ ## nano im.sh
11
+ export SCOPES="https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/blogger"
12
+ export TOKEN_FILE="token.json"
13
+ imageum
14
+ ## chmod +x im.sh
15
+ ## ./im.sh
16
+ ```
17
+
18
+ Detailed tips, tricks, and examples, can be found at project's repository
19
+ https://github.com/asinerum/imageum
20
+
21
+ (C)2026 Asinerum Conlang Project
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,39 @@
1
+ [metadata]
2
+ name = imageum
3
+ version = 1.0.1
4
+ author = Asinerum Conlang Project
5
+ author_email = asinerum.com@gmail.com
6
+ description = Google Drive and Blogger Image Tool
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown
9
+ url = https://github.com/asinerum/imageum
10
+ license = MIT
11
+ classifiers =
12
+ Programming Language :: Python :: 3
13
+ License :: OSI Approved :: MIT License
14
+ Operating System :: OS Independent
15
+
16
+ [options]
17
+ package_dir =
18
+ = src
19
+ packages = find:
20
+ python_requires = >=3.7
21
+ install_requires =
22
+ pillow >= 12.3.0
23
+ requests >= 2.34.2
24
+ google-auth >= 2.48.0
25
+ google-auth-oauthlib >= 1.4.0
26
+ google-api-python-client >= 2.187.0
27
+ tagrepo >= 1.0.14
28
+
29
+ [options.packages.find]
30
+ where = src
31
+
32
+ [options.entry_points]
33
+ console_scripts =
34
+ imageum = imageum.cli:main
35
+
36
+ [egg_info]
37
+ tag_build =
38
+ tag_date = 0
39
+
@@ -0,0 +1,3 @@
1
+ from .image import *
2
+
3
+ __version__ = "1.0.1"
@@ -0,0 +1,40 @@
1
+ import sys
2
+
3
+ from tagrepo.environ import set_environ
4
+
5
+ from .image import *
6
+
7
+ set_environ("SCOPES", "https://www.googleapis.com/auth/drive.file")
8
+ set_environ("TOKEN_FILE", "token.json")
9
+ set_environ("BLOG_ID", "")
10
+ set_environ("POST_ID", "")
11
+
12
+ SCOPES = SCOPES.split(",")
13
+
14
+ def get_input(prompt: str, default: str, cast_type=str) -> str:
15
+ user_val = input(f"{prompt} [{default}]: ").strip()
16
+ return cast_type(user_val) if user_val else default
17
+
18
+ def main():
19
+ while True:
20
+ image_url = get_input("Image URL to be archived", "")
21
+ token_file = get_input("Access token JSON file path", TOKEN_FILE)
22
+ blog_id = get_input("Blogger private blog ID", BLOG_ID)
23
+ post_id = get_input("Blogger draft post ID", POST_ID)
24
+ try:
25
+ up = BloggerPermanentImageUploader(token_file, SCOPES)
26
+ image_path = up.download_and_convert_to_png(image_url)
27
+ if not blog_id or not post_id:
28
+ image_dest = up.upload_image_permanently(image_path)
29
+ else:
30
+ image_dest = up.add_image_to_blogger_post(blog_id, post_id, image_path)
31
+ print(f"Uploaded: {image_dest}")
32
+ except Exception as e:
33
+ print(f"Error: {e}")
34
+ print()
35
+ quit = input("Quit or continue [y/n] ").strip()
36
+ if quit.lower() in ["q", "y"]: sys.exit(0)
37
+ print()
38
+
39
+ if __name__ == '__main__':
40
+ main()
@@ -0,0 +1,93 @@
1
+ import os
2
+ import io
3
+ import tempfile
4
+ import mimetypes
5
+
6
+ import requests
7
+ from PIL import Image
8
+
9
+ from google.oauth2.credentials import Credentials
10
+ from google.auth.transport.requests import Request
11
+ from googleapiclient.discovery import build
12
+ from googleapiclient.http import MediaFileUpload
13
+ from google_auth_oauthlib.flow import InstalledAppFlow
14
+
15
+ DEF_SCOPES = [
16
+ "https://www.googleapis.com/auth/blogger",
17
+ "https://www.googleapis.com/auth/drive.file",
18
+ ]
19
+
20
+ class BloggerPermanentImageUploader:
21
+ def __init__(self, token_path: str="token.json", scopes: list=DEF_SCOPES):
22
+ self.SCOPES = scopes
23
+ self.token_path = token_path
24
+ self.creds = self._authenticate()
25
+ self.blogger_service = build("blogger", "v3", credentials=self.creds)
26
+ self.drive_service = build("drive", "v3", credentials=self.creds)
27
+ def _authenticate(self) -> Credentials:
28
+ if not os.path.exists(self.token_path): raise FileNotFoundError(f"Credentials file not found: {self.token_path}")
29
+ creds = Credentials.from_authorized_user_file(self.token_path, self.SCOPES)
30
+ if not creds.valid:
31
+ if creds.expired and creds.refresh_token:
32
+ creds.refresh(Request())
33
+ with open(self.token_path, "w", encoding="utf-8") as token_file: token_file.write(creds.to_json())
34
+ else:
35
+ raise RuntimeError("Credentials in token.json are invalid or expired without a refresh token")
36
+ return creds
37
+ def _get_or_create_folder(self, folder_name: str="Blogger_Images") -> str:
38
+ query = f"name = '{folder_name}' and mimeType = 'application/vnd.google-apps.folder' and trashed = false"
39
+ results = self.drive_service.files().list(q=query, fields="files(id)").execute()
40
+ files = results.get("files", [])
41
+ if files: return files[0]["id"]
42
+ folder_metadata = {"name": folder_name, "mimeType": "application/vnd.google-apps.folder"}
43
+ folder = self.drive_service.files().create(body=folder_metadata, fields="id").execute()
44
+ return folder["id"]
45
+ def generate_token_json_file(self, scopes=None, token_file="token.json", credential_file="credentials.json"):
46
+ try:
47
+ flow = InstalledAppFlow.from_client_secrets_file(credential_file, scopes if scopes else self.SCOPES)
48
+ creds = flow.run_local_server(port=0)
49
+ with open(token_file, "w", encoding="utf-8") as file: file.write(creds.to_json())
50
+ print("New <token.json> generated successfully with scopes:", creds.scopes)
51
+ except Exception as e:
52
+ print(f"Error: {e}")
53
+ def download_and_convert_to_png(self, image_url, timeout=30, suffix=".png", format="PNG"):
54
+ msg_error = "Wrong image address detected, try another"
55
+ try:
56
+ response = requests.get(image_url, timeout=timeout, stream=True)
57
+ response.raise_for_status()
58
+ content_type = response.headers.get("Content-Type", "").lower()
59
+ if not content_type.startswith("image/"): raise ValueError(msg_error)
60
+ image_data = response.content
61
+ image = Image.open(io.BytesIO(image_data))
62
+ image = image.convert("RGBA") if image.mode in ("RGBA", "P") else image.convert("RGB")
63
+ tmp_file = tempfile.NamedTemporaryFile(suffix=suffix, delete=False)
64
+ image.save(tmp_file.name, format=format, optimize=True)
65
+ return tmp_file.name
66
+ except Exception:
67
+ raise ValueError(msg_error)
68
+ def upload_image_permanently(self, image_path: str, folder_name: str="Blogger_Images") -> str:
69
+ if not os.path.exists(image_path): raise FileNotFoundError(f"Image not found: {image_path}")
70
+ folder_id = self._get_or_create_folder(folder_name)
71
+ filename = os.path.basename(image_path)
72
+ mime_type, _ = mimetypes.guess_type(image_path)
73
+ mime_type = mime_type or "image/png"
74
+ file_metadata = {"name": filename, "parents": [folder_id]}
75
+ media = MediaFileUpload(image_path, mimetype=mime_type, resumable=True)
76
+ uploaded_file = self.drive_service.files().create(body=file_metadata, media_body=media, fields="id").execute()
77
+ file_id = uploaded_file["id"]
78
+ self.drive_service.permissions().create(fileId=file_id, body={"type": "anyone", "role": "reader"}).execute()
79
+ return f"https://lh3.googleusercontent.com/d/{file_id}"
80
+ def add_image_to_blogger_post(self, blog_id: str, post_id: str, image_path: str, alt_text: str="", is_draft: bool=True) -> str:
81
+ permanent_url = self.upload_image_permanently(image_path)
82
+ view_type = "ADMIN" if is_draft else "AUTHOR"
83
+ post = self.blogger_service.posts().get(blogId=blog_id, postId=post_id, view=view_type).execute()
84
+ existing_content = post.get("content", "")
85
+ img_html = (
86
+ f'<div class="separator" style="clear: both; text-align: center;">'
87
+ f'<a href="{permanent_url}" style="margin-left: 1em; margin-right: 1em;">'
88
+ f'<img border="0" src="{permanent_url}" alt="{alt_text}"/>'
89
+ f"</a></div>"
90
+ )
91
+ updated_content = f"{existing_content}\n{img_html}"
92
+ self.blogger_service.posts().patch(blogId=blog_id, postId=post_id, body={"content": updated_content}).execute()
93
+ return permanent_url
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.4
2
+ Name: imageum
3
+ Version: 1.0.1
4
+ Summary: Google Drive and Blogger Image Tool
5
+ Home-page: https://github.com/asinerum/imageum
6
+ Author: Asinerum Conlang Project
7
+ Author-email: asinerum.com@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: pillow>=12.3.0
16
+ Requires-Dist: requests>=2.34.2
17
+ Requires-Dist: google-auth>=2.48.0
18
+ Requires-Dist: google-auth-oauthlib>=1.4.0
19
+ Requires-Dist: google-api-python-client>=2.187.0
20
+ Requires-Dist: tagrepo>=1.0.14
21
+ Dynamic: license-file
22
+
23
+ # Google Drive and Blogger Image Tool
24
+
25
+ ## Installation
26
+ ```bash
27
+ pip install imageum
28
+ ```
29
+
30
+ ## Sample Usage [Nov 18, 2026]
31
+ ```bash
32
+ ## nano im.sh
33
+ export SCOPES="https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/blogger"
34
+ export TOKEN_FILE="token.json"
35
+ imageum
36
+ ## chmod +x im.sh
37
+ ## ./im.sh
38
+ ```
39
+
40
+ Detailed tips, tricks, and examples, can be found at project's repository
41
+ https://github.com/asinerum/imageum
42
+
43
+ (C)2026 Asinerum Conlang Project
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ src/imageum/__init__.py
6
+ src/imageum/cli.py
7
+ src/imageum/image.py
8
+ src/imageum.egg-info/PKG-INFO
9
+ src/imageum.egg-info/SOURCES.txt
10
+ src/imageum.egg-info/dependency_links.txt
11
+ src/imageum.egg-info/entry_points.txt
12
+ src/imageum.egg-info/requires.txt
13
+ src/imageum.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ imageum = imageum.cli:main
@@ -0,0 +1,6 @@
1
+ pillow>=12.3.0
2
+ requests>=2.34.2
3
+ google-auth>=2.48.0
4
+ google-auth-oauthlib>=1.4.0
5
+ google-api-python-client>=2.187.0
6
+ tagrepo>=1.0.14
@@ -0,0 +1 @@
1
+ imageum