Last active
December 2, 2024 17:44
-
-
Save ungeskriptet/555c52ca6e356468a7084a36b7548836 to your computer and use it in GitHub Desktop.
Samsung inquiry script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from selenium.common.exceptions import NoSuchElementException | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.support.ui import Select | |
from selenium.webdriver.support.ui import WebDriverWait | |
import requests | |
import sys | |
import time | |
import xml.etree.ElementTree as ET | |
writer = "Max Mustermann" | |
writeremail = "[email protected]" | |
def template(model, version): | |
template = f'''Dear Samsung Open Source Team, | |
the latest version for {model} is {version}. Please release the open source code used in this version. | |
Best Regards | |
{writer} <{writeremail}>''' | |
return template | |
def info(text): print(f'\033[94mINFO: \033[00m{text}') | |
def warning(text): print(f'\033[93mWARNING: \033[00m{text}') | |
def error(text): | |
print(f'\033[91mERROR: \033[00m{text}') | |
quit() | |
def getlatest(model: str, csc: str): | |
url = f'https://fota-cloud-dn.ospserver.net/firmware/{csc}/{model}/version.xml' | |
try: | |
response = requests.get(url, headers={'User-Agent': 'Kies2.0_FUS'}).text | |
tree = ET.fromstring(response) | |
for version in tree.iter('latest'): | |
if version.text == None: | |
error(f'No updates found for {model}, {csc}') | |
fwver = version.text.split('/') | |
return fwver | |
else: | |
raise Exception | |
except: | |
error(f'Encountered failure while attempting to get latest version for {model}, {csc}') | |
model = sys.argv[1] | |
if len(sys.argv[2]) == 3: | |
fwver = getlatest(model, sys.argv[2])[0] | |
else: | |
fwver = sys.argv[2] | |
info(f'Searching for {fwver}') | |
driver = webdriver.Firefox() | |
driver.get('https://opensource.samsung.com') | |
searchbox = driver.find_element(By.ID, 'searchValue1') | |
if searchbox: | |
info('Found search box') | |
searchbox.send_keys(sys.argv[1]) | |
searchbox.send_keys(Keys.ENTER) | |
wait = WebDriverWait(driver, 300) | |
if wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'pc-column'))): | |
info('Second page loaded') | |
page = 1 | |
while True: | |
try: | |
driver.find_element(By.XPATH, f'/html/body/div/form/div[2]/div[2]/a[{page}]') | |
page += 1 | |
except NoSuchElementException: | |
page -= 2 | |
info(f'Page count: {page}') | |
break | |
i = 0 | |
while i < page: | |
releasestable = driver.find_elements(By.XPATH, '/html/body/div/form/div[2]/div[1]/table/tbody') | |
releases = [i.text for i in releasestable][0] | |
if fwver in releases: | |
info(f'Found {fwver}') | |
driver.quit() | |
break | |
else: | |
info(f'Checking page {i+1}') | |
nextpage = driver.find_element(By.CLASS_NAME, 'direction.direc-next') | |
nextpage.click() | |
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'pc-column'))) | |
i += 1 | |
else: | |
info(f'Could not find {fwver}') | |
info('Opening inquiry page') | |
inquiry = driver.find_element(By.CLASS_NAME, 'ico-sourceUtil.ico-mail') | |
inquiry.click() | |
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'btn-inquiry'))).click() | |
info('Inputting writer') | |
wait.until(EC.presence_of_element_located((By.ID, 'writer'))).send_keys(writer) | |
info('Inputting writer E-Mail') | |
driver.find_element(By.ID, 'writerEmail').send_keys(writeremail) | |
info('Selecting country') | |
Select(driver.find_element(By.ID, 'countryRegion')).select_by_value('DEU') | |
info('Selecting SW continent') | |
if sys.argv[2] == 'BRI' or sys.argv[2] == 'CHC': | |
swcontinent = 'AS' | |
swregion = 'China' | |
elif sys.argv[2] == 'SJP' or sys.argv[2] == 'DCM' or sys.argv[2] == 'KDI': | |
swcontinent = 'AS' | |
swregion = 'Japan' | |
elif sys.argv[2] == 'KOO': | |
swcontinent = 'AS' | |
swregion = 'Korea' | |
elif sys.argv[2] == 'ATT' or sys.argv[2] == 'BCM': | |
swcontinent = 'NA' | |
swregion = None | |
else: | |
swcontinent = 'EU' | |
swregion = 'Europe' | |
Select(driver.find_element(By.ID, 'residenceContinent')).select_by_value(swcontinent) | |
if swregion != None: | |
info('Selecting SW region') | |
region = wait.until(EC.visibility_of_element_located((By.ID, 'residenceRegion'))) | |
Select(region).select_by_visible_text(swregion) | |
info('Inputting template') | |
driver.find_element(By.ID, 'contents').send_keys(template(sys.argv[1], fwver)) | |
info('Clicking checkbox') | |
driver.find_element(By.XPATH, '/html/body/div[1]/div/div[3]/form/div[1]/label/span/i').click() | |
info('Clicking hCaptcha') | |
hcaptcha = driver.find_element(By.XPATH, '/html/body/div[1]/div/div[3]/form/div[2]/iframe') | |
driver.switch_to.frame(hcaptcha) | |
driver.find_element(By.XPATH, '//*[@id="checkbox"]').click() | |
info('Please finish the captcha and click on send when done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment