summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/fetch-play-metadata.py144
-rwxr-xr-xscripts/prepareForTx.py107
2 files changed, 251 insertions, 0 deletions
diff --git a/scripts/fetch-play-metadata.py b/scripts/fetch-play-metadata.py
new file mode 100755
index 00000000..7c65b648
--- /dev/null
+++ b/scripts/fetch-play-metadata.py
@@ -0,0 +1,144 @@
+import os
+import argparse
+import json
+from googleapiclient.discovery import build
+from google.oauth2 import service_account
+
+# Load API key from environment variable
+api_key = os.environ.get('GOOGLE_PLAY_API_KEY')
+
+# Load command-line arguments
+parser = argparse.ArgumentParser(description='Fetch app details from Google Play Store.')
+parser.add_argument('package_name', help='Package name of the app')
+parser.add_argument('--source-language', action='store_true', help='Fetch app description in source language')
+parser.add_argument('--list-languages', action='store_true', help='List all supported languages')
+parser.add_argument('--extract-details', action='store_true', help='Extract and save app details as JSON')
+parser.add_argument('--extract-changelog', action='store_true', help='Extract and save changelog as JSON')
+args = parser.parse_args()
+
+# Create a service account credentials object
+credentials = service_account.Credentials.from_service_account_file(
+ '/home/kwadronaut/dev/leap/secrets/android-api.json',
+ scopes=['https://www.googleapis.com/auth/androidpublisher']
+)
+
+# Build the service object for the Google Play Developer API
+service = build('androidpublisher', 'v3', credentials=credentials, cache_discovery=False)
+
+# Fetch app details
+def fetch_app_details(package_name, language):
+ # Create a new edit
+ edit_request = service.edits().insert(body={}, packageName=package_name)
+ edit_response = edit_request.execute()
+ edit_id = edit_response['id']
+
+ # Fetch the app listing for the specified language within the edit
+ app_details = service.edits().listings().get(
+ packageName=package_name,
+ editId=edit_id,
+ language=language
+ ).execute()
+
+ # Commit the edit (optional)
+ service.edits().commit(
+ packageName=package_name,
+ editId=edit_id
+ ).execute()
+
+ return app_details, edit_id
+
+# Fetch changelog for a specific version
+def fetch_changelog(package_name, edit_id):
+ # Fetch the tracks for the package
+ tracks = service.edits().tracks().list(packageName=package_name, editId=edit_id).execute()
+ track = tracks['tracks'][0]['track']
+
+ # Fetch the changelog for the track
+ changelog = service.edits().tracks().get(packageName=package_name, editId=edit_id, track=track).execute()
+
+ return changelog
+
+# Package name
+package_name = args.package_name
+
+# Fetch app details
+try:
+ #app_details, edit_id = fetch_app_details(package_name, 'en-US')
+ app_details, edit_id = fetch_app_details(package_name, 'nl-NL')
+ print("App Details:")
+ print(app_details)
+except Exception as e:
+ print("An error occurred:", str(e))
+
+# List all supported languages
+if args.list_languages:
+ try:
+ # Create a new edit
+ edit_request = service.edits().insert(body={}, packageName=package_name)
+ edit_response = edit_request.execute()
+ edit_id = edit_response['id']
+
+ # Fetch the app listings for the edit
+ listings = service.edits().listings().list(packageName=package_name, editId=edit_id).execute()
+ supported_languages = [listing['language'] for listing in listings['listings']]
+ print("Supported Languages:")
+ for language in supported_languages:
+ print(language)
+
+ # Commit the edit
+ service.edits().commit(packageName=package_name, editId=edit_id).execute()
+ except Exception as e:
+ print("An error occurred:", str(e))
+
+# Extract and save app details as JSON
+if args.extract_details:
+ try:
+ # Extract the text fields from app details
+ title = app_details['title']
+ full_description = app_details['fullDescription']
+ short_description = app_details['shortDescription']
+
+ # Create a dictionary to hold the extracted app details
+ extracted_details = {
+ 'title': title,
+ 'full_description': full_description,
+ 'short_description': short_description
+ }
+
+ # Determine the output file path based on the language
+ language = 'en-US' # Update with the desired language
+ json_file_path = f"locale/{language}/transifex.json"
+
+ # Create the output directory if it doesn't exist
+ os.makedirs(os.path.dirname(json_file_path), exist_ok=True)
+
+ # Save the extracted details as JSON
+ with open(json_file_path, 'w', encoding='utf-8') as json_file:
+ json.dump(extracted_details, json_file, ensure_ascii=False, indent=4)
+
+ print(f"App details extracted and saved to {json_file_path} as JSON successfully.")
+ except Exception as e:
+ print("An error occurred:", str(e))
+
+# Extract and save changelog as JSON
+if args.extract_changelog:
+ try:
+ changelog = fetch_changelog(package_name, edit_id)
+ print("Changelog:")
+ print(changelog)
+
+ # Determine the output file path based on the language
+ language = 'en-US' # Update with the desired language
+ json_file_path = f"locale/{language}/transifex.json"
+
+ # Create the output directory if it doesn't exist
+ os.makedirs(os.path.dirname(json_file_path), exist_ok=True)
+
+ # Save the changelog as JSON
+ with open(json_file_path, 'w', encoding='utf-8') as json_file:
+ json.dump(changelog, json_file, ensure_ascii=False, indent=4)
+
+ print(f"Changelog extracted and saved to {json_file_path} as JSON successfully.")
+ except Exception as e:
+ print("An error occurred:", str(e))
+
diff --git a/scripts/prepareForTx.py b/scripts/prepareForTx.py
new file mode 100755
index 00000000..c683c84a
--- /dev/null
+++ b/scripts/prepareForTx.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+""
+__author__ = "kwadronaut"
+__copyright__ = "Copyright 2023, LEAP"
+__license__ = "GPL3 or later3 or later3 or later"
+__version__ = "1"
+
+import os
+import re
+import argparse
+import json
+
+# Set the path to the res directory containing different language folders
+main_res_dir = "../app/src/main/res"
+custom_res_dir = "../app/src/custom/res"
+
+# List all valid locale folders in the res directory
+def list_locales(app_type):
+ locales = []
+ if app_type == "main":
+ res_dir = main_res_dir
+ elif app_type == "custom":
+ res_dir = custom_res_dir
+ else:
+ raise ValueError("Invalid app type. Use 'main' or 'custom'.")
+
+ valid_locale_pattern = re.compile(r'^values-(?P<language>[a-z]{2})(-(?P<script>[a-zA-Z]{4}))?(-r(?P<region>[a-zA-Z]{2}))?$')
+ for folder in os.listdir(res_dir):
+ if valid_locale_pattern.match(folder):
+ locale_code = valid_locale_pattern.match(folder).group(0)
+ locales.append(locale_code)
+ return locales
+
+# Create empty JSON file for each locale metadata directory
+# If there's no file, tx will skip the translations
+def create_metadata_files(locales, app_type):
+ if app_type == "main":
+ metadata_dir = "../src/normal/fastlane/metadata"
+ elif app_type == "custom":
+ metadata_dir = "../src/custom/fastlane/metadata"
+ else:
+ raise ValueError("Invalid app type. Use 'main' or 'custom'.")
+
+ for locale_code in locales:
+ # Remove "values-" prefix from the locale directory name
+ locale_dir_name = locale_code.replace("values-", "")
+ file_path = os.path.join(metadata_dir, locale_dir_name, f"store-meta-{locale_dir_name}.json")
+ if not os.path.exists(file_path): # Check if the file already exists
+ os.makedirs(os.path.dirname(file_path), exist_ok=True)
+ with open(file_path, "w", encoding="utf-8") as file:
+ file.write("{}") # Write an empty JSON object to the file
+
+# Split JSON data and save to separate files for each locale
+def split_json_and_save(locales, metadata_dir):
+ for locale_code in locales:
+ locale_dir_name = locale_code.replace("values-", "")
+ json_file_path = os.path.join(metadata_dir, locale_dir_name, f"store-meta-{locale_dir_name}.json")
+
+ if os.path.exists(json_file_path):
+ with open(json_file_path, "r", encoding="utf-8") as json_file:
+ json_data = json.load(json_file)
+
+ title = json_data.get("title")
+ full_description = json_data.get("full_description")
+ short_description = json_data.get("short_description")
+
+ if title:
+ title_file_path = os.path.join(metadata_dir, locale_dir_name, "title.txt")
+ with open(title_file_path, "w", encoding="utf-8") as title_file:
+ title_file.write(title)
+
+ if full_description:
+ full_description_file_path = os.path.join(metadata_dir, locale_dir_name, "full_description.txt")
+ with open(full_description_file_path, "w", encoding="utf-8") as full_description_file:
+ full_description_file.write(full_description)
+
+ if short_description:
+ short_description_file_path = os.path.join(metadata_dir, locale_dir_name, "short_description.txt")
+ with open(short_description_file_path, "w", encoding="utf-8") as short_description_file:
+ short_description_file.write(short_description)
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Create metadata directories and empty JSON files for different locales.')
+ parser.add_argument('app_type', choices=['main', 'custom'], help='Type of the app (main or custom)')
+ args = parser.parse_args()
+
+ if args.app_type == "main":
+ metadata_dir = "../src/normal/fastlane/metadata"
+ elif args.app_type == "custom":
+ metadata_dir = "../src/custom/fastlane/metadata"
+ else:
+ raise ValueError("Invalid app type. Use 'main' or 'custom'.")
+
+ locales_list = list_locales(args.app_type)
+ if locales_list:
+ print("List of Locales:")
+ for locale_code in locales_list:
+ print(locale_code)
+
+ create_metadata_files(locales_list, args.app_type)
+ print(f"Empty JSON files created for each locale in the '{args.app_type}' app.")
+
+ split_json_and_save(locales_list, metadata_dir)
+ print(f"JSON data split and saved to separate files for each locale in the '{args.app_type}' app.")
+ else:
+ print(f"No valid locales found in the '{args.app_type}' app's 'res' directory.")
+