Skip to content

Instantly share code, notes, and snippets.

@Nyovelt
Created December 16, 2023 21:03
Show Gist options
  • Save Nyovelt/368e8844b1581954f809b6bcf6d4d1ae to your computer and use it in GitHub Desktop.
Save Nyovelt/368e8844b1581954f809b6bcf6d4d1ae to your computer and use it in GitHub Desktop.
image_process.py
import os
from PIL import Image
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
from time import sleep
from b2sdk.v2 import B2Api, InMemoryAccountInfo
# Configuration
folder_path = '/home/canarypwn/Downloads/Telegram Desktop/初选壁纸' # Replace with your folder path
max_upload_size = 10 * 1024 * 1024 # 10 MB
credentials_json = '/home/canarypwn/Downloads/client_secret_883671922151-cfeg1qla6uhmh34f1ksvgoa2erdcpidk.apps.googleusercontent.com.json' # Replace with your JSON credentials file path
token_json = 'token.json'
scopes = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/forms']
# Configuration for Backblaze B2
key_id = ""
application_key = ""
bucket_name = ""
# Function to load credentials
def load_credentials():
creds = None
if os.path.exists(token_json):
creds = Credentials.from_authorized_user_file(token_json, scopes)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(credentials_json, scopes)
creds = flow.run_local_server(port=0)
with open(token_json, 'w') as token:
token.write(creds.to_json())
return creds
# Initialize Google API clients
creds = load_credentials()
drive_service = build('drive', 'v3', credentials=creds)
forms_service = build('forms', 'v1', credentials=creds)
# Initialize Backblaze B2
info = InMemoryAccountInfo()
b2_api = B2Api(info)
b2_api.authorize_account("production", key_id, application_key)
bucket = b2_api.get_bucket_by_name(bucket_name)
# Function to compress an image
def compress_image(image_path, output_path):
if os.path.getsize(image_path) > 10 * 1024 * 1024: # 10 MB
img = Image.open(image_path)
img.save(output_path, "JPEG", optimize=True, quality=85)
# Function to compress and upload images
def compress_and_upload_image(file_path, max_resolution=(1280, 720)):
# Open the image
# with Image.open(file_path) as img:
# # Resize the image if it's too large
# img.thumbnail(max_resolution, Image.ANTIALIAS)
# # Save the compressed image
# img.save(file_path, "JPEG", optimize=True, quality=85)
# Upload image to Backblaze B2
file_name = os.path.basename(file_path)
b2_file = bucket.upload_local_file(
local_file=file_path,
file_name="aosc2023_1/"+file_name
)
download_url = f"https://webresources.aaaab3n.moe/aosc2023_2/{file_name}"
return download_url
# Create a Google Form
NEW_FORM = {
"info": {
"title": "Image Voting Form",
}
}
form = forms_service.forms().create(body=NEW_FORM).execute()
form_id = form['formId']
images = []
# Add checkbox questions to the form for each image
for filename in os.listdir(folder_path):
if filename.lower().endswith('.jpg'):
file_path = os.path.join(folder_path, filename)
image_link = compress_and_upload_image(file_path)
images.append([image_link, filename])
sleep(15)
print(images)
batch = []
options = []
i = 0
for url in images:
option = {
'value': url[1],
'image': {
'sourceUri': url[0],
'altText': url[1]
}
}
options.append(option)
i = i + 1
print(options)
question_item = {
'createItem': {
'item': {
'title': 'Choose an option',
'questionItem': {
'question': {
'choiceQuestion': {
'type': 'CHECKBOX',
'options': options
}
}
}
},
'location': {'index': 0}
}
}
print(question_item)
batch_update_body = {'requests': [question_item]}
forms_service.forms().batchUpdate(formId=form_id, body=batch_update_body).execute()
print(f"Form created: https://docs.google.com/forms/d/{form_id}/edit")

To find the "Create OAuth client ID" option in the Google Cloud Console, you can follow these steps:

  1. Access the Google Cloud Console: Go to the Google Cloud Console.

  2. Select Your Project: Make sure you have selected the correct project that you created or want to use for this purpose.

  3. Navigate to APIs & Services: On the Google Cloud Console dashboard, you'll find a navigation menu on the left side. Click on "APIs & Services" and then go to "Credentials".

  4. Credentials Page: On the Credentials page, you will see different options for creating credentials.

  5. Create Credentials Button: There will be a "Create Credentials" button at the top of the page. Click on this button.

  6. Select OAuth client ID: From the dropdown menu that appears after clicking "Create Credentials", select "OAuth client ID".

  7. Configure the OAuth Consent Screen: If you haven't configured the OAuth consent screen yet, you will be prompted to do so. This involves specifying the application type (Internal or External), adding application information, and setting up scopes and test users.

  8. Create OAuth Client ID: After configuring the consent screen, you will be able to fill in details for the OAuth client ID, such as Application type (for desktop apps, select "Desktop app") and Name.

  9. Download Credentials: Once you've created the OAuth client ID, you can download the credentials in a JSON file, which you will use in your application for authentication.

Ensure you're logged into the correct Google account and have the necessary permissions in the Google Cloud project to create these credentials. If you face any issues, the Google Cloud Console provides detailed help and documentation to guide you through the process.

