Initialize getters for Chrome software and general ones; Fix some examples for chrome

This commit is contained in:
Timothyxxx
2023-12-29 22:24:45 +08:00
parent a4e8cfedb9
commit 86ce9e1497
7 changed files with 124 additions and 17 deletions

View File

@@ -0,0 +1,80 @@
import json
import os
import platform
import sqlite3
"""
WARNING:
1. Functions from this script assume that no account is registered on Chrome, otherwise the default file path needs to be changed.
2. The functions are not tested on Windows and Mac, but they should work.
"""
# todo: move to getter module
def get_default_search_engine():
if platform.system() == 'Windows':
preference_file_path = os.path.join(os.getenv('LOCALAPPDATA'),
'Google\\Chrome\\User Data\\Default\\Preferences')
elif platform.system() == 'Darwin':
preference_file_path = os.path.join(os.getenv('HOME'),
'Library/Application Support/Google/Chrome/Default/Preferences')
else:
preference_file_path = os.path.join(os.getenv('HOME'), '.config/google-chrome/Default/Preferences')
try:
with open(preference_file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
# The path within the JSON data to the default search engine might vary
search_engine = data.get('default_search_provider_data', {}).get('template_url_data', {}).get('short_name',
'Google')
return search_engine
except Exception as e:
print(f"Error: {e}")
return "Google"
def get_cookie_data():
if platform.system() == 'Windows':
chrome_cookie_file_path = os.path.join(os.getenv('LOCALAPPDATA'), 'Google\\Chrome\\User Data\\Default\\Cookies')
elif platform.system() == 'Darwin':
chrome_cookie_file_path = os.path.join(os.getenv('HOME'),
'Library/Application Support/Google/Chrome/Default/Cookies')
else:
chrome_cookie_file_path = os.path.join(os.getenv('HOME'), '.config/google-chrome/Default/Cookies')
try:
conn = sqlite3.connect(chrome_cookie_file_path)
cursor = conn.cursor()
# Query to check for OpenAI cookies
cursor.execute("SELECT * FROM cookies")
cookies = cursor.fetchall()
return cookies
except Exception as e:
print(f"Error: {e}")
return None
def get_bookmarks():
if platform.system() == 'Windows':
preference_file_path = os.path.join(os.getenv('LOCALAPPDATA'),
'Google\\Chrome\\User Data\\Default\\Bookmarks')
elif platform.system() == 'Darwin':
preference_file_path = os.path.join(os.getenv('HOME'),
'Library/Application Support/Google/Chrome/Default/Bookmarks')
else:
preference_file_path = os.path.join(os.getenv('HOME'), '.config/google-chrome/Default/Bookmarks')
try:
with open(preference_file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
bookmarks = data.get('roots', {})
return bookmarks
except Exception as e:
print(f"Error: {e}")
return None

View File

@@ -0,0 +1,15 @@
import os
import platform
# todo: move to getter module
def get_desktop_path():
username = os.getlogin() # Get the current username
if platform.system() == "Windows":
return os.path.join("C:", "Users", username, "Desktop")
elif platform.system() == "Darwin": # macOS is identified as 'Darwin'
return os.path.join("/Users", username, "Desktop")
elif platform.system() == "Linux":
return os.path.join("/home", username, "Desktop")
else:
raise Exception("Unsupported operating system")

View File

@@ -8,5 +8,11 @@
"related_apps": [
"chrome"
],
"evaluator": "evaluation_dir"
"evaluator": {
"func": "",
"result": {
},
"expected": {
}
}
}

View File

@@ -8,5 +8,11 @@
"related_apps": [
"chrome"
],
"evaluator": "evaluation_dir"
"evaluator": {
"func": "",
"result": {
},
"expected": {
}
}
}

View File

@@ -8,5 +8,11 @@
"related_apps": [
"chrome"
],
"evaluator": "evaluation_dir"
"evaluator": {
"func": "",
"result": {
},
"expected": {
}
}
}

View File

@@ -1,12 +0,0 @@
{
"id": "b188fe10-ae67-4db8-a154-26a0b8ff8f1e",
"snapshot": "chrome",
"instruction": "Help me add \"bookmark this page\" button to Chrome.",
"source": "https://superuser.com/questions/1115565/how-to-add-bookmark-this-page-button-to-chrome",
"config": [],
"trajectory": "trajectories/",
"related_apps": [
"chrome"
],
"evaluator": "evaluation_dir"
}

View File

@@ -1,12 +1,18 @@
{
"id": "bb5e4c0d-f964-439c-97b6-bdb9747de3f4",
"snapshot": "chrome",
"instruction": "Could you help me set my default search engine to be Chrome?",
"instruction": "Could you help me set my default search engine to be Google?",
"source": "https://support.google.com/chrome/answer/95426?sjid=16867045591165135686-AP",
"config": [],
"trajectory": "trajectories/",
"related_apps": [
"chrome"
],
"evaluator": "evaluation_dir"
"evaluator": {
"func": "",
"result": {
},
"expected": {
}
}
}