Skip to content

Commit

Permalink
Merge branch 'main' into yash/install
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgorana committed Oct 10, 2024
2 parents 88a53ce + c9da6b1 commit 38359c2
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 9 deletions.
2 changes: 2 additions & 0 deletions fetchers/netflix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inputs/*
output
22 changes: 22 additions & 0 deletions fetchers/netflix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Netflix Fetcher

This will run periodically and download your netflix data so you can keep your stats up to date.

## Instructions

Add email, password and profile to text files in ./inputs

```
├── inputs
│   ├── NETFLIX_EMAIL.txt
│   ├── NETFLIX_PASSWORD.txt
│   └── NETFLIX_PROFILE.txt
```

## Profile ID

To get your profile ID go to the Profile Gate:
https://www.netflix.com/ProfilesGate

Right click and copy the url for your profile and get the part after:
https://www.netflix.com/SwitchProfile?tkn=
70 changes: 70 additions & 0 deletions fetchers/netflix/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

chrome_driver_path = os.environ["CHROMEDRIVER_PATH"]
email = os.environ["NETFLIX_EMAIL"]
password = os.environ["NETFLIX_PASSWORD"]
profile = os.environ["NETFLIX_PROFILE"]
output_dir = os.environ["OUTPUT_DIR"]

print(f"🍿 Downloading Netflix Activity for: {email} Profile {profile}")

# Set up WebDriver (for Chrome)
chrome_options = Options()
prefs = {
"download.default_directory": output_dir,
"download.prompt_for_download": False,
}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument(
"--headless"
) # Run in headless mode, comment this if you want to see the browser window
chrome_service = Service(chrome_driver_path) # Set the path to your ChromeDriver

driver = webdriver.Chrome(service=chrome_service, options=chrome_options)

# get login page
driver.get("https://www.netflix.com/login")


# Find the email and password input fields
email_input = driver.find_element(By.NAME, "userLoginId")
password_input = driver.find_element(By.NAME, "password")
# Enter email and password
email_input.send_keys(email)
password_input.send_keys(password)

# Submit the login form
print("Logging In")
password_input.send_keys(Keys.ENTER)

# Wait for the login to complete
time.sleep(3)

print("Switching Profiles")
# Navigate to Viewing Activity page
driver.get(f"https://www.netflix.com/SwitchProfile?tkn={profile}")

# Wait for the login to complete
time.sleep(3)

print("Getting Viewing Activity")
# Navigate to Viewing Activity page
driver.get("https://www.netflix.com/viewingactivity")

time.sleep(3)

print("Clicking Download all")
# Navigate to a page and download a file
element = driver.find_element(By.LINK_TEXT, "Download all").click()

print("Sleeping just in case")
time.sleep(10)

driver.quit()
1 change: 1 addition & 0 deletions fetchers/netflix/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
selenium
24 changes: 24 additions & 0 deletions fetchers/netflix/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Check if chromedriver is in the PATH
if ! command -v chromedriver &> /dev/null
then
echo "chromedriver is not installed. Installing with brew..."
brew install chromedriver
else
echo "chromedriver is already installed."
fi

export CHROMEDRIVER_PATH=$(which chromedriver)
echo $CHROMEDRIVER_PATH

mkdir -p inputs
mkdir -p output

export NETFLIX_EMAIL=$(cat inputs/NETFLIX_EMAIL.txt)
export NETFLIX_PASSWORD=$(cat inputs/NETFLIX_PASSWORD.txt)
export NETFLIX_PROFILE=$(cat inputs/NETFLIX_PROFILE.txt)
export OUTPUT_DIR=$(realpath ./output)

uv pip install -r requirements.txt
uv run main.py
43 changes: 34 additions & 9 deletions syftbox/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async def info():
}


def main() -> None:
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Run FastAPI server")
parser.add_argument(
"--port",
Expand All @@ -463,19 +463,44 @@ def main() -> None:
action="store_true",
help="Run the server in debug mode with hot reloading",
)
parser.add_argument(
"--ssl-keyfile",
type=str,
help="Path to SSL key file for HTTPS",
)
parser.add_argument(
"--ssl-keyfile-password",
type=str,
help="SSL key file password for HTTPS",
)
parser.add_argument(
"--ssl-certfile",
type=str,
help="Path to SSL certificate file for HTTPS",
)

args = parser.parse_args()
return args


def main() -> None:
args = parse_args()
uvicorn_config = {
"app": "syftbox.server.server:app" if args.debug else app,
"host": "0.0.0.0",
"port": args.port,
"log_level": "debug" if args.debug else "info",
"reload": args.debug,
}

uvicorn.run(
"syftbox.server.server:app"
if args.debug
else app, # Use import string in debug mode
host="0.0.0.0",
port=args.port,
log_level="debug" if args.debug else "info",
reload=args.debug, # Enable hot reloading only in debug mode
uvicorn_config["ssl_keyfile"] = args.ssl_keyfile if args.ssl_keyfile else None
uvicorn_config["ssl_certfile"] = args.ssl_certfile if args.ssl_certfile else None
uvicorn_config["ssl_keyfile_password"] = (
args.ssl_keyfile_password if args.ssl_keyfile_password else None
)

uvicorn.run(**uvicorn_config)


if __name__ == "__main__":
main()

0 comments on commit 38359c2

Please sign in to comment.