images = [['https://webresources.aaaab3n.moe/aosc2023_1/G8 - Tokyo.jpg', 'G8 - Tokyo.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/G8 - Book Store.jpg', 'G8 - Book Store.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/YzyParry - 维多利亚港.jpg', 'YzyParry - 维多利亚港.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 静安 II.jpg', 'Yu Changyuan - 静安 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/椰椰雪球 - 乌云过后.jpg', '椰椰雪球 - 乌云过后.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Seaway Trajectories.jpg', 'lz233 - Seaway Trajectories.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - US-441 from Morton Overlook.jpg', 'cthbleachbit - US-441 from Morton Overlook.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Fumbling.jpg', 'Mingcong Bai - Fumbling.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/RedL0tus - Connections.jpg', 'RedL0tus - Connections.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Mirrors of the Blue Sky.jpg', 'lz233 - Mirrors of the Blue Sky.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Dimensions.jpg', 'Mingcong Bai - Dimensions.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Beams.jpg', 'Mingcong Bai - Beams.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Smol Pumpkin.jpg', 'cthbleachbit - Smol Pumpkin.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Adore.jpg', 'Mingcong Bai - Adore.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alex Qin - 大风车.jpg', 'Alex Qin - 大风车.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Canvases.jpg', 'Mingcong Bai - Canvases.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Oregon Inlet Lifeboat Station.jpg', 'cthbleachbit - Oregon Inlet Lifeboat Station.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mogician Yang - 拼图 II.jpg', 'Mogician Yang - 拼图 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/YzyParry - 梅里雪山日出.jpg', 'YzyParry - 梅里雪山日出.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/宇宙眼镜人 - 星星的镜子.jpg', '宇宙眼镜人 - 星星的镜子.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Felix Yan - Their Prosperity I.jpg', 'Felix Yan - Their Prosperity I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Slumber on the ERT.jpg', 'cthbleachbit - Slumber on the ERT.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Lure.jpg', 'Mingcong Bai - Lure.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Pagoda.jpg', 'Mingcong Bai - Pagoda.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 格雷梅小镇 III.jpg', 'Yu Changyuan - 格雷梅小镇 III.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/椰椰雪球 - The Desert.jpg', '椰椰雪球 - The Desert.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 祁连山.jpg', 'Yu Changyuan - 祁连山.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Leisure.jpg', 'Mingcong Bai - Leisure.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mogician Yang - 地之脊 II.jpg', 'Mogician Yang - 地之脊 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Eye of Nanjing.jpg', 'lz233 - Eye of Nanjing.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 格雷梅小镇 II.jpg', 'Yu Changyuan - 格雷梅小镇 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Homeward Bound.jpg', 'Mingcong Bai - Homeward Bound.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Afterglow.jpg', 'Mingcong Bai - Afterglow.jpg']]
import os
from PIL import Image
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
from time import sleep
from b2sdk.v2 import B2Api, InMemoryAccountInfo
from urllib.parse import quote
# Configuration
folder_path = '/home/canarypwn/Downloads/Telegram Desktop/初选壁纸' # Replace with your folder path
max_upload_size = 10 * 1024 * 1024 # 10 MB
credentials_json = '/home/canarypwn/Downloads/client_secret_883671922151-cfeg1qla6uhmh34f1ksvgoa2erdcpidk.apps.googleusercontent.com.json' # Replace with your JSON credentials file path
token_json = 'token.json'
scopes = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/forms']
# Configuration for Backblaze B2
key_id = "0044acac6e283030000000004"
application_key = "K004mS7VveJubPeWmUCHosbtV+UGNCM"
bucket_name = "picgogo"
# Function to load credentials
def load_credentials():
creds = None
if os.path.exists(token_json):
creds = Credentials.from_authorized_user_file(token_json, scopes)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(credentials_json, scopes)
creds = flow.run_local_server(port=0)
with open(token_json, 'w') as token:
token.write(creds.to_json())
return creds
# Initialize Google API clients
creds = load_credentials()
drive_service = build('drive', 'v3', credentials=creds)
forms_service = build('forms', 'v1', credentials=creds)
# Initialize Backblaze B2
info = InMemoryAccountInfo()
b2_api = B2Api(info)
b2_api.authorize_account("production", key_id, application_key)
bucket = b2_api.get_bucket_by_name(bucket_name)
# Function to compress an image
def compress_image(image_path, output_path):
if os.path.getsize(image_path) > 10 * 1024 * 1024: # 10 MB
img = Image.open(image_path)
img.save(output_path, "JPEG", optimize=True, quality=85)
# Function to compress and upload images
def compress_and_upload_image(file_path):
# Compress image if necessary
if os.path.getsize(file_path) > max_upload_size:
img = Image.open(file_path)
img.save(file_path, "JPEG", optimize=True, quality=85)
# Upload image to Backblaze B2
file_name = os.path.basename(file_path)
b2_file = bucket.upload_local_file(
local_file=file_path,
file_name="aosc2023/"+file_name
)
download_url = f"https://webresources.aaaab3n.moe/aosc2023/{file_name}"
return download_url
# Create a Google Form
NEW_FORM = {
"info": {
"title": "Image Voting Form",
}
}
form = forms_service.forms().create(body=NEW_FORM).execute()
form_id = form['formId']
options = []
for url in images:
encoded_url = quote(url[0], safe=':/')
option = {
'value': url[1].strip(".jpg"),
'image': {
'sourceUri': encoded_url,
'altText': url[1]
}
}
options.append(option)
question_item = {
'createItem': {
'item': {
'title': 'Choose an option',
'questionItem': {
'question': {
'choiceQuestion': {
'type': 'CHECKBOX',
'options': options
}
}
}
},
'location': {'index': 0}
}
}
batch_update_body = {'requests': [question_item]}
forms_service.forms().batchUpdate(formId=form_id, body=batch_update_body).execute()
images = [ ['https://webresources.aaaab3n.moe/aosc2023_1/STARRY-S - 鲜艳.jpg', 'STARRY-S - 鲜艳.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Felix Yan - Their Prosperity II.jpg', 'Felix Yan - Their Prosperity II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 富士山 III.jpg', 'Yu Changyuan - 富士山 III.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alex Qin - 平潭.jpg', 'Alex Qin - 平潭.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Griffin Ardern - Holiday II.jpg', 'Griffin Ardern - Holiday II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Motion.jpg', 'Mingcong Bai - Motion.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Skyward Melody.jpg', 'Mingcong Bai - Skyward Melody.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/G8 - River Side.jpg', 'G8 - River Side.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/RedL0tus - Withered.jpg', 'RedL0tus - Withered.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Once Upon a Home.jpg', 'Mingcong Bai - Once Upon a Home.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 富士山 II.jpg', 'Yu Changyuan - 富士山 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mogician Yang - 地之脊 I.jpg', 'Mogician Yang - 地之脊 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alynx Zhou - Fly Me over the Moon.jpg', 'Alynx Zhou - Fly Me over the Moon.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 油菜花田 II.jpg', 'Yu Changyuan - 油菜花田 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Getting Some Fries on the Pier.jpg', 'cthbleachbit - Getting Some Fries on the Pier.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Metropolitan Retreat.jpg', 'Mingcong Bai - Metropolitan Retreat.jpg']]
options = []
for url in images:
encoded_url = quote(url[0], safe=':/')
option = {
'value': url[1].strip(".jpg"),
'image': {
'sourceUri': encoded_url,
'altText': url[1]
}
}
options.append(option)
question_item = {
'createItem': {
'item': {
'title': 'Choose an option',
'questionItem': {
'question': {
'choiceQuestion': {
'type': 'CHECKBOX',
'options': options
}
}
}
},
'location': {'index': 0}
}
}
batch_update_body = {'requests': [question_item]}
forms_service.forms().batchUpdate(formId=form_id, body=batch_update_body).execute()
images = [['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Midsummer Shade.jpg', 'Mingcong Bai - Midsummer Shade.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 大巴扎 II.jpg', 'Yu Changyuan - 大巴扎 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Antenna Sentinel.jpg', 'lz233 - Antenna Sentinel.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Luscious.jpg', 'Mingcong Bai - Luscious.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/YzyParry - 台灯和百叶窗.jpg', 'YzyParry - 台灯和百叶窗.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Rays.jpg', 'Mingcong Bai - Rays.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 热气球 I.jpg', 'Yu Changyuan - 热气球 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/RedL0tus - Sunset.jpg', 'RedL0tus - Sunset.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Coming Through.jpg', 'Mingcong Bai - Coming Through.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/wsyxbcl - Spring.jpg', 'wsyxbcl - Spring.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Cable Car and Seascape.jpg', 'lz233 - Cable Car and Seascape.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alex Qin - 屋檐 I.jpg', 'Alex Qin - 屋檐 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Griffin Ardern - Holiday I.jpg', 'Griffin Ardern - Holiday I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/RedL0tus - Reflections.jpg', 'RedL0tus - Reflections.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Daisy.jpg', 'Mingcong Bai - Daisy.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 蓝色清真寺.jpg', 'Yu Changyuan - 蓝色清真寺.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Griffin Ardern - Red Tower.jpg', 'Griffin Ardern - Red Tower.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 静安 I.jpg', 'Yu Changyuan - 静安 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Ariel AxionL - 斜阳几何.jpg', 'Ariel AxionL - 斜阳几何.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mogician Yang - New Frontier I.jpg', 'Mogician Yang - New Frontier I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Solo Voyage in Blue.jpg', 'lz233 - Solo Voyage in Blue.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Bridge Across.jpg', 'Mingcong Bai - Bridge Across.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mogician Yang - 拼图 I.jpg', 'Mogician Yang - 拼图 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alynx Zhou - 照无眠.jpg', 'Alynx Zhou - 照无眠.jpg']]
options = []
for url in images:
encoded_url = quote(url[0], safe=':/')
option = {
'value': url[1].strip(".jpg"),
'image': {
'sourceUri': encoded_url,
'altText': url[1]
}
}
options.append(option)
question_item = {
'createItem': {
'item': {
'title': 'Choose an option',
'questionItem': {
'question': {
'choiceQuestion': {
'type': 'CHECKBOX',
'options': options
}
}
}
},
'location': {'index': 0}
}
}
batch_update_body = {'requests': [question_item]}
forms_service.forms().batchUpdate(formId=form_id, body=batch_update_body).execute()
images = [ ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Blue Hydrangea Cluster.jpg', 'lz233 - Blue Hydrangea Cluster.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Calmly It Flows.jpg', 'Mingcong Bai - Calmly It Flows.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Sneak Peak.jpg', 'Mingcong Bai - Sneak Peak.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alynx Zhou - 群星的尽头.jpg', 'Alynx Zhou - 群星的尽头.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 油菜花田 I.jpg', 'Yu Changyuan - 油菜花田 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Interwoven Lines.jpg', 'lz233 - Interwoven Lines.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Delights.jpg', 'Mingcong Bai - Delights.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alex Qin - 屋檐 II.jpg', 'Alex Qin - 屋檐 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Garden Stroll.jpg', 'Mingcong Bai - Garden Stroll.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/STARRY-S - 寂静的树林.jpg', 'STARRY-S - 寂静的树林.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Sunset Upon the Mountain.jpg', 'Mingcong Bai - Sunset Upon the Mountain.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Fall Color in the Creek.jpg', 'cthbleachbit - Fall Color in the Creek.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/RedL0tus - Corridor.jpg', 'RedL0tus - Corridor.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Fallen Tree.jpg', 'cthbleachbit - Fallen Tree.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 大巴扎 I.jpg', 'Yu Changyuan - 大巴扎 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/RedL0tus - American Lady.jpg', 'RedL0tus - American Lady.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 外滩.jpg', 'Yu Changyuan - 外滩.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 大巴扎 III.jpg', 'Yu Changyuan - 大巴扎 III.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/RedL0tus - Bodie Island Lighthouse.jpg', 'RedL0tus - Bodie Island Lighthouse.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Tufts.jpg', 'Mingcong Bai - Tufts.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 南浦大桥.jpg', 'Yu Changyuan - 南浦大桥.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/STARRY-S - 红蔷薇.jpg', 'STARRY-S - 红蔷薇.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Manhattan Skyline.jpg', 'cthbleachbit - Manhattan Skyline.jpg']]
options = []
for url in images:
encoded_url = quote(url[0], safe=':/')
option = {
'value': url[1].strip(".jpg"),
'image': {
'sourceUri': encoded_url,
'altText': url[1]
}
}
options.append(option)
question_item = {
'createItem': {
'item': {
'title': 'Choose an option',
'questionItem': {
'question': {
'choiceQuestion': {
'type': 'CHECKBOX',
'options': options
}
}
}
},
'location': {'index': 0}
}
}
batch_update_body = {'requests': [question_item]}
forms_service.forms().batchUpdate(formId=form_id, body=batch_update_body).execute()
images = [['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 格雷梅小镇 I.jpg', 'Yu Changyuan - 格雷梅小镇 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Hugs.jpg', 'Mingcong Bai - Hugs.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Tapestry.jpg', 'cthbleachbit - Tapestry.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 棉花堡.jpg', 'Yu Changyuan - 棉花堡.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Skyline.jpg', 'lz233 - Skyline.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/新一 - Yulong.jpg', '新一 - Yulong.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/STARRY-S - 秋叶.jpg', 'STARRY-S - 秋叶.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/cthbleachbit - Camping.jpg', 'cthbleachbit - Camping.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Sincerity.jpg', 'Mingcong Bai - Sincerity.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mingcong Bai - Brisk.jpg', 'Mingcong Bai - Brisk.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 静安 III.jpg', 'Yu Changyuan - 静安 III.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/宇宙眼镜人 - 我相信,会再次看到蓝天.jpg', '宇宙眼镜人 - 我相信,会再次看到蓝天.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 油菜花田 III.jpg', 'Yu Changyuan - 油菜花田 III.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/宇宙眼镜人 - 日暮,那所有金色的梦.jpg', '宇宙眼镜人 - 日暮,那所有金色的梦.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/lz233 - Pathway of Reflections.jpg', 'lz233 - Pathway of Reflections.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mogician Yang - New Frontier II.jpg', 'Mogician Yang - New Frontier II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 富士山 I.jpg', 'Yu Changyuan - 富士山 I.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alynx Zhou - 拖把.JPG', 'Alynx Zhou - 拖把.JPG'], ['https://webresources.aaaab3n.moe/aosc2023_1/Alex Qin - 机柜.jpg', 'Alex Qin - 机柜.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Mogician Yang - Fly Low.jpg', 'Mogician Yang - Fly Low.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Yu Changyuan - 热气球 II.jpg', 'Yu Changyuan - 热气球 II.jpg'], ['https://webresources.aaaab3n.moe/aosc2023_1/Griffin Ardern - Sail & Sea.jpg', 'Griffin Ardern - Sail & Sea.jpg']]
options = []
for url in images:
encoded_url = quote(url[0], safe=':/')
option = {
'value': url[1].strip(".jpg"),
'image': {
'sourceUri': encoded_url,
'altText': url[1]
}
}
options.append(option)
question_item = {
'createItem': {
'item': {
'title': 'Choose an option',
'questionItem': {
'question': {
'choiceQuestion': {
'type': 'CHECKBOX',
'options': options
}
}
}
},
'location': {'index': 0}
}
}
batch_update_body = {'requests': [question_item]}
forms_service.forms().batchUpdate(formId=form_id, body=batch_update_body).execute()
print(f"Form created: https://docs.google.com/forms/d/{form_id}/edit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment