Skip to content

Instantly share code, notes, and snippets.

@androslee
Forked from stdsp/composer_auto.py
Last active October 30, 2022 04:28
Show Gist options
  • Save androslee/c55e41227c58f6415b8248c8d9751364 to your computer and use it in GitHub Desktop.
Save androslee/c55e41227c58f6415b8248c8d9751364 to your computer and use it in GitHub Desktop.
a script which saves a csv file of the 4 details on the https://app.composer.trade/follow page for all symphonies that you follow
pip3 install -r requirements.txt

##python update

  • it's highly recommended you keep your python install up to date. at the time of writing this, python 3.11.0 was just released.

  • start selenium java -jar selenium-server-4.5.3.jar standalone &

  • In terminal cd to directory which contains script

  • run: python3 -i composer_auto.py assuming your local python3 was made as an altinstall aliased to "python3"

  • login to composer

  • go to https://app.composer.trade/follow

  • In terminal run job() because this was launched interactive. after line 20, the current python interpreter has nothing left to do. it got you to login at line 20, so the current session has your login/session information. so, you can run the "job()" function and direct python to start scraping the page for all the information.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import datetime
from sys import platform
if platform == "linux" or platform == "linux2" or platform == "cygwin":
# linux
driver = webdriver.Chrome(executable_path="//usr/bin/chromedriver")
# don't know the OS X variants nor the install paths, sorry
#elif platform == "darwin":
# OS X
elif platform == "win32":
# Windows...
driver = webdriver.Firefox(executable_path="geckodriver.exe")
driver.get("https://app.composer.trade/login")
def job():
url = "https://app.composer.trade/follow"
wait = WebDriverWait(driver, 10)
wait.until(EC.url_to_be(url))
#symphony name
symps = driver.find_elements(By.CLASS_NAME, "text-lg.mb-1.leading-snug.relative.z-20.pointer-events-none")
symps_name = [symp.text for symp in symps]
#symphony url
symps = driver.find_elements(By.CLASS_NAME, "sr-only")
symps_url = [symp.get_attribute("href") for symp in symps]
#simulated value
sim_vals = driver.find_elements(By.XPATH, "//*[contains(text(), 'Simulated Value')]/following-sibling::node()")
sim_vals_txt = [sim_val.text for sim_val in sim_vals]
#cumulative return
cum_rets = driver.find_elements(By.XPATH, "//*[contains(text(), 'Cumulative Return')]/following-sibling::node()")
cum_rets_txt = [cum_ret.text for cum_ret in cum_rets]
#today's $ change
usd_changes = driver.find_elements(By.XPATH, "//*[contains(text(), \"Today's $ Change\")]/following-sibling::node()")
usd_changes_txt = [usd_change.text for usd_change in usd_changes]
#today's % change
percent_changes = driver.find_elements(By.XPATH, "//*[contains(text(), \"Today's % Change\")]/following-sibling::node()")
percent_changes_txt = [percent_change.text for percent_change in percent_changes]
prop_names = ["symp_name", "symp_url", "sim_val", "cum_ret", "usd_change", "percent_change"]
props = [symps_name, symps_url, sim_vals_txt, cum_rets_txt, usd_changes_txt, percent_changes_txt]
df = pd.DataFrame(dict(zip(prop_names, props)))
dt_now = datetime.datetime.now()
df["datetime"] = dt_now
df.to_csv(f"{dt_now.strftime('%d_%m_%Y_%H_%M_%S')}.csv")
Invalid port. Exiting...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment